Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Which message Window send to my app before it close?

Status
Not open for further replies.

JimmyK

Programmer
Sep 8, 2000
142
VN
Hi,
I make an small exe file without window
i want to know which message my EXE receive before it has to close (eg When user Shutdown or Restart)
The code is like this

stream = fopen( "c:\\Windows\\bootlog.txt", "a+" );
MSG msg;
while (GetMessage(&msg, NULL,0,0))
{
fprintf( stream, "MSG %i\n",msg.message);
TranslateMessage(&msg); /* translate keyboard message*/
DispatchMessage(&msg); /* return contro, to window 98*/
}
fclose( stream );
return 0;


i run this EXE, and restart windows, but my log file is nothing (just)

Note: My EXE create no window

Thank
Jimmy Le
nhan_tiags@yahoo.com
 
Greetinx!

Before Shotdown your app receives the message named WM_QUERYENDSESSION and if app returns a true (or false i dont remember) value, windows does not finish it session.
Before quit your app receives the message named WM_QUIT.
Happy programming!))
 
Thank Pavlo,

As you told, my log file must have a line [Msg 16] or something like this?
But, when i check this file, there is nothing!!

What i want is: writing something to log file before my app quit.
i am still waiting for your helps, guys.

Thank

Jimmy Le
nhan_tiags@yahoo.com
 
First of all, (If I remember correctly) "bootlog.txt" is a file name that is already reserved for use by the operating system. Your problem could be that after your fclose(), the operating system writes to the file, thus overwriting anything your application may have written. The first thing you should try is to change the name of your log file to something like "MyMsgLog.txt". WM_QUERYENDSESSION is sent to see if your application is ready to quit. WM_ENDSESSION is sent when Windows is actually performing the shutdown.
 
If your program can quit safely you should return TRUE after processing the WM_QUERYENDSESSION. When you receive the WM_ENDSESSION message the WPARAM parameter will be TRUE if the system is shutting down or FALSE if an application has indicated it can not shut down properly. This allows you deal with any process that Windows cannot shut down properly(console windows for instance in win95/98) and restart them if nesessary if the endsession is cancelled.

Because WM messages are targeted to specific windows you will need to create one(a hidden one will do) and use that to process messages like WM_QUERYENDSESSION, WM_ENDSESSION etc. EMail: lgworks at uklinux.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top