Discussion:
windows shutdown notification
(too old to reply)
rahul
2012-05-16 04:27:57 UTC
Permalink
Is there any way to make MFC application being notified at windows
shutdown event.
I have tried WM_QUERYWNDSESSION message but it didn't help.
Can anybody send me code to do that??
David Lowndes
2012-05-16 07:00:52 UTC
Permalink
Post by rahul
Is there any way to make MFC application being notified at windows
shutdown event.
I have tried WM_QUERYWNDSESSION message but it didn't help.
WM_QUERYENDSESSION should be the message to handle.

When you say "it didn't help", what exactly do you mean?

Dave
rahul
2012-05-16 08:03:16 UTC
Permalink
Post by David Lowndes
Post by rahul
Is there any way to make MFC application being notified at windows
shutdown event.
I have tried WM_QUERYWNDSESSION message but it didn't help.
WM_QUERYENDSESSION should be the message to handle.
When you say "it didn't help", what exactly do you mean?
Dave
I developed dialog based application in vc++ 6.0.
There is no OnQueryEndSession() function in classwizard i manually add
that in header file, source file and also in messagemap
(ON_WM_QUERYENDSESSION macro) and run application.
But when i put breakpoint and run application in debug mode and
shutdown PC breakpoint doesn't hit and PC shutdown.
Why??
rahul
2012-05-16 08:19:07 UTC
Permalink
developed a dialog based application in VC++ 6.0. I manually added
afx_msg BOOL OnQueryEndSession() in header file
ON_WM_QUERYENDSESSION() in message macro
and
BOOL CSomeDlg::OnQueryEndSession()
{
return FALSE;
}

in cpp file.

When I run the application in debug mode and put the breakpoint in
above
function and then shutdown pc
breakpoint should be hit.
but breakpoint didn't hit and windows shuts down normally.
---------------------------

I want my application displays some message box before windows shut
down..
How this could be done?
David Lowndes
2012-05-16 22:59:45 UTC
Permalink
Post by rahul
developed a dialog based application in VC++ 6.0. I manually added
afx_msg BOOL OnQueryEndSession() in header file
ON_WM_QUERYENDSESSION() in message macro
and
BOOL CSomeDlg::OnQueryEndSession()
{
return FALSE;
}
in cpp file.
When I run the application in debug mode and put the breakpoint in
above
function and then shutdown pc
breakpoint should be hit.
but breakpoint didn't hit and windows shuts down normally.
I don't know what you've got wrong - everything you've mentioned looks
fine. I've just added a handler for WM_QUERYENDSESSION to a default
MFC dialog application using VS2008 and the breakpoint was hit. I can
see no real differences in what the tool generated and what you
mentioned above.

Dave
rahul
2012-05-17 04:10:06 UTC
Permalink
Post by David Lowndes
Post by rahul
developed a dialog based application in VC++ 6.0. I manually added
afx_msg BOOL OnQueryEndSession() in header file
ON_WM_QUERYENDSESSION() in message macro
and
BOOL CSomeDlg::OnQueryEndSession()
{
return FALSE;
}
in cpp file.
When I run the application in debug mode and put the breakpoint in
above
function and then shutdown pc
breakpoint should be hit.
but breakpoint didn't hit and windows shuts down normally.
I don't know what you've got wrong - everything you've mentioned looks
fine. I've just added a handler for WM_QUERYENDSESSION to a default
MFC dialog application using VS2008 and the breakpoint was hit. I can
see no real differences in what the tool generated and what you
mentioned above.
Dave
I just want to know, if everything goes right, and if we return FALSE
in OnQueryEndSession() what will heppan? Windows will not shut down pc?
David Lowndes
2012-05-17 07:25:22 UTC
Permalink
Post by rahul
I just want to know, if everything goes right, and if we return FALSE
in OnQueryEndSession() what will heppan? Windows will not shut down pc?
That's what the documentation says.

