Guidance
指路人
g.yi.org
software / rapidq / examples / GUI / form / MDI / SimpleMDI / SimpleMDI.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
'================== API stuff ==============================
'======== Type for creating new window class ==============

     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

'=================== API declarations =========================

     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

'================= constants for window style/size/count ============

     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

'================= Global variables ===================================
' hClient - handle of client window(the frame inside the main form that
'           displays the child forms)
' ChildCount - number of currently running child forms
' hChild() - array of child handles
' Buffer - string to hold class names for EnumCallback
' ClassName - string to hold class name for our new window class

     DEFLNG hClient, ChildCount, hChild(1024)
     DEFSTR Buffer, ClassName = "MDIChild"

'====================== Declares =====================================

     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

'===================== Parent form ===================================

     CREATE Form AS QFORM
      CAPTION = "MDI Parent"
      Center
      FormStyle = 2 ' fsMDIParent
      Width = Screen.Width/2*1.5
      Height = Screen.Height/2*1.5
      COLOR = -2147483636 ' clAppWorkspace
      CREATE mnuMain AS QMAINMENU
       CREATE mnuNew AS QMENUITEM
        CAPTION  ="&New"
        OnClick = mnuNew_Click
       END CREATE
      END CREATE
     END CREATE

'============== our child class ======================================

' Create instance of WNDCLASSEX
     DIM ChildClass AS WNDCLASSEX

' Fill the type
     WITH ChildClass
      .cbSize = SIZEOF(ChildClass)
      .style = 0
      .lpfnWndProc = CODEPTR(ChildProc)
      .cbClsExtra = 0
      .cbWndExtra = 0
      .hInstance = 0
      .hIcon = 0
      .hCursor = 0
      .hbrBackground = -2147483632 ' clBtnFace+1
      .lpszMenuName = 0
      .lpszClassName = VARPTR(ClassName)
      .hIconSm = 0
     END WITH

' And register it
     RegisterClassEx(ChildClass)

'============= Find handle to client window ============================
' This API function passes all child windows of Form to our EnumCallback
' function, to find the client handle. lParam is not used.

     EnumChildWindows(Form.Handle, CODEPTR(EnumCallback), 0)

'=============== Show the form! ======================================

     Form.SHOWMODAL

' Here is where the real work begins...

'=============== Create a new MDIChild ==================================
' The result of CreateWindowEx is the handle to the newly created form,
' so we load it into our array. CW_USEDEFAULT tells Windows to scale the
' size of our child to fit the client area, at 2/3 width and 2/3 height.
' The owner is hClient. Then we increase ChildCount.

     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

' ============== Message handling for our child ======================
' If a child is closed, we decrease ChildCount, to minimize the size of
' the array and keep a count of how many child windows we have running.
' Then we forward all messages to Windows, letting it manage our child
' windows.

     FUNCTION ChildProc
      IF uMsg = WM_DESTROY THEN
       ChildCount--
      END IF
      Result = DefMDIChildProc(hWnd, uMsg, wParam, lParam)
     END FUNCTION

' ========== Enumerates children of main form ========================
' Here we will find the handle of the inner frame of our main form, so
' we can assign it as the parent of our child windows. The client is a
' pre-registered class in Windows with the classname "MDIClient".

     FUNCTION EnumCallback
      Buffer = SPACE$(255)
      GetClassName(hWnd, @Buffer, 255)
      IF INSTR(UCASE$(Buffer), "MDICLIENT") THEN hClient = hWnd
      Result = 1
     END FUNCTION

掌柜推荐
 
 
¥1,800.00 ·
 
 
¥489.00 ·
 
 
¥288.00 ·
 
 
¥908.00 ·
 
 
¥748.00 ·
 
 
¥264.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2013-06-19 07:59:21