我的想法是:在App类的PreTranslateMessage函数中设置一个timer用于计时。再设置一个全局变量在OnTimer中记录时间,每次PreTranslateMessage收到消息,并且不是wm_timer的时候,就把这个变量清零,重新开始计时。

解决方案 »

  1.   

    怎么编写这个timer及其函数呢?timer在哪定义?在PreTranslateMessage中吗?怎么才会激活?
      

  2.   

    在OnInitInstance中调用AfxGetMainWnd()->SetTimer(1,1000,NULL)设置一个timer,然后在PreTranslateMessage中:
    BOOL CMFCApp::PreTranslateMessage(MSG* pMsg) 
    {
    if(pMsg->message==WM_TIMER)
    {
    if(++nTime>=YourTimeLimit)
    AfxGetMainWnd()->SendMessage(WM_CLOSE); }
    else
    nTime=0; return CWinApp::PreTranslateMessage(pMsg);
    }
    其中nTime是一个全局变量,用来记录用户持续无操作的时间。