首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

VS2010用Win32创建MFC窗口程序编译异常,窗口闪退

2013-07-09 
VS2010用Win32创建MFC窗口程序编译错误,窗口闪退来源:http://blog.csdn.net/misskissc/article/details/86

VS2010用Win32创建MFC窗口程序编译错误,窗口闪退

来源:http://blog.csdn.net/misskissc/article/details/8631532

1、MFCWinCret.h

#include "stdafx.h"
#include <afxwin.h>

class GameApp:public CWinApp
{
public:
public:
GameApp();
~GameApp();
virtual BOOL InitInstance();
};

class GameWnd:public CFrameWnd
{
public:
 GameWnd();
~GameWnd();
private:
DECLARE_MESSAGE_MAP();
};


2、MFCWinCret.cpp

#include "stdafx.h"
#include "MFCWinCret.h"
#include <afxwin.h>
#include "resource.h"

GameApp MyApp;


BOOL GameApp::InitInstance()
{
m_pMainWnd=new GameWnd();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();

return TRUE;
}

GameWnd::GameWnd()
{
CString strmyclass;
strmyclass="hi";
Create(NULL,strmyclass,WS_CAPTION|WS_THICKFRAME|WS_MINIMIZEBOX,CRect(40,50,500,500),NULL,NULL);
}

GameApp::GameApp()
{

}

GameApp::~GameApp()
{
delete m_pMainWnd;
}

GameWnd::~GameWnd()
{

}

BEGIN_MESSAGE_MAP(GameWnd,CFrameWnd)
END_MESSAGE_MAP()


3、stdafx.h

#include "targetver.h"
#include <afxwin.h>


4、stdafx.cpp
#include "stdafx.h"


5、targetver.h
#pragma once
#include <sdkddkver.h>


6、其他资源文件resource.h都为空

编译出现以下信息:
Warning: calling DestroyWindow in CWnd::~CWnd; OnDestroy or PostNcDestroy in derived class will not be called.
HEAP[game.exe]: Invalid address specified to RtlValidateHeap( 00A30000, 01788BE8 )

Windows 已在 game.exe 中触发一个断点。

其原因可能是堆被损坏,这说明 game.exe 中或它所加载的任何 DLL 中有 Bug。

------解决方案--------------------


窗口闪退通常是因为没有建立消息循环。

热点排行