Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 18: Progress-Based Controls


void CRandShapesDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
static int MoveCounter = 0;

if( MoveCounter >= 20 )
DestroyWindow();
MoveCounter++;

CDialog::OnMouseMove(nFlags, point);
}


  1. To change the background of the dialog box to black, change the OnPaint() event as
    follows:


void CRandShapesDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect ScreenRecto;

GetClientRect(&ScreenRecto);
CBrush BrushBlack(RGB(0, 0, 0));

CBrush *pOldBrush = dc.SelectObject(&BrushBlack);

dc.Rectangle(ScreenRecto);
dc.SelectObject(pOldBrush);

if (IsIconic())
{
SendMessage(WM_ICONERASEBKGND,
reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}


  1. Test the application and return to MSVC

  2. To hide the cursor, at the end of the OnInitDialog() event, just before the return line,
    call the ShowCursor() function with a FALSE argument.


18.1.2..The Timer Control...............................................................................


Unlike most other controls, the MFC timer has neither a button to represent it nor a class.
To create a timer, you simply call the CWnd::SetTimer() method. Its syntax is:
Free download pdf