1

大多数如何创建桌面警报的示例如下所示。它使用 new 关键字创建新的 CMFCDesktopAlertWnd,用于创建 CMFCDesktopAlertDialog。这些示例都没有在函数末尾删除对象,所以我想有些东西正在释放内存。什么是释放内存?

CMFCDesktopAlertWnd* pPopup = new CMFCDesktopAlertWnd;
// int m_nAnimation
pPopup->SetAnimationType ((CMFCPopupMenu::ANIMATION_TYPE) m_nAnimation);

// int m_nAnimationSpeed
pPopup->SetAnimationSpeed (m_nAnimationSpeed);

// int m_nTransparency
pPopup->SetTransparency ((BYTE)m_nTransparency);

// BOOL m_bSmallCaption
pPopup->SetSmallCaption (m_bSmallCaption);

// BOOL m_bAutoClose, int m_nAutoCloseTime
pPopup->SetAutoCloseTime (m_bAutoClose ? m_nAutoCloseTime * 1000 : 0);

// int m_nPopupSource
if (m_nPopupSource == 0)
{
   // int m_nVisualMngr
   // CPoint m_ptPopup
   // The this pointer points to a CDesktopAlertDemoDlg class which extends the CDialogEx class.
   if (m_nVisualMngr == 5)  // MSN-style
   {
      pPopup->Create (this, IDD_DIALOG2, NULL, m_ptPopup, RUNTIME_CLASS (CMSNDlg));
   }
   else
   {
      pPopup->Create (this, IDD_DIALOG1, 
      m_menuPopup.GetSubMenu (0)->GetSafeHmenu (), m_ptPopup, RUNTIME_CLASS (CMyPopupDlg));
   }
}
4

2 回答 2

1

你可以看看源代码:

void CMFCDesktopAlertWnd::OnNcDestroy()
{
    CWnd::OnNcDestroy();
    delete this;
}

当窗口被销毁时,WM_NCDESTROY 消息会删除分配的内存。

于 2012-05-29T20:54:58.467 回答
0

微软建议删除这属于PostNcDestroy()而不是OnNcDestroy()方法,我已经看到一些崩溃,comctl32!ComboBox_WndProc()当删除太早完成时,我会尝试引用释放的内存,即在OnNcDestroy().

于 2014-01-24T15:13:11.190 回答