m_pMainWnd在MFC中更改为NULL

时间:2012-04-02 11:49:47

标签: c++ mfc

我在扩展WinApp的类的InitInstance函数中得到了这段代码:

m_pMainWnd = &m_Frame;  // Clearly setting m_pMainWnd to !NULL
m_Frame.LoadFrame(BMP_ICON, 0, NULL, NULL);

m_pMainWnd->GetMenu()->Detach();
m_pMainWnd->SetMenu(NULL);

m_Frame.ShowWindow(SW_SHOW);
m_Frame.UpdateWindow();

然而,在运行时,应用程序会打开,显示m_Frame一段时间,然后再次关闭。我得到了这个输出:

Warning: calling DestroyWindow in CWnd::~CWnd; OnDestroy or PostNcDestroy in derived class will not be called.
Warning: m_pMainWnd is NULL in CWinApp::Run - quitting application.
The thread 'Win32 Thread' (0x914) has exited with code 0 (0x0).
The program '[6628] VentSizerPro.exe: Native' has exited with code 0 (0x0).

所以沿着m_pMainWnd的某个地方已经改为NULL,但是在哪里以及为什么以及如何以及如何? :(

编辑:

m_Frame是一个类的实例,它使用CFrameWnd来修改窗口框架。

1 个答案:

答案 0 :(得分:8)

不要是白痴......你将指针值赋给了局部变量的值。