Click here to Skip to main content
15,886,362 members
Articles / Programming Languages / C++

CatchCulator

Rate me:
Please Sign up or sign in to vote.
4.97/5 (71 votes)
18 Oct 2005CPOL7 min read 130K   2K   69  
A tool used to catch and combine values output by different applications.
// Author: Dr. Mircea Puiu
// Created on: October 2005 for CodeProject
//
// StaticDisplay.cpp : implementation file
//

#include "stdafx.h"
#include "CatchCulator.h"
#include "StaticDisplay.h"

#include "DisplayFormatDlg.h"
#include "CatchCulatorDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CStaticDisplay

CStaticDisplay::CStaticDisplay()
{
	ID = 1;
	m_strDisplayFormat = "%.5lf";
}

CStaticDisplay::~CStaticDisplay()
{
}


BEGIN_MESSAGE_MAP(CStaticDisplay, CStatic)
	//{{AFX_MSG_MAP(CStaticDisplay)
	ON_WM_PAINT()
	ON_WM_RBUTTONDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CStaticDisplay message handlers

void CStaticDisplay::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	char	chCaption[256];

	// Create the script dialog (only once)
	if ( !m_dlgScript.GetSafeHwnd() )
	{
		sprintf(chCaption, " Script > D%d", ID);
		m_dlgScript.m_strCaption = chCaption;
		m_dlgScript.Create(IDD_DIALOG_SCRIPT);
	}
	
	// TODO: Add your message handler code here
	CDC			memDC;
	CBitmap		*oldB, B;
	CRect		rcControl;
	CString		strText;
	UINT		oldTA;
	int			w, h, oldBkMode;

	// Create the memory resources
	memDC.CreateCompatibleDC(&dc);
	GetClientRect(&rcControl);
	w = rcControl.Width();
	h = rcControl.Height();
	switch ( ID )
	{
		case 1:		B.LoadBitmap(IDB_BITMAP_D1);	break;
		case 2:		B.LoadBitmap(IDB_BITMAP_D2);	break;
		case 3:		B.LoadBitmap(IDB_BITMAP_D3);	break;
		default:	B.LoadBitmap(IDB_BITMAP_D1);
	}
	oldB = (CBitmap *)memDC.SelectObject(&B);
	oldBkMode = memDC.SetBkMode(TRANSPARENT);
	oldTA = memDC.SetTextAlign(TA_RIGHT);

	// Write the text
	memDC.TextOut(w - 4, 5, m_strDisplay);

	// Put everything on the screen
	dc.BitBlt(0, 0, w, h, &memDC, 0, 0, SRCCOPY);
	// Clean the garbage
	memDC.SetBkMode(oldBkMode);
	memDC.SetTextAlign(oldTA);
	if ( oldB ) memDC.SelectObject(oldB);
	B.DeleteObject();
	ReleaseDC(&memDC);
}

void CStaticDisplay::OnRButtonDown(UINT nFlags, CPoint point) 
{
	CDisplayFormatDlg	dlgFormat;
	CCatchCulatorDlg	*pMain = (CCatchCulatorDlg *)AfxGetMainWnd();

	if ( nFlags == MK_RBUTTON )
	{
		// Erase the display
		m_strDisplay = "";
		Invalidate(FALSE);
	}
	else if ( nFlags == (MK_RBUTTON | MK_CONTROL) )
	{
		// Show the script for this display
		m_dlgScript.ShowWindow(SW_SHOW);
	}
	else if ( nFlags == (MK_RBUTTON | MK_SHIFT) )
	{
		// Change the display format
		dlgFormat.m_nDisplayID = ID;
		dlgFormat.m_strCrtFormat = m_strDisplayFormat;
		if ( dlgFormat.DoModal() == IDOK )
		{
			m_strDisplayFormat = dlgFormat.m_strNewDisplayFormat;
			if ( pMain ) pMain->UpdateDisplay(ID);
		}
	}
	
	CStatic::OnRButtonDown(nFlags, point);
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Europe Europe
More than 30 years of software development experience.
(also playing the SCRUM Master role depending on the project)

Comments and Discussions