When the user shuts down MyApp, I want my SaveWindowPosition(hDlg) routine to store the proper values in MyApp.ini...
There are two ways to exit MyApp:
- the sysmenu's X button
- my own Quit command button
My Quit button is created as part of the main dialog, but has its own callback:
SaveWindowPosition(hDlg) doesn't seem to be working here, and I'm presuming that by the time we arrive here, hDlg is no longer valid. Added: NOPE! It works fine, but is missed by exiting via the sysmenu X button.
So I looked for info in the SDK about how to capture the X button from the sysmenu. Here's what I found:
I also searched lots of source code on the forum and found people also used the wm_destroy message.
SO, I turned my attention to my main dialog's callback DlgProc(). It would appear that I have the following two choices:
Added:
By putting a msgbox in each point in code, I see that:
- clicking the Quit button, the Quit CB gets processed first, then we go through the wm_command/CB.CTL=idcancel, and finally we go through wm_destroy
- clicking on the sysmenu's X button, we go through the wm_command/CB.CTL=idcancel, and through wm_destroy
and that the same hDlg value is available at all 3 points.
QUESTION: Is there a good reason to use wm_command/CB.CTL=idcancel versus wm_destroy, (or NOT to)??
Thanks!
There are two ways to exit MyApp:
- the sysmenu's X button
- my own Quit command button
My Quit button is created as part of the main dialog, but has its own callback:
Code:
CallBack Function CB_Quit() As Long Local lResult As Long If Cb.Msg = %wm_command And CbCtlMsg = %bn_clicked Then If gConfirm Then lResult = MsgBox ("Are you sure?",%mb_yesno,"Quit?") If lResult = %idno Then Exit Function End If SaveWindowPosition(hDlg) Dialog End Cb.Hndl, 0 ' Return 0 Function = 1 ' no further processing... End If End Function
So I looked for info in the SDK about how to capture the X button from the sysmenu. Here's what I found:
When the user chooses the Close command, Windows sends a WM_COMMAND message to the dialog box procedure with the wParam parameter set to IDCANCEL.
SO, I turned my attention to my main dialog's callback DlgProc(). It would appear that I have the following two choices:
Code:
Select Case CbMsg Case %wm_command If Cb.Ctl = %IDCANCEL Then SaveWindowPosition(hDlg) End If Case %wm_destroy SaveWindowPosition(hDlg)
By putting a msgbox in each point in code, I see that:
- clicking the Quit button, the Quit CB gets processed first, then we go through the wm_command/CB.CTL=idcancel, and finally we go through wm_destroy
- clicking on the sysmenu's X button, we go through the wm_command/CB.CTL=idcancel, and through wm_destroy
and that the same hDlg value is available at all 3 points.
QUESTION: Is there a good reason to use wm_command/CB.CTL=idcancel versus wm_destroy, (or NOT to)??
Thanks!
Comment