TYPE WNDCLASSEX
cbSize AS LONG
style AS LONG
lpfnWndProc AS LONG
cbClsExtra AS LONG
cbWndExtra AS LONG
hInstance AS LONG
hIcon AS LONG
hCursor AS LONG
hbrBackground AS LONG
lpszMenuName AS LONG
lpszClassName AS LONG
hIconSm AS LONG
END TYPE
DECLARE FUNCTION RegisterClassEx LIB "User32" ALIAS "RegisterClassExA" _
(pcWndClassEx AS WNDCLASSEX) AS LONG
DECLARE FUNCTION EnumChildWindows LIB "User32" ALIAS "EnumChildWindows" _
(hWndParent AS LONG, lpEnumFunc AS LONG, lParam AS LONG) AS LONG
DECLARE FUNCTION CreateWindowEx LIB "User32" ALIAS "CreateWindowExA" _
(dwExStyle AS LONG, lpClassName AS STRING, lpWindowName AS STRING, _
dwStyle AS LONG, x AS LONG, y AS LONG, nWidth AS LONG, nHeight AS LONG, _
hWndParent AS LONG, hMenu AS LONG, hInstance AS LONG, lpParam AS LONG) AS LONG
DECLARE FUNCTION DefMDIChildProc LIB "User32" ALIAS "DefMDIChildProcA" _
(hWnd AS LONG, uMsg AS LONG, wParam AS LONG, lParam AS LONG) AS LONG
DECLARE FUNCTION GetClassName LIB "User32" ALIAS "GetClassNameA" _
(hwnd AS LONG, lpClassName AS STRING, nMaxCount AS LONG) AS LONG
CONST WS_EX_MDICHILD = &H40
CONST WS_CHILD = &H40000000
CONST WS_VISIBLE = &H10000000
CONST WS_OVERLAPPED = &H0
CONST WS_CAPTION = &HC00000
CONST WS_SYSMENU = &H80000
CONST WS_THICKFRAME = &H40000
CONST WS_MINIMIZEBOX = &H20000
CONST WS_MAXIMIZEBOX = &H10000
CONST WS_OVERLAPPEDWINDOW = (WS_OVERLAPPED OR WS_CAPTION OR WS_SYSMENU OR WS_THICKFRAME OR WS_MINIMIZEBOX OR WS_MAXIMIZEBOX)
CONST CW_USEDEFAULT = &H80000000
CONST WM_DESTROY = &H2
DEFLNG hClient, ChildCount, hChild(1024)
DEFSTR Buffer, ClassName = "MDIChild"
DECLARE SUB mnuNew_Click
DECLARE FUNCTION ChildProc (hWnd AS LONG, uMsg AS LONG, wParam AS LONG, lParam AS LONG) AS LONG
DECLARE FUNCTION EnumCallback(hWnd AS LONG, lParam AS LONG) AS LONG
CREATE Form AS QFORM
CAPTION = "MDI Parent"
Center
FormStyle = 2
Width = Screen.Width/2*1.5
Height = Screen.Height/2*1.5
COLOR = -2147483636
CREATE mnuMain AS QMAINMENU
CREATE mnuNew AS QMENUITEM
CAPTION ="&New"
OnClick = mnuNew_Click
END CREATE
END CREATE
END CREATE
DIM ChildClass AS WNDCLASSEX
WITH ChildClass
.cbSize = SIZEOF(ChildClass)
.style = 0
.lpfnWndProc = CODEPTR(ChildProc)
.cbClsExtra = 0
.cbWndExtra = 0
.hInstance = 0
.hIcon = 0
.hCursor = 0
.hbrBackground = -2147483632
.lpszMenuName = 0
.lpszClassName = VARPTR(ClassName)
.hIconSm = 0
END WITH
RegisterClassEx(ChildClass)
EnumChildWindows(Form.Handle, CODEPTR(EnumCallback), 0)
Form.SHOWMODAL
SUB mnuNew_Click
hChild(ChildCount) = CreateWindowEx(WS_EX_MDICHILD, @ClassName, "MDI Child "+STR$(ChildCount+1), WS_CHILD OR WS_VISIBLE OR WS_OVERLAPPEDWINDOW, _
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hClient, 0, 0, 0)
ChildCount++
END SUB
FUNCTION ChildProc
IF uMsg = WM_DESTROY THEN
ChildCount--
END IF
Result = DefMDIChildProc(hWnd, uMsg, wParam, lParam)
END FUNCTION
FUNCTION EnumCallback
Buffer = SPACE$(255)
GetClassName(hWnd, @Buffer, 255)
IF INSTR(UCASE$(Buffer), "MDICLIENT") THEN hClient = hWnd
Result = 1
END FUNCTION
|
|