Dave
Farnsworth
2012-05-17 10:23:22 UTC
Permalink
Post by David Lowndes
Post by rahul
I just want to know, if everything goes right, and if we return FALSE
in OnQueryEndSession() what will heppan? Windows will not shut down pc?
That's what the documentation says.
Actually, it could in some cases like in terminal servers. It's very common
for administrators to log off disconnected sessions, or set it to auto log
off if disconnected after a period of time. When that happens, your
application that might be displaying "Do you want to save?" prompt will be
allowed only 5 seconds to terminate, after that, the process is
automatically killed. This is because the session is disconnected and
invisible, so no one is responding to the Save prompt. This is documented
somewhere in MSDN.
Farnsworth
2012-05-16 19:28:24 UTC
Permalink
Post by rahul
Post by David Lowndes
Post by rahul
Is there any way to make MFC application being notified at windows
shutdown event.
I have tried WM_QUERYWNDSESSION message but it didn't help.
WM_QUERYENDSESSION should be the message to handle.
When you say "it didn't help", what exactly do you mean?
Dave
I developed dialog based application in vc++ 6.0.
There is no OnQueryEndSession() function in classwizard i manually add
that in header file, source file and also in messagemap
(ON_WM_QUERYENDSESSION macro) and run application.
But when i put breakpoint and run application in debug mode and
shutdown PC breakpoint doesn't hit and PC shutdown.
Why??
I think that Windows doesn't send this message to every window, only top
level windows. Try using Spy++ to see if your window is a child of another
window, or use GetAncestor(GA_PARENT), which should return 0.
rahul
2012-05-17 04:06:33 UTC
Permalink
Post by Farnsworth
Post by rahul
Post by David Lowndes
Post by rahul
Is there any way to make MFC application being notified at windows
shutdown event.
I have tried WM_QUERYWNDSESSION message but it didn't help.
WM_QUERYENDSESSION should be the message to handle.
When you say "it didn't help", what exactly do you mean?
Dave
I developed dialog based application in vc++ 6.0.
There is no OnQueryEndSession() function in classwizard i manually add
that in header file, source file and also in messagemap
(ON_WM_QUERYENDSESSION macro) and run application.
But when i put breakpoint and run application in debug mode and
shutdown PC breakpoint doesn't hit and PC shutdown.
Why??
I think that Windows doesn't send this message to every window, only top
level windows. Try using Spy++ to see if your window is a child of another
window, or use GetAncestor(GA_PARENT), which should return 0.
Main dialog( in which i kept handler) in dialod based application is
top level window.
Tom Sherren
2012-05-24 14:12:20 UTC
Permalink
Post by rahul
Post by David Lowndes
Post by rahul
Is there any way to make MFC application being notified at windows
shutdown event.
I have tried WM_QUERYWNDSESSION message but it didn't help.
WM_QUERYENDSESSION should be the message to handle.
When you say "it didn't help", what exactly do you mean?
Dave
I developed dialog based application in vc++ 6.0.
There is no OnQueryEndSession() function in classwizard i manually add
that in header file, source file and also in messagemap
(ON_WM_QUERYENDSESSION macro) and run application.
But when i put breakpoint and run application in debug mode and
shutdown PC breakpoint doesn't hit and PC shutdown.
Why??
Perhaps the problem is due to the app being dialog based.

I have a vc++ 6.0 application that has a a main frame derived from CFrameWnd.
WM_QUERYENDSESSION works for this program as follows.


IMPLEMENT_DYNCREATE(CMyMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMyMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CCMyMainFrame)
ON_WM_CREATE()
ON_WM_INITMENUPOPUP()
ON_WM_SIZE()
ON_WM_MENUSELECT()
ON_WM_MOVE()
ON_WM_QUERYENDSESSION()
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()



// Ask the user if they want to save data before
// closing the application.

BOOL CMyMainFrame::OnQueryEndSession()
{
if (!CFrameWnd::OnQueryEndSession())
return FALSE;

if (!g_pDoc->AskSaveDataQuestion()) // part of my app
{
// User said "Cancel" so keep the windows session open
return FALSE;
}

return TRUE;
}
Bob Moore
2012-05-26 21:45:50 UTC
Permalink
Post by rahul
I developed dialog based application in vc++ 6.0.
There is no OnQueryEndSession() function in classwizard i manually add
that in header file, source file and also in messagemap
It's being filtered out. Go to the Class Info tab in ClassWizard and
change the message filter to Window.

I can't see any error in the method you've posted. Did you add

afx_msg BOOL OnQueryEndSession();

between the AFX_MSG macros ?

--
Bob Moore
http://bobmoore.mvps.org/

Stephen Wolstenholme
2012-05-16 09:31:06 UTC
Permalink
Post by rahul
Is there any way to make MFC application being notified at windows
shutdown event.
I have tried WM_QUERYWNDSESSION message but it didn't help.
Can anybody send me code to do that??
WM_CLOSE ?

Steve
--
Neural Network Software. http://www.npsl1.com
EasyNN-plus. Neural Networks plus. http://www.easynn.com
SwingNN. Forecast with Neural Networks. http://www.swingnn.com
JustNN. Just Neural Networks. http://www.justnn.com
Continue reading on narkive:
Loading...