MDI in LB

By David Conner, copyright 2003

lbdavid26@yahoo.com


(The classname for the MDI client taken from Mitchell Kotler's XIDE)

NewsLetter TOC

Newsletter Home

Blast

MDI

OS Editor

LBW Review

Fast Data

SQLite

Tsunami

Begin Prog II

Locate/LBCard

MDI stands for Multiple Document Interface. Have you ever used a program like Microsoft Word that allows you to open more than one program at a time? We can accomplish MDI in Liberty BASIC. It takes quite a few steps, though, if you want to open windows in the MDI client.

First you need to setup a window to contain the MDI client.

Open "MDI Test" For Window As #1

Next, you need to obtain the handle to your window using the Liberty BASIC hWnd function. You also need to maximize your window using the ShowWindow call.

hWnd = hWnd(#1)

CallDLL #User32, "ShowWindow", hWnd As Long, _SW_MAXIMIZE As Long,_
Result As Long

After obtaining the handle, we need to create some variables to hold information for the API call to create the MDI client.

ClassName$ = "MDICLIENT"
MDIWidth   =   DisplayWidth
MDIHeight  =   DisplayHeight-50
X = 0
Y = 0

dwStyle = _WS_CLIPCHILDREN or _WS_CHILD or _WS_VISIBLE or _WS_BORDER

Next obtain the instance handle using the GetWindowLongA function.

CallDLL #User32, "GetWindowLongA", hW As Long,_
_GWL_HINSTANCE As Long, hInstance As Long

Now, make the API call to create the MDI client. If the call is successful, the handle for the client will be returned.

CallDLL #User32, "CreateWindowExA",_
     0 As Long, ClassName$ As Ptr,_
     "" As Ptr, dwStyle As Long, X As Long,_
     Y As Long, Width As Long, Height As Long,_
     hW As Long, 0 As Long, hInstance As Long,_
     "" As Ptr, hMDI As Long

You now should try to open a child window and test to see if your MDI client is working. One thing to note is that you need to use SetParent to make the parent of your window the MDI client. Below is a demo of what I am talking about. You also need to make a flag for the main window trapclose command.

Open "MDI CHILD WINDOW" for window as #2
#2 "Trapclose [closeChild1]
hChild1 = hWnd(#2)
WindowOpen=1

CallDLL #User32, "ShowWindow", hChild1 As Long, _SW_MAXIMIZE As Long, Result As Long

CallDLL #User32, "SetParent", hChild1 As Long, hMDI As Long, Result As Long

Wait

Below is a working demo of MDI.

WindowOpen = 0
NoMainWin
Menu #1, "&File", "&Open Window", [open], "&Quit", [quit]
open "MDI Test" for window as #1
#1 "trapclose [quit]"

hW =hwnd(#1)

calldll #user32, "ShowWindow", hW as long, _SW_MAXIMIZE as long, reesult as long
calldlL #user32, "GetWindowLongA", hW as long, _GWL_HINSTANCE as long, hInst as long

style = _WS_CLIPCHILDREN or _WS_CHILD or _WS_VISIBLE or _WS_BORDER

Width = DisplayWidth
Height = DisplayHeight-65
calldll #user32, "CreateWindowExA",_
0  as long,_
"MDICLIENT" as ptr,_
"" as ptr,_
style as long,_
0 as long,_
0 as long,_
Width as long,_
Height as long,_
hW as long,_
0 as long,_ ' NULL
hInst as long,_
"" as ptr,_
hMDI as long

[open]
If WindowOpen = 1 then wait
texteditor #2.edit,0,0,DisplayWidth-5,DisplayHeight-105
open "MDI CHILD WINDOW" for window as #2
#2 "Trapclose [closeChild]"
WindowOpen = 1
hChild1=hwnd(#2)
calldll #user32, "SetParent", hChild1 as long, hMDI as long, result as long

calldll #user32, "ShowWindow", hChild1 as long, _SW_MAXIMIZE as long, result as long

wait

[quit] 
	close #1: if WindowOpen = 1 then close #2 else end

[closeChild]
    close #2: WindowOpen = 0 : wait

NewsLetter TOC

Newsletter Home

Blast

MDI

OS Editor

LBW Review

Fast Data

SQLite

Tsunami

Begin Prog II

Locate/LBCard