CMainFrame 窗体中用OnTimer定时器控制程序退出,异常报错.
设置定时器:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
SetTimer(1,100,NULL);
return 0;
}
关闭窗体.
void CMainFrame::OnTimer(UINT nIDEvent)
{
PostNcDestroy();
CFrameWnd::OnTimer(nIDEvent);
}
void CMainFrame::OnDestroy()
{
CFrameWnd::OnDestroy();
KillTimer(1);
}
void CMainFrame::PostNcDestroy()
{
// TODO: Add your specialized code here and/or call the base class
CFrameWnd::PostNcDestroy();
delete this;
}
以上为源码,程序退出后要异常报错一下,不知该怎么解决!谢谢