logo

Global constants and variables

The following page is split into two sections: global constants and global variables.

Global constants

The following are global constants groupted by function.

Boolean

The traditional way of having boolean variables in QB64 is by setting True = -1, as it allows bit manipulation with operators like NOT, AND, OR, etc (False = NOT True).

Back style

Used for setting a control's background to opaque or transparent.

Text align

MessageBox

For a detailed explanation of using the message box global constants, please refer to the MessageBox method.

Buttons
  • MsgBox_OkOnly
  • MsgBox_OkCancel
  • MsgBox_AbortRetryIgnore
  • MsgBox_YesNoCancel
  • MsgBox_YesNo
  • MsgBox_RetryCancel
  • MsgBox_CancelTryagainContinue
Modal
  • MsgBox_AppModal
  • MsgBox_SystemModal
  • MsgBox_SetForeground
Default button
  • MsgBox_DefaultButton1
  • MsgBox_DefaultButton2
  • MsgBox_DefaultButton3
  • MsgBox_Defaultbutton4
Icons
  • MsgBox_Critical
  • MsgBox_Question
  • MsgBox_Exclamation
  • MsgBox_Information
Results
  • MsgBox_Ok
  • MsgBox_Cancel
  • MsgBox_Abort
  • MsgBox_Retry
  • MsgBox_Ignore
  • MsgBox_Yes
  • MsgBox_No
  • MsgBox_Tryagain
  • MsgBox_Continue

Global Variables

Global variables affect the drawing, input, or event dispatcher routines. Their names always start with the UI prefix.

__UI_ContextMenuSourceID

Global variable __UI_ContextMenuSourceID holds the ID of the control associated to a ContextMenu control that triggered the event.

For example, if you have three picture box controls, each associated with the same context menu, let the context menu have an item labeled change-color. When clicked, it will change the associated picture box background to a random color.

Sub __UI_Click (id As Long)
    Select Case id
        Case Form1
        Case PictureBox1
        Case PictureBox2
        Case PictureBox3
        Case MenuItem1
            Control(__UI_ContextMenuSourceID).BackColor = _RGB(Rnd * 255, Rnd * 255, Rnd * 255)
    End Select
End Sub

__UI_ForceRedraw

__UI_ForceRedraw is a global variable that triggers a redraw for all form controls when it's set to True. When it's not set to True, controls are redrawn only when changes in their properties or state are detected.

__UI_ForceRedraw = True

It's automatically set back to False after the next form repaint is executed.
If you want to trigger a redraw for only a specific control, use the Redraw property:

Control(myControl).Redraw = True

__UI_KeyHit

__UI_KeyHit is a global variable of type LONG INTEGER. It holds the scan code of the last key pressed by the user. Positive values mean a key was pressed, while negative values indicate a key was released.

This variable can be accessed anywhere, but it's usually manipulated in KeyPress event handlers, especially for Textbox controls, as it can be used to change the key presses that actually get sent to the control.

__CtrlIsDown, __UI_ShiftIsDown, __UI_AltIsDown

Keyboard modifiers are global variables that hold True when the key they represent is being held down.

__UI_UnloadSignal

The global variable __UI_UnloadSignal will be set to True if the user requests that the program be closed, either by clicking the X button on the title bar or by hitting Alt+F4 (Windows only).

In an BeforeUnload event, set this variable to False to cancel the quit request.

__UI_KeepScreenHidden

The global variable __UI_KeepScreenHidden can be set to True if you don't want InForm to show the main form immediately, which is useful when your program needs to perform any startup routines before the main form can be displayed.

In the BeforeInit event, set this variable to True to avoid showing the form immediately.

Caution:

If you do set __UI_KeepScreenHidden to True, don't forget to use _SCREENSHOW somewhere later in your program, or your main form will never be displayed and your program will keep running as a hidden window.

__UI_EventsTimer __UI_RefreshTimer

For timer critical issues:


'Try adding this before your search routine:

Code: QB64: [Select]
        TIMER(__UI_EventsTimer) OFF
        TIMER(__UI_RefreshTimer) OFF

'Just don't forget to turn those timers back on after you're done:

Code: QB64: [Select]
        TIMER(__UI_EventsTimer) ON
        TIMER(__UI_RefreshTimer) ON

InForm's events and repaint routines are timer-based, and that surely takes up some cycles. The trade-off of the above method is that your interface will remain unresponsive while the calculations take place. You must judge if the speed gain is considerable enough to justify the tweak.