mfc 设置子窗口只打开一遍_如何关闭包括打开的所有子窗口在内的应用程序,MFC...

I have developed an application which is closed after certain time when user has done no movement either using the mouse and keyboard. The program works fine when my Home screen of the app is open, the program quits without any exception. In a scenario were my home screen is open and on click of button in home screen , another dialog box is open, and user gives no input the either from keyboard or mouse, in this case the application closes with an exception. Here's the code.

void CMainFrame::OnTimer(UINT_PTR nIDEvent)

{

LASTINPUTINFO li;

li.cbSize = sizeof(LASTINPUTINFO);

::GetLastInputInfo(&li);

// Calculate the time elapsed in seconds.

DWORD te = ::GetTickCount();

int elapsed = (te - li.dwTime) / 1000;

TRACE(_T("\n%d"),elapsed);

if(m_nAutoLogOffTime < elapsed)

{

switch (m_nAutoLogOffTime)

{

case AUTO_LOGOF_1MIN:

PostMessage(WM_CLOSE);

break;

case AUTO_LOGOF_3MIN:

PostMessage(WM_CLOSE);

break;

case AUTO_LOGOF_10MIN:

PostMessage(WM_CLOSE);

break;

}

}

CFrameWnd::OnTimer(nIDEvent);

}

so if I am in different window apart from MainFrame and their if the PostMessage(WM_CLOSE) is called then it gives exception. So can i close the application without exception, even if another dialog is open.

Please help me its urgent.Thanks in advance.

Error comes in doccore.h

Please check the image

解决方案ASSERT( AfxGetMainWnd()!=NULL );

AfxGetMainWnd()->SendMessage(WM_CLOSE);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值