Click to See Complete Forum and Search --> : WM_CLOSE does not function on a CPropertySheet window application !!!!! ????


abkareem
May 21st, 1999, 01:16 AM
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.

Jason Teagle
May 21st, 1999, 02:07 AM
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?

abkareem
May 21st, 1999, 04:35 AM
Thank you for your unique solution. Thanks once again.

Regards,
Kareem.