In MFC, which event works when user clicks on close button?
-
I need to handle and override the event that works when user presses the close button on the upper right (on the left of minimize and maximize buttons)? Thanks;)
That event is signaled via a
WM_SYSCOMMAND
notification message, with thewParam
value set toSC_CLOSE
.
Software Zen:
delete this;
-
I need to handle and override the event that works when user presses the close button on the upper right (on the left of minimize and maximize buttons)? Thanks;)
You could probably just handle the WM_CLOSE message and accomplish what you want.
-
I need to handle and override the event that works when user presses the close button on the upper right (on the left of minimize and maximize buttons)? Thanks;)
I agree with Curious_George since your app may be closed by other methods, such as right clicking on the app in the task bar and selecting close or using Alt-F4. Otherwise, use Spy++ to see what the message is. Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke
-
You could probably just handle the WM_CLOSE message and accomplish what you want.
-
Then either I'm not sure what you're trying to accomplish, or you went about it the wrong way. If you could post a code snippet (the part that didn't work), or if you could explain exactly what you are wanting to accomplish, then either myself or someone else would surely be able to help you.
-
I need to handle and override the event that works when user presses the close button on the upper right (on the left of minimize and maximize buttons)? Thanks;)
I process the WM_CLOSE message and override the virtual OnCancel() if it is a dialog to catch the close attempts. If you do not call the base class for either of those, your window will not close.
-
I process the WM_CLOSE message and override the virtual OnCancel() if it is a dialog to catch the close attempts. If you do not call the base class for either of those, your window will not close.
OK, I did the same. The window closes there is no problem with that. But the problem is; I am using a process which uses soundcard inside the program, I play some voice on soundcard, and I want to stop it before user presses close button and closes application. I have the function that closes my process, I implemented an event handler to the exit event on exit menu item, and it worked. I wanted to do the same for event that works when close button is pressed, but this time my application window closes but the process does not, it still works. And when I hook up Task Manager i see that my application is also still working, which shows me that my window is destroyed but the application is still running.