为了创建一个完整的MFC程序,只需要从MFC派生出两个类:an Application class和a windows class.首先需要包含头文件afxwin.h,这个文件中包含很多MFC类的定义。然后利用Visual C++2005创建一个空的Win32 Project,在Project properties属性的General子页中单击Use of MFC property选定Use MFC in a Shared DLL.
// An elementary MFC program
#include <afxwin.h> // For the class library
// Application class definition
class COurApp:public CWinApp
{
public:
virtual BOOL InitInstance();
};
// Window class definition
class COurWnd:public CFrameWnd
{
public:
// Constructor
COurWnd()
{
Create(0, L"Our Dumb MFC Application");
}
};
// Function to create an instance of the main application window
BOOL COurApp::InitInstance(void)
{
// Construct a window object in the free store
m_pMainWnd = new COurWnd;
m_pMainWnd->ShowWindow(m_nCmdShow); // ...and display it
return TRUE;
}
// Application object definition at global scope
COurApp AnApplication; // Define an application object