The OnOK(), OnCancel() and OnClose() functions are merly handlers for messages that gets sent when your button (I am assuming these are linked to a button) gets pressed. The previous poster mentioned creating a handler function for the WM_ENDSESSION message. This could be one possible solution to your problem.
My solution uses the fact that the WinApp::ExitInstance() function gets called whenever the user choses to exit their windows session.
Every MFC application should have a WinApp derived class, called something like MyProgApp, or something similar with the App appended to your class name.
Now this function isn't visible by default, so you need to override this function using the Classwizard (if using VS6), or the properties window (if using VS7.1).
You can then write your logging code within the function, but remember to call the base class at the end (or your app won't exit).
// CLEANUP STUFF
return CWinApp::ExitInstance(); // base class
The system sends the message, so all you have to do is capture that message and then do your stuff.
( return FALSE after a WM_QUERYENDSESSION is received and then capture the WM_ENDSESSION and check if system is really shutting down and do your stuff before returning from this message...
Yes, I found this in MSDN under "Synchronization Objects":
In some circumstances, you can also use a file, named pipe, or communications device as a synchronization object; however, their use for this purpose is discouraged. Instead, use asynchronous I/O and wait on the event object set in the OVERLAPPED structure. It is safer to use the event object because of the confusion that can occur when multiple simultaneous overlapped operations are performed on the same file, named pipe, or communications device. In this situation, there is no way to know which operation caused the object's state to be signaled.
I need to modify a 16 color bmp and then save it as a seperate file. I loaded a 16 color 48x48 bmp file on DC using the LoadImage() and BitBlt() API. Using GDI functions, I change the display on the DC, say draw a line on the DC, on top of the image displayed. Now I need to capture the current DC ( bmp image + the changes,i.e., the line) and create a new BMP file.
For 256 color and 16 color BMP file, the new BMP created is a plain white imgage, if I load the image with 'LR_CREATEDIBSECTION' flag in LoadImage API. else I get am able to create the file, but the image size is different. For the 24 bpp the application is working fine. Where am i doing wrong. I am using the 'CreateCompatibleBitmap()' to create the bitmap from DC. Is there any other way?.