//首先,在文件中加入如下头文件语句: #ifndef VC_EXTRALEAN #define VC_EXTRALEAN // 从 Windows 头中排除极少使用的资料 #endif #include <afx.h> #include <afxwin.h> // MFC 核心组件和标准组件 #include <afxext.h> // MFC 扩展 #pragma comment(lib,"kernel32.lib") #pragma comment(lib,"user32.lib") #pragma comment(lib,"gdi32.lib") // //上面这段代码可以放在预编译头文件stdafx.h中,位置自己可定 // //然后在_tWinMain的开始加入 int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { //Enable IPAddress、Calendar.etc //InitCommonControls(); if (!AfxWinInit(hInstance, NULL, lpCmdLine, 0)) { MessageBox(NULL,_T("MFC init error!"),_T("Error!"),MB_OK); return 0; } MessageBox(NULL,_T("MFC init ok!"),_T("Ok!"),MB_OK); return 0; } /* 然后在菜单中依次选择"项目->属性->配置属性->常规->MFC的使用"中选择"在共享DLL中使用MFC"; 然后再在菜单中依次选择"项目->属性->配置属性->链接器->常规->附加库目录"中加入"kernel32.lib user32.lib gdi32.lib",中间以空格隔开; 如果编译时出现下面错误: fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h> 那么我们在预编译头文件stdafx.h中将"#include <windows.h>"删掉或者注释掉即可. //*/