请问何时释放的m_pMainWnd 呢?

afgkidy 2010-01-14 11:10:21
MFC的重写函数InitInstance中,有创建窗口代码如:m_pMainWnd = new CMainWindow;问m_pMainWnd在哪里被释放的呢?

CWinApp 和CWinThread 类,没有看到对m_pMainWnd释放。

没有重写ExitInstance,且CWinApp和CWinThread中的ExitInstance似乎也没有看到对m_pMainWnd释放。
...全文
128 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
marrco2005 2010-01-14
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 afgkidy 的回复:]
但是也没找到类似于m_pMainWnd->PostNcDestroy() 这样的代码。
[/Quote]
这个不是你主动调用的
是MFC框架自己调用的
你在这个函数里打一个断点,你就清楚了
hill_qd 2010-01-14
  • 打赏
  • 举报
回复
你看看主程序在哪里销毁框架窗口的?他应该发送WM_DESTROY消息,这个消息应该能顺序找到这个函数
afgkidy 2010-01-14
  • 打赏
  • 举报
回复
没找到,不知道在哪地方。
hill_qd 2010-01-14
  • 打赏
  • 举报
回复
是通过发送消息的方式,然后cmainframe对象接收到消息后,进行自我销毁的,这个不用我们手动作的
不说害怕 2010-01-14
  • 打赏
  • 举报
回复
在MFC框架里哈
afgkidy 2010-01-14
  • 打赏
  • 举报
回复
但是也没找到类似于m_pMainWnd->PostNcDestroy() 这样的代码。
marrco2005 2010-01-14
  • 打赏
  • 举报
回复
void CFrameWnd::PostNcDestroy()
{
// default for frame windows is to allocate them on the heap
// the default post-cleanup is to 'delete this'.
// never explicitly call 'delete' on a CFrameWnd, use DestroyWindow instead
delete this; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 这里销毁的
}
ripyu 2010-01-14
  • 打赏
  • 举报
回复
销毁main window的时候释放了
afgkidy 2010-01-14
  • 打赏
  • 举报
回复
我的问题是没有找到这个释放m_pMainWnd的地方。
liumenghappy 2010-01-14
  • 打赏
  • 举报
回复
CWinApp 关闭时会析构它的变量m_pMainWnd,调用CMainWindow的析构函数
afgkidy 2010-01-14
  • 打赏
  • 举报
回复
我在基类中(CWinApp 和CWinThread 类)也没有找到释放的地方!
快乐鹦鹉 2010-01-14
  • 打赏
  • 举报
回复
m_pMainWnd是基类的变量,应该在基类的析构中被释放掉的。
luhongyu2108 2010-01-14
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 marrco2005 的回复:]
引用 7 楼 afgkidy 的回复:
但是也没找到类似于m_pMainWnd->PostNcDestroy() 这样的代码。

