Can anyone tell me what message windows sends when the close button is clicked on a standard (%WS_SYSMENU) type dialog. In other words, the X in the upper right-hand corner? Thanks.
Announcement
Collapse
No announcement yet.
Close button
Collapse
X
-
Here's some test code to demo what I believe you're after, plus illustrate to newbies how to use a central callback function for all events (PBDLL6):
(to cut & paste the code below with proper indentation, click on the "Edit/Delete Message" button above this message, select all, copy and paste)
#DIM ALL
#COMPILE EXE
#OPTION VERSION4
#INCLUDE "WIN32API.INC"
%ID_Button1 = 101
%ID_Button2 = 102
GLOBAL ghDlg AS LONG
CALLBACK FUNCTION MainCallback
SELECT CASE CBMSG
CASE %WM_INITDIALOG
MSGBOX "Initializing ..."
CASE %WM_CLOSE
MSGBOX "Closing ..."
CASE %WM_DESTROY
MSGBOX "Destroying ..."
END SELECT
SELECT CASE CBCTL
CASE %ID_Button1
IF CBCTLMSG = %BN_CLICKED THEN MSGBOX "Button1 clicked"
CASE %ID_Button2
IF CBCTLMSG = %BN_CLICKED THEN MSGBOX "Button2 clicked"
END SELECT
END FUNCTION 'MainCallback
FUNCTION PBMAIN () AS LONG
DIALOG NEW 0,"TEST", , , 150, 80, %WS_SYSMENU TO ghDlg
CONTROL ADD BUTTON,ghDlg,%ID_Button1,"Button1",10,20,50,20
CONTROL ADD BUTTON,ghDlg,%ID_Button2,"Button2",80,20,50,20
DIALOG SHOW MODAL ghDlg, CALL MainCallback
END FUNCTION
[This message has been edited by William Fletcher (edited January 06, 2000).]
Comment
-
Clicking the 'X' (close) button on a window/dialog generates a %WM_SYSCOMMAND message (with CBWPARAM = %SC_CLOSE). The window/dialog handler (aka Windows) responds by sending a %WM_CLOSE message to your application.
If you return non-zero to the WM_SYSCOMMAND|SC_CLOSE message, then the 'close' command is cancelled. This is useful for preventing a dialog from closing, for instance if edit box data was found to be invalid or missing, etc.
It's not generally a 'good idea' to respond to CBCTL messages unless CBMSG = %WM_COMMAND (the value of CBMSG could coincide with a button id under circumstances other than %WM_COMMAND. With these point in mind, try this modified source code:
Code:#DIM ALL #COMPILE EXE #OPTION VERSION4 #INCLUDE "WIN32API.INC" %ID_Button1 = 101 %ID_Button2 = 102 CALLBACK FUNCTION MainCallback SELECT CASE CBMSG CASE %WM_INITDIALOG MSGBOX "Initializing ..." CASE %WM_SYSCOMMAND IF CBWPARAM = %SC_CLOSE THEN MSGBOX "App close" ' FUNCTION = 1 CASE %WM_CLOSE MSGBOX "Closing ..." CASE %WM_DESTROY MSGBOX "Destroying ..." CASE %WM_COMMAND SELECT CASE CBCTL CASE %ID_Button1 IF CBCTLMSG = %BN_CLICKED THEN MSGBOX "Button1 clicked" CASE %ID_Button2 IF CBCTLMSG = %BN_CLICKED THEN MSGBOX "Button2 clicked" END SELECT END SELECT END FUNCTION 'MainCallback FUNCTION PBMAIN () AS LONG LOCAL hDlg AS LONG DIALOG NEW 0,"TEST", , , 150, 80, %WS_SYSMENU TO hDlg CONTROL ADD BUTTON,hDlg,%ID_Button1,"Button1",10,20,50,20 CONTROL ADD BUTTON,hDlg,%ID_Button2,"Button2",80,20,50,20 DIALOG SHOW MODAL hDlg, CALL MainCallback END FUNCTION
Lance
PowerBASIC Support
( mailto:[email protected][email protected]</A> )
Lance
mailto:[email protected]
Comment
-
f you return non-zero to the WM_SYSCOMMAND|SC_CLOSE message, then the 'close' command is cancelled. This is useful for preventing a
dialog from closing, for instance if edit box data was found to be invalid or missing, etc.
James
Comment
Comment