|
// 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.
More than 30 years of software development experience.
(also playing the SCRUM Master role depending on the project)