Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


protected:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);

DECLARE_MESSAGE_MAP()
};

CMainFrame::CMainFrame()
{
// Create the window's frame
Create(NULL, "Windows Application", WS_OVERLAPPEDWINDOW,
CRect(120, 100, 700, 480), NULL);
}

class CExerciseApp: public CWinApp
{
public:
BOOL InitInstance();
};

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

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

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

return TRUE;
}

CExerciseApp theApp;


  1. Test the application and return to MSVC


4.4.2 The Key Down Effect.........................................................................


When we think of the keyboard, the first thing that comes in mind if to press a key. When
a keyboard key is pressed, a message called WM_KEYDOWN. Its syntax is:

afx_msg void OnKeyDown( UINT nChar, UINT nRepCnt, UINT nFlags );

The first argument, nChar, specifies the virtual code of the key that was pressed.
The second argument, nRepCnt, specifies the number of times counted repeatedly as the
key was held down.
The nFlags argument specifies the scan code, extended-key flag, context code, previous
key-state flag, and transition-state flag.
Free download pdf