
03-29-2007, 01:11 PM
|
| D-Web Analyst | | Join Date: Mar 2007
Posts: 301
| |
Re: VC++ Tips & Tricks About 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.
1.How to use the dynamic macros, I have given the sample code here. #include <afxwin.h>
class CSimpleFrame : public CFrameWnd
{
public:
CSimpleFrame();
DECLARE_DYNCREATE(CSimpleFrame)
};
class CSimpleApplication : public CWinApp
{
public:
BOOL InitInstance();
};
IMPLEMENT_DYNCREATE(CSimpleFrame, CFrameWnd)
CSimpleFrame::CSimpleFrame()
{
// Create the window's frame
Create(NULL, "Windows Application");
}
BOOL CSimpleApplication::InitInstance()
{
// Use a pointer to the window's frame for the application
// to use the window
m_pMainWnd = new CSimpleFrame ();
// Show the window
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
CSimpleApplication theApp; thanks 
__________________ Karpagarajan. R Necessity is the mother of invention
Last edited by Karpagarajan : 03-29-2007 at 01:16 PM.
|