GUI statement
The following is a minimal BCX GUI
program.
' -------BCX Code start-------------------- GUI "BCX_Template" SUB FORMLOAD GLOBAL Form1 AS HWND Form1 = BCX_FORM("BCX_TEMPLATE", 0, 0, 110, 110) BCX_SET_FORM_COLOR(Form1,QBCOLOR(4)) CENTER(Form1) SHOW(Form1) END SUB BEGIN EVENTS SELECT CASE CBMSG CASE WM_CLOSE DestroyWindow(Form1) EXIT FUNCTION END SELECT END EVENTS ' -------BCX Code end----------------------
Purpose: The GUI statement
specifies that the program is a Graphical User Interface
application and provides a ClassName for the program. The
GUI statement must be placed at the start of
the program and can not be placed inside any SUB,
FUNCTION or within the BEGIN EVENTS...END
EVENTS loop. It must be placed at the module level, the same
level at which your directives and global variables are
declared.
Syntax 1: GUI "ClassName" [,PIXELS, ICON, ResInt%] Syntax 2: GUI NOMAIN [,PIXELS, ICON, ResInt%] Parameters:
|
Remarks:
As well as the GUI statement, a minimal
BCX GUI program must have a SUB FORMLOAD ... END SUB procedure , which translates to
a WinMain function, and as well a BEGIN EVENTS ...
END EVENTS procedure. See below for an example.
In a BCX GUI program, all expressions
must be inside a FUNCTION, SUB or the BEGIN EVENTS...END EVENTS
procedure.
Note well, a GUI NOMAIN(see below)
program must NOT use a SUB FORMLOAD ... END
SUB procedure but instead GUI NOMAIN
requires that the programmer provide a WinMain equivalent and the
other basic functions to register a ClassName and provide a message
pump.
BCX_FORM function
Purpose: BCX_FORM creates a window.
Syntax: hWnd = BCX_FORM([Caption$] _ [,Xpos%] _ [,Ypos%] _ [,Width%] _ [,Height%] _ [,WinStyle%] _ [,ExWinStyle%]) Parameters:
|
Note well: When using BCX_FORM
without
GUI "Classname"
a ClassName must be provided by using
BCX_CLASSNAME$ = "SomeClassName"
prior to initialization of BCX_FORM.
Example 1 :
Form1 = BCX_FORM()
Example 2 :
Form1 = BCX_FORM("My Form")
Example 3 :
Form1 = BCX_FORM("My Form", 0, 0, 310, 250)
Example 4 :
Form1 = BCX_FORM("My Form", 0, 0, 100, 100, WS_CAPTION | WS_SYSMENU)
Remarks: In Examples 1, 2 and 3 the default style used is
WS_MINIMIZEBOX | WS_SIZEBOX | WS_CAPTION | WS_MAXIMIZEBOX | WS_POPUP | WS_SYSMENU.
The default window Style for a BCX_FORM control also can be changed by using the MODSTYLE function.
Example 5 : This example shows how to set up two forms in SUB FORMLOAD. The trick involves:
GUI"Two_Forms_Demo"GLOBALForm1ASHWNDGLOBALForm2ASHWNDGLOBALForm1_Button1ASHWNDGLOBALForm2_Button1ASHWNDGLOBALlpForm2_ProcASWNDPROCCONSTIDC_FORM1_BUTTON1=201CONSTIDC_FORM2_BUTTON1=202SUBFormLoad Form1=BCX_FORM("Form 1",0,0,160,100)Form1_Button1=BCX_BUTTON("Show", Form1, IDC_FORM1_BUTTON1,64,40,40,14)Form2=BCX_FORM("Form 2",0,0,200,140)Form2_Button1=BCX_BUTTON("Hide",Form2, IDC_FORM2_BUTTON1,80,70,40,14)lpForm2_Proc=SubclassWindow(Form2, Form2_Proc)CENTER(Form1)SHOW(Form1)ENDSUBBEGINEVENTSSELECTCASECBMSG'**********************CASEWM_COMMAND'**********************IFCBCTL=IDC_FORM1_BUTTON1THENCENTER(Form2)SHOW(Form2)ENDIFEXITFUNCTION'**********************CASEWM_CLOSE'**********************DIMRAWid id=MSGBOX("Are you sure?","Close Window!",MB_YESNOORMB_ICONQUESTION)IFidTHENPostQuitMessage(0)EXITFUNCTION'**********************CASEWM_DESTROY'**********************PostQuitMessage(0)EXITFUNCTIONENDSELECTENDEVENTSCALLBACKFUNCTIONForm2_ProcSELECTCASECBMSG'**********************CASEWM_COMMAND'**********************IFCBCTL=IDC_FORM2_BUTTON1THENHIDE(CBHWND)EXITFUNCTION'**********************CASEWM_CLOSE'**********************HIDE(CBHWND)'Don't CLOSE it, HIDE itEXITFUNCTION'**********************CASEWM_DESTROY'Don't DESTROY it, HIDE it'**********************HIDE(CBHWND)ENDSELECTENDFUNCTION
BCX_WndClass and BCX_GUI_Init
When a BCX GUI program is translated, a WNDCLASSEX structure named BCX_WndClass is created and declared GLOBAL. It is initialized to the default values in 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.
BCX_HINSTANCE
When a BCX GUI program is translated, an HINSTANCE named BCX_HINSTANCE is created and declared GLOBAL. It is initialized to the value of the HINSTANCE of WinMain. From that point on, you are free to reference it. BCX_HINSTANCE should be considered a READ-ONLY HINSTANCE -- changing its value at runtime is not advisable.
BCX_SCALEX and BCX_SCALEY variables.
As well as BCX_HINSTANCE, two other user accessible variables, BCX_SCALEX and BCX_SCALEY are created when a BCX GUI program is translated. BCX provides the ability to read the value of BCX_SCALEX and BCX_SCALEY variables.
Purpose: BCX_SCALEX and BCX_SCALEY variables are used by BCX to scale horizontal and vertical placement and size of GUI controls. A default scaling factor is calculated by BCX based on the Win32API function GetDialogBaseUnits() which always assumes the system font is being used when calculating the dialog units that form the basis of the scaling values.
If any font other than the system font is used, then the return value from the default scaling may not be correct for your dialog box. And if different fonts are used in controls in a dialog box, then user modifiable scaling is needed.
To be clear ... BCX_SCALEX and BCX_SCALEY are intended to be READ ONLY variables to assist in modifying the values used in dimensioning GUI controls. If the value of BCX_SCALEX or BCX_SCALEY is modified after the system initializes them, then unforeseen consequences may occur.
Syntax: NumberX = BCX_SCALEX NumberY = BCX_SCALEY Parameters:
|
GUI NOMAIN statement
Purpose: The GUI 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 GUI NOMAIN statement is similar to
the $NOMAIN directive used in console mode
programs. The GUI NOMAIN statement must be
placed at the start of the program and can not be placed inside any
SUB, FUNCTION or within the BEGIN EVENTS...END EVENTS loop. It must be placed at the
module level, the same level at which your directives and global
variables are declared.
Syntax: GUI NOMAIN [,PIXELS, ICON, ResInt%] Parameters:
|
Remarks:
In a BCX GUI 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 GUI 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.
BCX_REGWND statement
Purpose: BCX_REGWND registers a window class. If the WndProc is NULL then ClassName$ will be removed from the list of windows classes registered in BCX and the class will be unregistered with UnregisterClass WinAPI call.
Syntax:
Parameters:
|
BCX_MSGPUMP statement
Purpose: BCX_MSGPUMP creates a message loop to retrieve messages, from the message queue of the non-MDI gui programs, and dispatch them to the destination window procedures.
Syntax:
Parameters:
|
BCX_MDI_MSGPUMP statement
Purpose: BCX_MDI_MSGPUMP creates a message loop to retrieve messages, from the message queue of a MDI gui program, and dispatch them to the destination window procedures.
Syntax:
Parameters:
|
BCX_SETMETRIC statement
Purpose: sets either pixels or dlgunits can be either "pixels" or "dlgUnits"(not case sensitive).
Syntax:
Parameters:
|
The following procedures are used to replace members of the WNDCLASSEX structure. For more details on this replacement see the SetClassLong Function in your Win32 SDK or PSDK Reference help.
BCX_SETBKGRDBRUSH statement
Purpose: BCX_SETBKGRDBRUSH sets the background brush.
Syntax:
Parameters:
|
BCX_SETCLASSSTYLE statement
Purpose: BCX_SETCLASSSTYLE sets the class style.
Syntax:
Parameters:
|
BCX_SETICON statement
Purpose: BCX_SETICON sets the Icon.
Syntax:
Parameters:
|
BCX_SETICONSM statement
Purpose: BCX_SETICONSM sets the small Icon .
Syntax:
Parameters:
|
BCX_SETCURSOR statement
Purpose:BCX_SETCURSOR sets the cursor.
Syntax:
Parameters:
|
Example
BCX_RESOURCE123ICON"bcx.ico"GUINOMAIN,ICON,123DIMFooBlooASHACCELFUNCTIONWINMAINGLOBALForm1ASHWNDBCX_SETMETRIC("DialogUnits")BCX_REGWND("MAINFORM", form1Proc)Form1=BCX_FORM("BCX_TEMPLATE",0,0,110,110)BCX_SET_FORM_COLOR(Form1,QBCOLOR(31))CENTER(Form1)SHOW(Form1)FUNCTION=BCX_MSGPUMP(FooBloo)ENDFUNCTIONBEGINEVENTSform1ProcSELECTCASECBMSGCASEWM_KEYDOWNSELECTCASEwParamCASEVK_HOMEMSGBOX"VK_HOME"CASEVK_ENDMSGBOX"VK_END"CASEVK_NEXTMSGBOX"VK_NEXT"CASEVK_PRIORMSGBOX"VK_PRIOR"CASEVK_DOWNMSGBOX"VK_DOWN"CASEVK_UPMSGBOX"VK_UP"CASEVK_LEFTMSGBOX"VK_LEFT"CASEVK_RIGHTMSGBOX"VK_RIGHT"CASEVK_RETURNMSGBOX"VK_RETURN"ENDSELECTCASEWM_CLOSE DestroyWindow(Form1)ENDSELECTENDEVENTSMAIN