GUI statement

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:

  • "ClassName" A unique string literal name for the program. Every Windows GUI program requires a ClassName. Windows uses the ClassName to distinguish one running program from another. The ClassName also is stored in a BCX defined variable named BCX_CLASSNAME$.
  • NOMAIN statement specifies that a WinMain function will not be automatically emitted. NOMAIN requires the programmer, at minimum, to provide a WinMain equivalent register a ClassName and provide a message pump. See the GUI NOMAIN section below for more detail.
  • PIXELS [OPTIONAL] parameter indicating that pixels instead of dialog units are to be used in the placement and size arguments dimensioning the control.
  • ICON [OPTIONAL] parameter indicating that an icon is to be loaded as a resource.
  • ResInt% Used with ICON, specifies an integer value to an icon resource type defined in an .rc file or as a BCX_RESOURCE.

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_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:

  • NumberX Floating point number of the scale of horizontal placement and size of GUI controls.
  • NumberY Floating point number of the scale of vertical placement and size of GUI controls.

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(31))
 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---------------------- 

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:

  • PIXELS [OPTIONAL] parameter indicating that pixels instead of dialog units are to be used in the placement and size arguments dimensioning the control.
  • ICON [OPTIONAL] parameter indicating that an icon is to be loaded as a resource.
  • ResInt% Used with ICON, specifies an integer value to an icon resource type defined in an .rc file or as a BCX_RESOURCE.

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 unregisted with UnregisterClass WinAPI call.


 Syntax:

 BCX_REGWND(ClassName$, ProcedureName)

 Parameters:

  • ClassName$ specifies unique string literal name for the program. Every Windows GUI program requires a ClassName. Windows uses the ClassName to distinguish one running program from another.
  • ProcedureName specifies a name for the WNDPROC windows procedure to be registered. If ProcedureName is NULL, which is the default value, then it unregisters ClassName$.

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:

 BCX_MSGPUMP([hAccel])

 Parameters:

  • [OPTIONAL] specifies a handle to an accelerator table dimensioned as data type HACCEL. This handle must be dimensioned as a GLOBAL.

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:

 BCX_MDI_MSGPUMP([hAccel])

 Parameters:

  • [OPTIONAL] specifies a handle to an accelerator table dimensioned as data type HACCEL. This handle must be dimensioned as a GLOBAL.

BCX_SETMETRIC statement

Purpose: sets either pixels or dlgunits can be either "pixels" or "dlgUnits"(not case sensitive).


 Syntax:

 BCX_SETMETRIC(Metric$)

 Parameters:

  • Metric$ specifies a string literal or variable containing either "pixels" or "dlgunits" indicating that either pixels or dialog units are to be used in the placement and size arguments dimensioning the control.

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:

 BCX_SETBKGRDBRUSH(hwnd, Brush%)

 Parameters:

  • hwnd specifies a HWND handle to the control of which the background brush is to be set.
  • hbrush specifies the integer value of a brush resource with which the background will be set.

BCX_SETCLASSSTYLE statement

Purpose: BCX_SETCLASSSTYLE sets the class style.


 Syntax:

 BCX_SETCLASSSTYLE(hWnd, Style%)

 Parameters:

  • hwnd specifies a HWND handle to the control of which the window-class style bits to be replaced.
  • Style% specifies an integer representing a new value for the window-class style bits to be replaced.

BCX_SETICON statement

Purpose: BCX_SETICON sets the Icon.


 Syntax:

 BCX_SETICON(hwnd, Icon%)

 Parameters:

  • hwnd specifies a HWND handle to the control of which the icon is to be set.
  • Icon% specifies the integer value of a icon resource specifying the replacement icon.

BCX_SETICONSM statement

Purpose: BCX_SETICONSM sets the small Icon .


 Syntax:

 BCX_SETICONSM(hwnd, smIcon%)

 Parameters:

  • hwnd specifies a HWND handle to the control of which the small icon is to be set.
  • smIcon% specifies the integer value of a small icon resource specifying the replacement small icon.

BCX_SETCURSOR statement

Purpose:BCX_SETCURSOR sets the cursor.


 Syntax:

 BCX_SETCURSOR(hwnd, CursorName$)

 Parameters:

  • hwnd specifies a HWND handle to the control of which the cursor is to be set.
  • CursorName$ specifies a string literal or variable that contains the name of the cursor resource to be loaded.

Example


 BCX_RESOURCE 123 ICON "bcx.ico"
 
 GUI NOMAIN, ICON, 123
 
 DIM FooBloo AS HACCEL
 
 FUNCTION WINMAIN
   GLOBAL Form1 AS HWND
   BCX_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)
 END FUNCTION
 
 BEGIN EVENTS form1Proc
   SELECT CASE CBMSG
   CASE WM_KEYDOWN
     SELECT CASE wParam
     CASE VK_HOME
       MSGBOX "VK_HOME"
     CASE VK_END
       MSGBOX "VK_END"
     CASE VK_NEXT
       MSGBOX "VK_NEXT"
     CASE VK_PRIOR
       MSGBOX "VK_PRIOR"
     CASE VK_DOWN
       MSGBOX "VK_DOWN"
     CASE VK_UP
       MSGBOX "VK_UP"
     CASE VK_LEFT
       MSGBOX "VK_LEFT"
     CASE VK_RIGHT
       MSGBOX "VK_RIGHT"
     CASE VK_RETURN
       MSGBOX "VK_RETURN"
     END SELECT
   CASE WM_CLOSE
     DestroyWindow(Form1)
   END SELECT
 END EVENTS MAIN