MDIGUI statement
Purpose: The MDIGUI
statement specifies that the program
is a Multiple Document Interface Graphical User Interface application.
Like the GUI
statement,
MDIGUI
provides a ClassName
for the program.
As well as the MDIGUI
statement,
minimal BCX MDIGUI
program must have a
SUB FORMLOAD ... END SUB
section and as well
a BEGIN MDIEVENTS ... END MDIEVENTS
section.
Syntax 1: MDIGUI "ClassName" [,PIXELS, ICON, ResInt%] Syntax 2: MDIGUI NOMAIN [,PIXELS, ICON, ResInt%] Parameters:
|
Remarks:
The MDIGUI
"ClassName"
statement must be placed at the start of your program. The
MDIGUI
statement can not be placed
inside any SUB, FUNCTION
nor within the
BEGIN MDIEVENTS ... END MDIEVENTS
loop.
It must be placed at the module level, the same level at which your directives and
global variables are declared.
In a BCX MDIGUI
program,
expressions must be inside a FUNCTION, SUB or the BEGIN MDIEVENTS...END MDIEVENTS
procedure.
MDIGUI NOMAIN statement
Purpose: The MDIGUI NOMAIN
statement specifies
that a WinMain function will not be automatically emitted.
NOMAIN requires, at least, that the programmer provide a WinMain equivalent,
register a ClassName and provide a message pump.
The MDIGUI NOMAIN
statement is similar to the
$NOMAIN
directive used in console mode programs.
Syntax: MDIGUI NOMAIN [,PIXELS, ICON, ResInt%] Parameters:
|
Remarks:
In a BCX MDIGUI NOMAIN
program,
all expressions must be inside a FUNCTION, SUB or the BEGIN EVENTS...END EVENTS
procedure.
BCX_WndClass and BCX_GUI_Init
When a BCX MDIGUI NOMAIN program is translated, a WNDCLASSEX structure named BCX_WndClass is created and declared GLOBAL. It is initialized to the default values by the internal BCX translator BCX_INITGUI() procedure and then registered using the internal BCX translator BCX_REGWND procedure. BCX_REGWND checks to see if a window class of the name being registered has already been used and if so does not register it again. It allows 256 different(non case sensitive) window classes to be registered. It also sets the BCX_GUI_INIT variable to TRUE, indicating that the procedure has been run and it will exit without doing anything next time it is called.
See Example 2 below for a complete MDIGUI NOMAIN example.
BCX_MDICLASS statement
Purpose:The BCX_MDICLASS
statement is valid only in BCX programs which use the
MDIGUI
statement. It creates a CLASS on which Multiple Document Interface(MDI)
Child Windows can be based. This function should be placed in the
SUB FORMLOAD ... END SUB
section of the code. Every MDIGUI
application needs at least one CLASS for child windows, and it is also
possible to create multiple classes if required.
Syntax: BCX_MDICLASS((WNDPROC)MdiChildWndProc, MdiChildWndClass$) Parameters:
|
Remarks: The BCX_MDICLASS
statement does not return a value.
See the example under BCX_MDICHILD
function.
BCX_MDICLIENT function
Purpose: The BCX_MDICLIENT
function is valid only in BCX programs which use the
MDIGUI
statement.
It creates a MDICLIENT window in which the Multiple Document Interface
child windows can be displayed. This function should be placed in the
SUB FORMLOAD ... END SUB
section of the code. Every MDIGUI
application needs a MDICLIENT area, and the application will not run
if it is omitted.
Syntax: hwndMDIClient = BCX_MDICLIENT(hWnd, Index%) Parameters:
|
Remarks: See the example under
BCX_MDICHILD
function.
BCX_MDICHILD function
Purpose: The BCX_MDICHILD
function is valid only in BCX programs which use the
MDIGUI
statement. It creates a MDICHILD window in the MDICLIENT area.
Syntax: hwndMDIChild = BCX_MDICHILD(ChildTitle$, _ MdiChildWndClass$) _ [,Xpos%] _ [,Ypos%] _ [,Width%] _ [,Height%] _ [,MDIStyle%] _ [,MDILparam%]) Parameters:
|
BEGIN MDICHILDEVENTS ... END MDICHILDEVENTS statements
Purpose: In a MDIGUI multiple-document interface program code that is responsible for monitoring and responding to BCX_MDICHILD child window messages and commands like mouse clicks, button presses, radio controls and so on is placed between BEGIN MDICHILDEVENTS and END MDICHILDEVENTS.
Syntax :
Parameters:
|
Remarks:
The MAIN parameter, optionally used with the END EVENTS and END MDIEVENTS loop terminators, can not be used with the END MDICHILDEVENTS loop terminator.
This BCX code,
BEGIN
MDICHILDEVENTS
ProcedureNameSELECT
CASE
CBMSG
CASE
WM_LBUTTONDOWN SetWindowText(
Stat1,"left mouse button down :-("
)
CASE
WM_LBUTTONUP SetWindowText(
Stat1,"LEFT MOUSE BUTTON UP :-)"
)
END
SELECT
END
MDICHILDEVENTS
translates to
LRESULT CALLBACK ProcedureName(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { while(1) { if(Msg==WM_LBUTTONDOWN) { SetWindowText(Stat1,"left mouse button down :-("); break; } if(Msg==WM_LBUTTONUP) { SetWindowText(Stat1,"LEFT MOUSE BUTTON UP :-)"); } break; } return DefMDIChildProc(hWnd,Msg,wParam,lParam); }
Example 1:
'----------------------------------------------------------
MDIGUI
NOMAIN
,PIXELS
,ICON
,123
DIM
Form1AS
HWND' Main window handle
'----------------------------------------------------------
CONST
IDM_NEW=
10
CONST
IDM_OPEN=
20
CONST
IDM_SAVE=
30
CONST
IDM_SAVEAS=
40
CONST
IDM_PRINT=
50
CONST
IDM_CLOSE=
70
CONST
IDM_EXIT=
60
CONST
IDM_UNDO=
100
CONST
IDM_CUT=
110
CONST
IDM_COPY=
120
CONST
IDM_PASTE=
130
CONST
IDM_DEL=
140
CONST
IDM_SELALL=
150
CONST
IDM_WORDWRAP=
300
CONST
IDM_FONT=
310
CONST
IDM_CASCADE=
160
CONST
IDM_TILE=
170
CONST
IDM_ARRANGE=
180
CONST
IDM_CLOSEALL=
190
CONST
IDM_HELP=
200
CONST
IDM_ABOUT=
210
CONST
CBWNDEXTRA=
12
CONST
GWL_HWNDEDIT=
0
CONST
GWL_EDITCHANGED=
4
CONST
ID_EDIT=
300
CONST
IDM_FIRSTCHILD=
400
CONST
ID_MAINMENU=
500
'----------------------------------------------------------
FUNCTION
WINMAIN(
)
RAW
hMenuAS
HMENU'Attach the main menu
hMenu=
LoadMenu(
BCX_HINSTANCE
, MAKEINTRESOURCE(
ID_MAINMENU)
)
Form1=
BCX_FrameWnd
(
"MAINFORM"
, FrameWndProc,"Mini-Multi-Pad"
, hMenu,4
)
' BCX_MDICLASS takes the name of the callback function
' and the name of the class
BCX_MDICLASS
(
(
WNDPROC)
MDIChildWndProc,"MdiChildWndClass"
)
BCX_MDICHILD
(
""
,"MdiChildWndClass"
,0
,0
,600
,480
, WS_MAXIMIZE)
SHOW
(
Form1)
FUNCTION
=
BCX_MDI_MsgPump
(
)
END
FUNCTION
'----------------------------------------------------------
BEGIN
MDIEVENTS
FrameWndProc handle_cmd(
IDM_NEW, newChild,0
)
handle_cmd(
IDM_OPEN, openChild,0
)
handle_cmd(
IDM_SAVE, saveChild,0
)
handle_cmd(
IDM_SAVEAS, saveAsChild,0
)
handle_cmd(
IDM_FONT, fontChild)
handle_cmd(
IDM_CASCADE, mdiCascade)
handle_cmd(
IDM_TILE, mdiTile)
handle_cmd(
IDM_ARRANGE, mdiArrange)
handle_cmd(
IDM_CLOSEALL, mdiCloseAll)
handle_cmd(
IDM_CLOSE, mdiClose)
handle_cmd(
IDM_ABOUT, mdiAbout)
handle_cmd(
IDM_EXIT, mdiExit)
handle_msg
(
WM_QUERYENDSESSION, mdiEndSession,0
)
handle_msg
(
WM_CLOSE, mdiEndSession,0
)
END
MDIEVENTS
MAIN
CMDHANDLER saveChildRAW
hWndChildAS
HWNDRAW
hEditAS
HWNDRAW
wintext$RAW
lengthRAW
buffer$*
10
hWndChild=
(
HWND)
SendMessage(
BCX_hwndMDIClient, WM_MDIGETACTIVE,0
,0
)
hEdit=
(
HWND)
GetWindowLong(
hWndChild, GWL_HWNDEDIT)
length=
GetWindowText(
hWndChild, wintext$,SIZEOF
(
wintext$)
)
wintext$=
MID$
(
wintext$,1
, length)
? wintext$ length=
Edit_GetTextLength(
hEdit)
? lengthREDIM
buffer$*
length length=
Edit_GetText(
hEdit,buffer$,SIZEOF
(
buffer$)
)
buffer$=
MID$
(
buffer$,1
, length)
? buffer$END
Handler
CMDHANDLER saveAsChildRAW
hWndChildAS
HWNDRAW
wintext$RAW
length hWndChild=
(
HWND)
SendMessage(
BCX_hwndMDIClient, WM_MDIGETACTIVE,0
,0
)
length=
GetWindowText(
hWndChild, wintext$,SIZEOF
(
wintext$)
)
wintext$=
MID$
(
wintext$,1
, length)
? wintext$END
Handler
MSGHANDLER
mdiEndSession SendMessage(
hWnd,WM_COMMAND,IDM_CLOSEALL,0
)
DestroyWindow(
Form1)
END
Handler
CMDHANDLER mdiCascade SendMessage(
BCX_hwndMDIClient, WM_MDICASCADE,0
,0
)
END
Handler
CMDHANDLER mdiTile SendMessage(
BCX_hwndMDIClient, WM_MDITILE,0
,0
)
END
Handler
CMDHANDLER mdiArrange SendMessage(
BCX_hwndMDIClient, WM_MDIICONARRANGE,0
,0
)
END
Handler
CMDHANDLER mdiCloseAll EnumChildWindows(
BCX_hwndMDIClient,CloseEnumProc,0
)
END
Handler
CMDHANDLER mdiClose SendMessage(
(
HWND)
SendMessage(
BCX_hwndMDIClient, WM_MDIGETACTIVE,0
,0
)
, WM_CLOSE,0
,0
)
END
Handler
CMDHANDLER mdiExit SendMessage(
Form1, WM_CLOSE,0
,0
)
END
Handler
CMDHANDLER mdiAbout MessageBox(
hWnd,"Mini-Multi-Pad Editor"
+
CR$
+
_" Vic McClung"
,"About"
,0
)
END
Handler
CMDHANDLER newChild(
)
BCX_MDICHILD
(
""
,"MdiChildWndClass"
,0
,0
,640
,480
, WS_MAXIMIZE)
END
Handler
CMDHANDLER openChildRAW
hChildWndAS
HWNDRAW
filename$RAW
hEditAS
HWNDRAW
buffer$*
10
filename$=
GETFILENAME$
(
"Open a Text File"
,"*.txt"
,0
, hWnd)
IF
filename$ <>""
THEN
REDIM
buffer$*
LOF
(
filename$)
buffer$=
LOADFILE$
(
filename$)
hChildWnd=
BCX_MDICHILD
(
""
,"MdiChildWndClass"
,0
,0
,640
,480
, WS_MAXIMIZE)
hEdit=
(
HWND)
GetWindowLong(
hChildWnd, GWL_HWNDEDIT)
EDITLOADFILE
(
hEdit, filename$)
SendMessage(
hChildWnd, WM_SETTEXT,0
, filename$)
END
IF
END
Handler
CMDHANDLER fontChildRAW
hwndChildAS
HWNDRAW
hEditAS
HWND hwndChild=
(
HWND)
SendMessage(
BCX_hwndMDIClient, WM_MDIGETACTIVE,0
,0
)
hEdit=
(
HWND)
GetWindowLong(
hwndChild, GWL_HWNDEDIT)
IF
BCX_FONTDLG
(
TRUE, hEdit)
THEN
BCX_SET_FONT
(
hEdit, BCX_Font.Name$, BCX_Font.Size, _ BCX_Font.Bold, BCX_Font.Italic, BCX_Font.Underline, _ BCX_Font.Strikeout)
END
IF
END
Handler
'----------------------------------------------------------
BEGIN
MDICHILDEVENTS
MDIChildWndProchandle_msg
(
WM_CREATE, child_OnCreate)
handle_msg
(
WM_SIZE, child_OnSize)
handle_cmd(
ID_EDIT, edit_OnCommand,0
)
handle_msg
WM_SETFOCUS INLINE"SetFocus((HWND)GetWindowLong(hWnd, GWL_HWNDEDIT))"
handle_msg
WM_CLOSE INLINE"SendMessage(GetParent(hWnd),WM_MDIDESTROY,hWnd,0)"
END
MDICHILDEVENTS
MSGHANDLER
child_OnCreateRAW
hWndEditAS
HWNDRAW
Style=
WS_CHILD | WS_HSCROLL | WS_VISIBLE | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE hWndEdit=
BCX_RICHEDIT
(
""
, hWnd, ID_EDIT,0
,0
,0
,0
, Style)
' Remember the edit control's window handle,
' and set the edit changed flag to 0.
' You can use this to see if you can close
' the child window.
SetWindowLong(
hWnd, GWL_HWNDEDIT,(
LONG)
hWndEdit)
; SetWindowLong(
hWnd, GWL_EDITCHANGED,0
)
; SetFocus(
hWndEdit)
;END
Handler
MSGHANDLER
child_OnSizeRAW
hWndEditAS
HWND'Move the edit control to MDI child's size.
hWndEdit=
(
HWND)
GetWindowLong(
hWnd, GWL_HWNDEDIT)
IF
NOT
MoveWindow(
hWndEdit,0
,0
, LOWORD(
lParam)
,HIWORD(
lParam)
, TRUE)
THEN
MessageBox(
NULL,"Could not move window"
, NULL,0
)
END
IF
END
Handler
MSGHANDLER
edit_OnCommandRAW
hWndEditAS
HWND hWndEdit=
(
HWND)
GetWindowLong(
hWnd, GWL_HWNDEDIT)
IF
lParamAND
LOWORD(
wParam)
=
ID_EDITTHEN
SELECT
CASE
HIWORD(
wParam)
CASE
EN_UPDATE, EN_CHANGE SetWindowLong(
hWnd, GWL_EDITCHANGED,1
)
EXIT
FUNCTION
END
SELECT
EXIT
FUNCTION
END
IF
END
Handler
'----------------------------------------------------------
FUNCTION
CloseEnumProc(
hWndAS
HWND,lParamAS
LPARAM)
AS
BOOL
CALLBACK
' Check for icon title
IF
(
GetWindow(
hWnd,GW_OWNER)
)
THEN
FUNCTION
=
TRUEEND
IF
SendMessage(
GetParent(
hWnd)
,WM_MDIRESTORE,(
WPARAM)
hWnd,0
)
IF
NOT
SendMessage(
hWnd,WM_QUERYENDSESSION,0
,0
)
THEN
FUNCTION
=
TRUEEND
IF
SendMessage(
GetParent(
hWnd)
,WM_MDIDESTROY,hWnd,0
)
FUNCTION
=
TRUEEND
FUNCTION
'----------------------------------------------------------
$BCX_RESOURCE
#define IDM_NEW10
#define IDM_OPEN20
#define IDM_SAVE30
#define IDM_SAVEAS40
#define IDM_PRINT50
#define IDM_CLOSE70
#define IDM_EXIT60
#define IDM_WORDWRAP300
#define IDM_FONT310
#define IDM_UNDO100
#define IDM_CUT110
#define IDM_COPY120
#define IDM_PASTE130
#define IDM_DEL140
#define IDM_SELALL150
#define IDM_CASCADE160
#define IDM_TILE170
#define IDM_ARRANGE180
#define IDM_CLOSEALL190
#define IDM_HELP200
#define IDM_ABOUT210
#define CBWNDEXTRA12
#define GWL_HWNDEDIT0
#define GWL_EDITCHANGED4
#define ID_EDIT300
#define IDM_FIRSTCHILD400
#define ID_MAINMENU500
#include <windows.h>
123
ICON
"bcx.ico"
ID_MAINMENU MENU DISCARDABLEBEGIN
POPUP"&File"
BEGIN
MENUITEM"&New"
, IDM_NEW MENUITEM"&Open..."
, IDM_OPEN MENUITEM"&Save"
, IDM_SAVE MENUITEM"Save &As..."
, IDM_SAVEAS MENUITEM"&Close"
, IDM_CLOSE MENUITEM SEPARATOR MENUITEM"&Print"
, IDM_PRINT MENUITEM SEPARATOR MENUITEM"E&xit"
, IDM_EXITEND
POPUP"&Edit"
BEGIN
MENUITEM"&Undo"
, IDM_UNDO MENUITEM SEPARATOR MENUITEM"Cu&t"
, IDM_CUT MENUITEM"&Copy"
, IDM_COPY MENUITEM"&Paste"
, IDM_PASTE MENUITEM"De&lete"
, IDM_DEL MENUITEM SEPARATOR MENUITEM"&Select All"
, IDM_SELALLEND
POPUP"F&ormat"
BEGIN
MENUITEM"&Wordwrap"
, IDM_WORDWRAP MENUITEM"&Font"
, IDM_FONTEND
POPUP"&Window"
BEGIN
MENUITEM"&Cascade"
, IDM_CASCADE MENUITEM"&Tile"
, IDM_TILE MENUITEM"Arrange &Icons"
, IDM_ARRANGE MENUITEM"Close &All"
, IDM_CLOSEALLEND
POPUP"&Help"
BEGIN
MENUITEM"&Help..."
, IDM_HELP MENUITEM"&About..."
, IDM_ABOUTEND
END
$BCX_RESOURCE
Example 2:
'--------------------------------------------------- MDIGUI "MDIName", PIXELS, ICON, 123 '--------------------------------------------------- $RESOURCE "$PELLES$\bin\porc.exe" $COMPILER "$PELLES$\Bin\pocc -W1 -Gd -Go -Ze -Zx -Tx86-coff $FILE$.c" $LINKER "$PELLES$\Bin\polink _ -release _ -machine:ix86 _ -subsystem:windows _ -OUT:$FILE$.exe _ $FILE$.obj " $BCX_RESOURCE #define IDM_NEW 200 #define IDM_EXIT 201 #define IDM_WINDOWTILE 202 #define IDM_WINDOWCASCADE 203 #define IDM_WINDOWICONS 204 #define ID_MAINMENU 205 ' 123 ICON "mdigui.ico" ID_MAINMENU MENU DISCARDABLE BEGIN POPUP "&File" BEGIN MENUITEM "&New", IDM_NEW MENUITEM "E&xit", IDM_EXIT END POPUP "&Window" BEGIN MENUITEM "&Tile", IDM_WINDOWTILE MENUITEM "&Cascade", IDM_WINDOWCASCADE MENUITEM "Arrange &Icons",IDM_WINDOWICONS END END $BCX_RESOURCE CONST IDM_NEW = 200 CONST IDM_EXIT = 201 CONST IDM_WINDOWTILE = 202 CONST IDM_WINDOWCASCADE = 203 CONST IDM_WINDOWICONS = 204 CONST ID_MAINMENU = 205 DIM Form1 AS HWND ' Main window handle DIM hwndMDIClient AS HWND ' Mdi client window handle SUB FormLoad() DIM RAW Style AS INTEGER Style = WS_MINIMIZEBOXBOR
_ WS_CLIPSIBLINGSBOR
_ WS_CLIPCHILDRENBOR
_ WS_MAXIMIZEBOXBOR
_ WS_CAPTIONBOR
_ WS_BORDERBOR
_ WS_SYSMENUBOR
_ WS_THICKFRAME Form1 = BCX_FORM("MDI", 0, 0, 300, 300, Style) 'Attach the main menu SetMenu(Form1,LoadMenu(BCX_HINSTANCE , _ MAKEINTRESOURCE(ID_MAINMENU))) ' BCX_MDICLASS takes the name of the callback function ' and the name of the class BCX_MDICLASS((WNDPROC)MdiChildWndProc, "MdiChildWndClass") ' The second parameter is the index of the main menu ' you want to attach "Untitled1" hwndMDIClient = BCX_MDICLIENT(Form1, 2) CENTER(Form1) SHOW(Form1) END SUB '--------------------------------------------------- CALLBACK FUNCTION WndProc() SELECT CASE Msg CASE WM_CREATE CASE WM_COMMAND SELECT CASE wParam CASE IDM_NEW ' Use a character string if you do not want ' the default "untitled%d" title ' The second parameter is the name of class ' used in BCX_MDICLASS BCX_MDICHILD("", "MdiChildWndClass") CASE IDM_WINDOWTILE SendMessage(hwndMDIClient, WM_MDITILE, 0, 0) CASE IDM_WINDOWCASCADE SendMessage(hwndMDIClient, WM_MDICASCADE, 0, 0) CASE IDM_WINDOWICONS SendMessage(hwndMDIClient, WM_MDIICONARRANGE, 0, 0) CASE IDM_EXIT PostMessage(hWnd,WM_CLOSE,0,0) END SELECT CASE WM_DESTROY PostQuitMessage(0) END SELECT FUNCTION = DefFrameProc(hWnd, hwndMDIClient, _ Msg, wParam, lParam) END FUNCTION '---------------------------------------------------------- CALLBACK FUNCTION MdiChildWndProc() SELECT CASE Msg CASE WM_CREATE END SELECT FUNCTION = DefMDIChildProc(hWnd, Msg, wParam, lParam) END FUNCTION