这个不是你主动调用的
是MFC框架自己调用的
你在这个函数里打一个断点,你就清楚了
[/Quote]
SkinMagicToolkit 一:文件说明 SkinMagicLib.h 必须的头文件,请添加到工程中。 SkinMagic.lib + SkinMagic.dll 动态链接库配套使用 编译时需要在工程中添加SkinMagic.dll,程序运行时需要SkinMagic.dll 以下版本的编译出来的程序运行时不再依赖SkinMagic.dll SkinMagicLibMD6.lib 静态链接库,用于VC6的Release版编译 SkinMagicLibMT6.lib 静态链接库,用于VC6的Debug版编译 二:使用步骤 1。把SkinMagicLib.h, SkinMagicLibMT6.lib, SkinMagicLibMD6.lib放到你的VC6工程目录下 2。在StdAfx.h中添加 #include "SkinMagicLib.h" 3。在工程设置中添加对应的库 Win32 Release中填上SkinMagicLibMD6.lib Win32 Debug中填上SkinMagicLibMT6.lib 4。在InitInstance()函数的开始处添加初始化SkinMagic资源的代码。 VERIFY(1 == InitSkinMagicLib(AfxGetInstanceHandle(), NULL, NULL, NULL)); 5。在InitInstance()函数中加载皮肤文件并设置程序皮肤。 你可以选择添加皮肤文件到资源中,并编译到程序中。或者程序在运行时动态加载皮肤文件 a. 比如添加corona.smf,设置资源类型为"SKINMAGIC", 资源ID为IDR_SKIN_CORONA CBossKeyDlg dlg; m_pMainWnd = &dlg; //加载SkinMagic皮肤 VERIFY(1 == LoadSkinFromResource(NULL, (LPSTR)IDR_SKIN_CORONA, "SKINMAGIC")); VERIFY(1 == SetWindowSkin(m_pMainWnd->m_hWnd, "MainFrame")); VERIFY(1 == SetDialogSkin("Dialog")); int nResponse = dlg.DoModalEx(bStartShow); if (nResponse == IDOK) { } else if (nResponse == IDCANCEL) { } b. 程序在运行时动态加载皮肤文件 CBossKeyDlg dlg; m_pMainWnd = &dlg; //加载SkinMagic皮肤 VERIFY(1 == LoadSkinFile("corona.smf")); VERIFY(1 == SetWindowSkin(m_pMainWnd->m_hWnd, "MainFrame")); VERIFY(1 == SetDialogSkin("Dialog")); int nResponse = dlg.DoModalEx(bStartShow); if (nResponse == IDOK) { } else if (nResponse == IDCANCEL) { } 6。在ExitInstance()函数中释放SkinMagic资源 //释放SkinMagic资源: ExitSkinMagicLib();
本资源含大量的图像处理代码(C++) int kind = 0; // 图像类型(8位kind=1,24位kind=3,初始化kind=0) LONG Bytes = 0; // 图像分配内存的最大值 BOOL Step; // 菜单上一步、下一步启动禁用标志 -> FALSE为下一步禁用 BOOL Step_All = TRUE; // 初始化上一步、下一步 -> TRUE为禁用 BOOL fdj = TRUE; // 可以使用放大镜的标志 int screen_width = GetSystemMetrics(SM_CXSCREEN); // 获取屏幕宽度 int screen_height = GetSystemMetrics(SM_CYSCREEN); // 获取屏幕高度 BOOL DirectDraw_Pause = FALSE; // DirectDraw显示时键盘中断标志 int Match_x = 0; // 模板匹配中左上方坐标 - 行 int Match_y = 0; // 模板匹配中左上方坐标 - 列 CString Match_result = ""; // 模板匹配结果 SOCKET m_socket; // 定义一个套接字 ///////////////////////////////////////////////////////////////////////////// // CMy002App initialization BOOL CMy002App::InitInstance() { // *** 判断程序是否已运行 *** HANDLE hMutex; // 定义一个句柄 // 创建一个互斥对象,并返回句柄 hMutex = CreateMutex(NULL, TRUE, "7 4 的程序"); // 主线程拥有互斥对象,相当于一次请求互斥对象 // hMutex = CreateMutex(NULL, FALSE, "7 4 的程序"); // 主线程不拥有互斥对象 // WaitForSingleObject(hMutex,INFINITE); // 请求互斥对象 if (hMutex) // 判断句柄是否有值 { if (ERROR_ALREADY_EXISTS == GetLastError()) // 判断程序是否已运行 { AfxMessageBox("该应用程序已运行! ", MB_ICONINFORMATION | MB_OK); ExitProcess(0); // 退出应用程序 } } ReleaseMutex(hMutex); // 释放互斥对象 // *** 登陆密码对话框 *** Password dlg; // 定义对话框对象 dlg.DoModal(); // 显示并运行模态对话框 - 用户登录对话框 // CG: The following block was added by the Splash Screen component. \ { \ CCommandLineInfo cmdInfo; \ ParseCommandLine(cmdInfo); \ \ C_SplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash); \ } AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif // Change the registry key under which our settings are stored. // TODO: You should modify this string to be something appropriate // such as the name of your company or organization. SetRegistryKey(_T("Local AppWizard-Generated Applications")); LoadStdProfileSettings(); // Load standard INI file options (including MRU) // Register the application's document templates. Document templates // serve as the connection between documents, frame windows and views. CMultiDocTemplate* pDocTemplate; pDocTemplate = new CMultiDocTemplate( IDR_MY002TYPE, RUNTIME_CLASS(CMy002Doc), RUNTIME_CLASS(CChildFrame), // custom MDI child frame RUNTIME_CLASS(CMy002View)); AddDocTemplate(pDocTemplate); // create main MDI Frame window CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; m_pMainWnd = pMainFrame; // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // 启动时不打开子窗口 cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; // The main window has been initialized, so show and update it. pMainFrame->ShowWindow(m_nCmdShow); pMainFrame->UpdateWindow(); return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog // *** 关于对话框 *** { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) //}}AFX_MSG_MAP END_MESSAGE_MAP() // App command to run the dialog void CMy002App::OnAppAbout() { CAboutDlg aboutDlg; aboutDlg.DoModal(); } ///////////////////////////////////////////////////////////////////////////// // CMy002App message handlers BOOL CMy002App::PreTranslateMessage(MSG* pMsg) { // CG: The following lines were added by the Splash Screen component. if (C_SplashWnd::PreTranslateAppMessage(pMsg)) return TRUE; return CWinApp::PreTranslateMessage(pMsg); }

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