CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2001
    Posts
    306

    Question No closing with Alt-F4

    How can I avoid that the user closes the app by pressing Alt-F4 ?

    I thought that I can detect the key stroke with OnSysCommand in CMainFrame, but that did not work.

  2. #2
    Join Date
    Jun 2003
    Posts
    16
    Try this out:

    In your MainFrame.h file copy the following line of code

    #define IsALTpressed() ( (GetKeyState(VK_MENU) & (1 << (sizeof(SHORT)*8-1))) != 0 )


    Now in the "PreTranslateMessage" function of your MainFrame.cpp file include the following the following lines of code :

    BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
    {
    if(IsALTpressed() && pMsg->wParam==VK_F4)
    pMsg->wParam=VK_TAB;
    return CFrameWnd::PreTranslateMessage(pMsg);
    }

    that's all.

  3. #3
    Join Date
    Apr 2003
    Posts
    1,755

    Smile

    Take a look at how to not react for Alt-F4 thread. There are other threads regarding this matter. Try to look.

    Hope it will help you

  4. #4
    Join Date
    Jul 2001
    Posts
    306
    @rxbagain:
    thank you for the link to the other thread.
    There I can recommend the solution with the accelerator key from Gabriel Fleseriu.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured