Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 5: The Document/View Architecture Visual C++ and MFC Fundamentals


};

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
ON_WM_KEYDOWN()
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}

void CMainFrame::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch(nChar)
{
case VK_RETURN:
MessageBox("You pressed Enter");
break;
case VK_F1:
MessageBox("Help is not available at the moment");
break;
case VK_DELETE:
MessageBox("Can't Delete This");
break;
default:
MessageBox("Whatever");
}
}

void CMainFrame::OnLButtonDown(UINT nFlags, CPoint point)
{
char *MsgCoord = new char[20];

sprintf(MsgCoord, "Left Button at P(%d, %d)", point.x, point.y);

MessageBox(MsgCoord);
}

BOOL CExerciseApp::InitInstance()
{
m_pMainWnd = new CMainFrame ;
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();

return TRUE;
}

CExerciseApp theApp;


  1. Test the program:

Free download pdf