#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers#include <afxwin.h> // MFC core and standard components #include <afxext.h> // MFC extensions #include <afxdisp.h> // MFC Automation classes #include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls #ifndef _AFX_NO_AFXCMN_SUPPORT #include <afxcmn.h> // MFC support for Windows Common Controls #endif // _AFX_NO_AFXCMN_SUPPORT
是啊,我加了这些了,编译也过了, 如下:LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... RECT rt; GetClientRect(hWnd, &rt); DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER); EndPaint(hWnd, &ps); break; case WM_CREATE: { Cdia asd; asd.DoModal(); } break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0; }主要是case wm_create 里,我加了一个cdia的类,在这里执行了一下,结果报错,为什么?
debug assertion failde!program :E:\vc++\win32test\debug\win32test.exe file:afxwin1.inl line:22for information on how you program can cause an assertion failure ,see the viasual c++ documentation on asserts.(press retry to debug the applition) 终止 重试 忽略就这些!
包含的头文件不就都可以用了啊,有什么支持不支持的。
编译也可以通过,但一运行就出错了,不知为什么?比如我新建一个dialog,定为Cdlg,但在主程序里一domodal()就出错了,为何?
#include <afxext.h> // MFC extensions
#include <afxdisp.h> // MFC Automation classes
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
如下:LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_CREATE:
{
Cdia asd;
asd.DoModal();
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}主要是case wm_create 里,我加了一个cdia的类,在这里执行了一下,结果报错,为什么?
“主要是case wm_create 里,我加了一个cdia的类,在这里执行了一下,结果报错,为什么?
”
报什么错要所有的人去猜测是不是?@!@
file:afxwin1.inl
line:22for information on how you program can cause an assertion
failure ,see the viasual c++ documentation on asserts.(press retry to debug the applition) 终止 重试 忽略就这些!
应用程序发生异常 unknow software exception(0x80000003),位置0x5f47b0b3.要终止,按确定。
要调试,按取消
Cdia asd;
asd.DoModal();
再试
把
Cdia asd;
asd.DoModal();
注释一下
再试
注释都不出错了。
里面什么都没做。
Cdia asd;
改为
asd.DoModal();DialogBox(hInst, (LPCTSTR)IDD_DIALOG1, hWnd, (DLGPROC)NewDialog);
Cdia asd;
asd.DoModal();
改为
DialogBox(hInst, (LPCTSTR)IDD_DIALOG1, hWnd, (DLGPROC)NewDialog);
MFC 在WinMain里做了很多MFC其它类初始化工作,而你的 Win32 API工程中没有做这些初始化工作。在使用MFC类的时候当然会出错了。你可以看一下 MFC scr WinMain.cpp文件做了多少初始化工作。你的出错原因可以是:你的类中使用了MFC中没有被初始化的类。