' Created by by Jason DAngelo
' This is NOT a 100% complete list of all functions/calls/notices...
' This is just a wide-guide, which can be used as a generic template.
' Well, if you remove all the miles of comments, it might be a nice guide.
' NOTE: This is NOT an MDI-Child/Parent sample. These are parent/child by assignment.
#MINVERSION 1.7.0.0
#SCRIPTVERSION 1.0.0.1
USES "UI"
Declare Function DestroyWindow Lib "user32.dll" ALIAS "DestroyWindow"(ByVal hWnd As Long) As Long
' -- ID numbers of controls
BEGIN CONST
%menuFILE = 1000
%menuCHILD_OP
%menuEXIT_OP
%btnCOMMAND ' NOTE: There are three buttons, +0, +1, +2. Keep that in mind if you add more stuff.
' -- The ID's for more functions must be %MyNewConstant = %btnCOMMAND + 3 + 1
' -- The +3 is 0-2 and the +1 is the incrament designated for the new constant.
END CONST
GLOBAL hWnd, hMenu, hMenuFile, hWndChild AS LONG
' -- Create dialog here
FUNCTION TBMAIN()
DIALOG NEW PIXELS, 0, "Parent Window",-1,-1, 300, 180, _
%WS_CLIPCHILDREN OR %WS_CLIPSIBLINGS OR %WS_OVERLAPPEDWINDOW, _
%WS_EX_APPWINDOW TO hWnd
' -- Place NON-CALLBACK controls here
' -- Simple Menu
MENU NEW BAR TO hMenu
' -- FILE Menu
MENU NEW POPUP TO hMenuFile
MENU ADD POPUP, hMenu, "&File", hMenuFile, %MF_ENABLED
MENU ADD STRING, hMenuFile, "&New CHILD Window", %menuCHILD_OP, %MF_ENABLED
MENU ADD STRING, hMenuFile, "&Exit", %menuEXIT_OP, %MF_ENABLED
MENU ATTACH hMenu, hWnd
DIALOG SHOW MODAL hWnd, CALL mainProc()
END FUNCTION
' -- Callback Function for hWnd (MAIN) dialog/window
CALLBACK FUNCTION mainProc() AS LONG
' -- CBMSG is the primary "Notice" Message
' -- Followed by, CBCTL, which is a Control ID value (%MyConstant)
' -- Followed by, CBCTLMSG, which is the "Notice" Message of a control.
' -- NOTE: You can't have a "Message", without a control. Do not check for "Notice" first.
' -- SAMPLE: CBMSG=(%WM_COMMAND) and -> CBCTL=(%btnCOMMAND) and -> CBCTLMSG=(%BN_CLICKED)
SELECT CASE CBMSG
CASE %WM_CREATE
' -- Once the "CallBack Handle" has been assigned, and the window "Cloned"
' -- This is the first event notice that triggers.
' -- (After the %WM_PARENTNOTIFY to the parent of this child.)
CASE %WM_INITDIALOG
' -- Put code to be executed after dialog creation here.
' -- Here is where you should place any controls that have a CALLBACK
' -- Understand that there will be TWO callbacks, this one for the
' -- parent of the control, and the callback for the actual control.
CASE %WM_SHOWWINDOW
' -- This area is fired once the window is visible.
CASE %WM_COMMAND
' -- You can handle ALL hWnd (MAIN) controls here.
' -- This message is sent when the user selects a command item from
' -- a menu, when a control sends a notification message to its
' -- parent window, or when an accelerator key-stroke is translated.
SELECT CASE CBCTL
CASE %menuCHILD_OP
CreateChildWindow()
RETURN(1)
CASE %menuEXIT_OP
' -- Do not actually terminate from here.
SendMessage(hWnd, %WM_SYSCOMMAND, %SC_CLOSE, 0)
RETURN(1)
END SELECT
CASE %WM_SYSCOMMAND
SELECT CASE CBCTL
CASE %SC_MINIMIZE
CASE %SC_MAXIMIZE
CASE %SC_RESTORE
CASE %SC_MOVE
CASE %SC_SIZE
CASE %SC_CLOSE
IF MSGBOX(0, "Are you sure you want to exit the program?", %MB_YESNO OR %MB_ICONQUESTION, "CONFIRM EXIT") = %IDYES THEN
' -- This tells the program to call close, if you select YES.
' -- You can close immediately, without prompt, by sending a message
' -- directly to %WM_CLOSE, as opposed to capturing the SYSCOMMAND close.
SendMessage(hWnd, %WM_CLOSE, 0, 0)
END IF
RETURN(1)
END SELECT
CASE %WM_CLOSE
' -- Put code to be executed before dialog end here
' -- This is the API call to kill this "Virtual Window" by the "Call Handle"
' -- This will be a TB function soon, I imagine.
DestroyWindow(hWnd)
RETURN(1)
CASE %WM_DESTROY
END SELECT
END FUNCTION
SUB CreateChildWindow()
' -- NOTICE: This is NOT an MDI-Child. This is a CHILD by assignment. (Parent=hWnd to Child=hWndChild)
DIALOG NEW PIXELS, hWnd, "Test CHILD Window", -1, -1, 260, 80, _
%WS_CLIPCHILDREN OR %WS_CLIPSIBLINGS OR %WS_OVERLAPPEDWINDOW, _
0 TO hWndChild
' -- These are Children by assignment, of hWndChild.
' -- All these controls will trigger the childProc() CALL
' -- If you want to assign a callback for these controls, they need to be moved
' -- to the childProc() callback notice "%WM_INITDIALOG" area.
CONTROL ADD BUTTON, hWndChild, %btnCOMMAND+0, "BEEP", 45, 10, 170, 20
CONTROL ADD BUTTON, hWndChild, %btnCOMMAND+1, "CLOSE THIS CHILD", 45, 30, 170, 20
CONTROL ADD BUTTON, hWndChild, %btnCOMMAND+2, "CLOSE PARENT", 45, 50, 170, 20
DIALOG SHOW MODELESS hWndChild, CALL childProc()
END SUB
' -- Callback Function for hWndChild (CHILD) dialog/window
CALLBACK FUNCTION childProc() AS LONG
SELECT CASE CBMSG
CASE %WM_CREATE
CASE %WM_INITDIALOG
DIALOG SET TEXT CBHNDL, "Child CB-Handle: " & CBHNDL
RETURN(1)
CASE %WM_SHOWWINDOW
CASE %WM_COMMAND
SELECT CASE CBCTL
' -- I have use three %btnCOMMAND constants.
' -- Each three have a virtual handle that mathes the parent they
' -- are attached to. (They could also have another handle, if they
' -- had thier own btnProc() CALLBACK. But that requires a complex
' -- setup, because all buttons would trigger that same callback.)
CASE %btnCOMMAND+0
IF CBCTLMSG = %BN_CLICKED THEN
BEEP
END IF
RETURN(1)
CASE %btnCOMMAND+1
IF CBCTLMSG = %BN_CLICKED THEN
' -- Close this child by the "Virtual Handle", using the SYSCOMMAND close
SendMessage(CBHNDL, %WM_SYSCOMMAND, %SC_CLOSE, 0)
END IF
RETURN(1)
CASE %btnCOMMAND+2
IF CBCTLMSG = %BN_CLICKED THEN
' -- Close parent (MAIN), using the SYSCOMMAND close
' -- This can be the real handle, because it is only one window
' -- If this were a virtual child, with others using the same mainProc()
' -- You would want to send the CBHNDL of the window when it was created.
' -- That would require additional tracking in an ARRAY, of virtual CBHNDL's
SendMessage(hWnd, %WM_SYSCOMMAND, %SC_CLOSE, 0)
END IF
RETURN(1)
END SELECT
CASE %WM_SYSCOMMAND
SELECT CASE CBCTL
CASE %SC_MINIMIZE
CASE %SC_MAXIMIZE
CASE %SC_RESTORE
CASE %SC_MOVE
CASE %SC_SIZE
CASE %SC_CLOSE
SendMessage(CBHNDL, %WM_CLOSE, 0, 0)
RETURN(1)
END SELECT
CASE %WM_CLOSE
DestroyWindow(CBHNDL)
RETURN(1)
CASE %WM_DESTROY
END SELECT
END FUNCTION
I have updated this code to use RETURN(1) values. (Seems the "Close" button likes to continue to CLOSE, even though you explicitly block it. The values of (1) are generic and only a temp-guide. See the note below.)
Bookmarks