In the Aurora section of the forum peaslee solved how to intercept a dialog's Close Box. (http://www.ionicwind.com/forums/index.php?topic=5946.0)
This can be useful also in iWB, so here is the code:
CONST WM_SYSCOMMAND = 0x112
CONST SC_CLOSE = 0xF060
DIALOG dlg
'create the dialog
CREATEDIALOG dlg, 100,100,400,300, @CAPTION|@SYSMENU, 0, "Intercepting Dialog's Close Box", &HandlerDialog
'show the dialog
domodal dlg
END
'--------------------------------------------------------------------------------------------------------
SUB HandlerDialog(),int
Select @MESSAGE
Case WM_SYSCOMMAND
If (@CODE = SC_CLOSE > 0)
If MessageBox(dlg, "Do you really want to exit?", "Warning", @MB_YESNO|@MB_ICONQUESTION) = @IDYES
CloseDialog(dlg)
EndIf
EndIf
Return 1 :' Return non-zero value if you don't want to exit Dialog
endselect
ENDSUB
If either Windowssdk.inc or Windows.inc is included, omit the two first lines (the constant definitions)
Good Luck!
the above code has a structural flaw in it. The location of the "return 1" statement causes other sub commands of the WM_SYSCOMMAND message to be trapped and not passed on to the dialog handler. The problem doesn't show up in the simple example above but could in a different dialog/window application.
I have modified the above example to add just 3 more of the obvious subcommands (the max,min, and restore buttons)
CONST WM_SYSCOMMAND = 0x112
CONST SC_CLOSE = 0xF060
CONST SC_MAXIMIZE = 0xF030
CONST SC_MINIMIZE = 0xF020
CONST SC_RESTORE = 0xF120
DIALOG dlg
'create the dialog
CREATEDIALOG dlg, 100,100,400,300, @CAPTION|@SYSMENU|@MINBOX|@MAXBOX|@MAXIMIZED, 0, "Intercepting Dialog's Close Box", &HandlerDialog
'show the dialog
domodal dlg
END
'--------------------------------------------------------------------------------------------------------
SUB HandlerDialog(),int
Select @MESSAGE
Case WM_SYSCOMMAND
select @CODE
case SC_CLOSE
If MessageBox(dlg, "Do you really want to exit?", "Warning", @MB_YESNO|@MB_ICONQUESTION) = @IDNO
return 1:' Return non-zero value if you don't want to exit Dialog
EndIf
case SC_MAXIMIZE
If MessageBox(dlg, "Do you really want to maximize?", "Warning", @MB_YESNO|@MB_ICONQUESTION) = @IDNO
return 1
EndIf
case SC_MINIMIZE
If MessageBox(dlg, "Do you really want to minimize?", "Warning", @MB_YESNO|@MB_ICONQUESTION) = @IDNO
return 1
EndIf
case SC_RESTORE
If MessageBox(dlg, "Do you really want to restore?", "Warning", @MB_YESNO|@MB_ICONQUESTION) = @IDNO
return 1
EndIf
Endselect
endselect
RETURN 0
ENDSUB
As you can see I changed the messagebox question to test for a no response. If it it is no I return 1 which keep the handler from following the normal background message processing (signified by RETURN 0)
If you want the action taken (such as closing the dialog) there is no need to take an explicit action at this point; simply allow the message to take its normal path and the message will be processed normally.
Very simple when you understand what is really going on.
Thanks Larry, I did not think of that.