CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    25

    WM_CLOSE does not function on a CPropertySheet window application !!!!! ????

    Dear all,

    I have made an application based on CPropertySheet window. It is working very well also. But in my property pages I have a lengthy process running in worker thread. While the thread is active and process is continuing, if somebody closes the window, the application exists silently. I need to get the information that user has pressed the close button(top right X button), because I want to warn the user and terminate the process before exit if he wishes. But when I mapped the WM_CLOSE on the property sheet it never worked ?!. Why?. I need an alert to be given before the window is deleted and hence the WM_DESTROY dont work. Please help?

    Thanks and regards
    Kareem.



  2. #2
    Join Date
    May 1999
    Location
    Farnborough, Hants, England
    Posts
    710

    Re: WM_CLOSE does not function on a CPropertySheet window application !!!!! ????

    In ClassWizard, go to the Info tab for your CPropertySheet class and change the Message Filter type to just 'Window'. This enables all messages in ClassWizard.

    Now add a handler for the WM_SYSCOMMAND message in this CPropertySheet window you want to trap, and replace the existing code with the following code:

    ---void CPropertySheetWindow::OnSysCommand(UINT nID, LPARAM lParam)
    {
    BOOL bAllowAction = TRUE ;

    if (nID == SC_CLOSE)
    {
    if (AfxMessageBox("Allow app to close?", MB_YESNO) == IDNO)
    bAllowAction = FALSE ;
    }

    if (bAllowAction)
    CPropertySheetWindow::OnSysCommand(nID, lParam);
    }




    ---

    This certainly works on a CFrameWnd, I think it will work for you - I think that for CPropertySheets, the WM_CLOSE is not generated.

    Does this help?



    --
    Jason Teagle
    [email protected]

  3. #3
    Join Date
    May 1999
    Posts
    25

    WM_CLOSE now gracefully works !!!

    Thank you for your unique solution. Thanks once again.

    Regards,
    Kareem.


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