Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


If the window that sent this message is being restored from its deactivation, pass the
bMinimized value as TRUE.

When calling this message, before implementing the custom behavior you want, first call
its implementation from the parent class:

void CMainFrame::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CFrameWnd::OnActivate(nState, pWndOther, bMinimized);

// TODO: Add your message handler code here
}

Practical Learning: Activating a Window



  1. To activate a window that has been created, change the file as follows:


#include <afxwin.h>


class CMainFrame : public CFrameWnd
{
public:
CMainFrame ();


protected:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
afx_msg void OnActivate(UINT nState, CWnd* pWndOther,
BOOL bMinimized);
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()
ON_WM_SHOWWINDOW()
ON_WM_ACTIVATE()
END_MESSAGE_MAP()


int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
// Call the base class to create the window
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}

Free download pdf