Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 2: Introduction to MFC


{
BOOL InitInstance();
};

CSimpleFrame::CSimpleFrame()
{
// Create the window's frame
Create(NULL, "Windows Application");
}

// Frame diagnostics

#ifdef _DEBUG
void CSimpleFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}

void CSimpleFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif // _DEBUG

BOOL CSimpleApp::InitInstance()
{
CSimpleFrame *Tester = new CSimpleFrame();
m_pMainWnd = Tester;

m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();

return TRUE;
}

CSimpleApp theApp;


  1. Test the program and return to MSVC


2.2.3 Introduction to Macros...........................................................................


When creating objects that derive directly or indirectly from CObject, such as
CFrameWnd, you should let the compiler know that you want your objects to be
dynamically created. To do this, use the DECLARE_DYNCREATE and the
IMPLEMENT_DYNCREATE macros. The DECLARE_DYNCREATE macro is
provided in the class' header file and takes as argument the name of your class. An
example would be DECLARE_DYNCREATE(CTheFrame). Before implementing the
class or in its source file, use the IMPLEMENT_DYNCREATE macro, passing it two
arguments: the name of your class and the name of the class you derived it from.

We mentioned that, to access the frame, a class derived from CFrameWnd, from the
application class, you must use a pointer to the frame's class. On the other hand, if you
want to access the application, created using the CWinApp class, from the windows
frame, you use the AfxGetApp() global function.
Free download pdf