程序设计中,派生出自己的按钮窗口,并且使用new 和creat函数创建了几个按钮,然后单击按钮弹出,一个模式对话框。
按钮中有自己的定时函数,当定时条件满足时,调用关闭并清除这个按钮窗口,在PostNcDestroy()
中delete this;删除按钮,但是此时不能关闭模式对话框,会出现
access violation 错误提示,错误定位到
LRESULT CWnd::Default()
{
// call DefWindowProc with the last message
_AFX_THREAD_STATE* pThreadState = _afxThreadState.GetData();
return DefWindowProc(pThreadState->m_lastSentMsg.message,
pThreadState->m_lastSentMsg.wParam, pThreadState->m_lastSentMsg.lParam);
}CWnd::Default() line 257 + 29 bytes
按钮的清除是这样实现的
void CRoundButton::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
TRACE1("timer%d",nIDEvent);
//find overtime destroy this button
//time is equal to DELAYTIME Micro at the start of file
//不能在这里关闭对话框,否则在按钮清除的过程中会出错,
//因为按钮清除时会向模式对话框发出消息,而此时对话框已经清除
//消息无法处理导致出错
HWND hWnd=::FindWindow(NULL,"数据显示");
if (hWnd!=NULL)
{
::SendMessage(hWnd,WM_CLOSE,NULL,NULL);
}
DestroyWindow();
}
void CRoundButton::PostNcDestroy()
{
// TODO: Add your specialized code here and/or call the base class
CControlButton::PostNcDestroy();
delete this;
}
请各位老手帮忙看看解决,是什么愿因造成的,谢谢
按钮中有自己的定时函数,当定时条件满足时,调用关闭并清除这个按钮窗口,在PostNcDestroy()
中delete this;删除按钮,但是此时不能关闭模式对话框,会出现
access violation 错误提示,错误定位到
LRESULT CWnd::Default()
{
// call DefWindowProc with the last message
_AFX_THREAD_STATE* pThreadState = _afxThreadState.GetData();
return DefWindowProc(pThreadState->m_lastSentMsg.message,
pThreadState->m_lastSentMsg.wParam, pThreadState->m_lastSentMsg.lParam);
}CWnd::Default() line 257 + 29 bytes
按钮的清除是这样实现的
void CRoundButton::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
TRACE1("timer%d",nIDEvent);
//find overtime destroy this button
//time is equal to DELAYTIME Micro at the start of file
//不能在这里关闭对话框,否则在按钮清除的过程中会出错,
//因为按钮清除时会向模式对话框发出消息,而此时对话框已经清除
//消息无法处理导致出错
HWND hWnd=::FindWindow(NULL,"数据显示");
if (hWnd!=NULL)
{
::SendMessage(hWnd,WM_CLOSE,NULL,NULL);
}
DestroyWindow();
}
void CRoundButton::PostNcDestroy()
{
// TODO: Add your specialized code here and/or call the base class
CControlButton::PostNcDestroy();
delete this;
}
请各位老手帮忙看看解决,是什么愿因造成的,谢谢
解决方案 »
- 【新手求助】win32 模态对话框显示后没有边框
- 请教 VC++ error C2678 错误
- 'MCI_ClOSE' : undeclared identifier
- ###进来进来,男人都喜欢的快来玩
- openschema方法如何得到数据库的约束信息(在线等!!)
- 急,帮朋友弄个串口程序要在类和类之间传递一个HANDLE,怎么解决呢
- 什么地方可以找到CGI/ISAPI标准的资料?
- 怎样这个动态连接库里的"test"函数?
- 在线等.高分请教如何用vc2005生成一个VBScript可调用的dll?
- MFC中如何获取指针
- 求visual stdio高手,关于从vc6移植到vs2005的一个程序
- 如何实现监控某程序运行窗口内出现关键字后,关闭程序或是重启计算机
你可以用GetSafeWnd()判断是否已经创建,如果创建了,直接ShowWindow(1)就可以了
if(dlg.GetSafeWnd() == NULL)
dlg.Create(...);
dlg.ShowWindow(1);
pThreadState->m_lastSentMsg.wParam, pThreadState->m_lastSentMsg.lParam);里面的谋些汇编语言中,此时堆栈里面 pThreadState->m_lastSentMsg的值是0x00000000202这样的值。
if(hDlg)
{
if(::SendMessageW(hDlg,WM_COMMAND,MAKEWORD(IDOK,BN_CLICKED),(LPARAM)this->GetSafeHwnd()))
{
KillTimer(1);//设置Timer的IDEvent为1;
DestroyWindow();
} } //CButton::OnTimer(nIDEvent);
这里_T("Dialog")是弹出模态对话框的标题。我已经试过,可以的。