Creating a Control |
Top Previous Next |
Emergence BASIC supports dynamic creation of controls in windows or dialogs. In a window the control is created and added immediately. In a dialog the control is added to the dialog template and created when the dialog is shown. The CONTROL statement is used for both windows and dialogs. The generalized syntax of the control statement is: CONTROL parent, type, title, left, top, width, height, style_flags, id The parent of the control must be specified and can be either a WINDOW or DIALOG variable. The dimensions of the control are in pixels and are automatically converted to device units for dialogs. This allows the same control definition to be used for both a dialog and a window. The type of the control must be one of the following control constants: @BUTTON @CHECKBOX @RADIOBUTTON @EDIT @LISTBOX @COMBOBOX @STATIC @SCROLLBAR @GROUPBOX @RICHEDIT @LISTVIEW @STATUS @SYSBUTTON @RGNBUTTON @TREEVIEW Example definitions: CONTROL w,@BUTTON,"Save",56,100,50,20,0, 1
Each control has its own creation flags and returns specific messages to your window or dialog subroutine, see the specific topics for each control type for details. The @IDCONTROL message is sent when any operation is done to one of the controls. @CONTROLID will contain the ID value specified when the control was created. @WPARAM may contain additional information. Also it is important to check the value of @NOTIFYCODE for most control types. Communication with the control is done with generic control functions and the CONTROLCMD function. They will be covered in detail for each individual control type. The easiest way to create and size a control is with the dialog editor/GUI designer. The @SYSBUTTON control is a Windows XP Theme compatible button control. When using @SYSBUTTON you will not be able to set the color of the control manually with SETCONTROLCOLOR. Bitmap buttons and static controls Buttons and static controls have the capability of displaying a bitmap instead of text. To define a bitmap button use the flag @CTLBTNBITMAP for a button or @CTLSTCBITMAP for static controls To specify the bitmap to display set the buttons text to the complete pathname to the bitmap file with the SETCONTROLTEXT statement. If your button is contained in a dialog use SETCONTROLTEXT in response to the @IDINITDIALOG message. Example of bitmap static control: DEF d1 as DIALOG Changing the font of a control The text printed in a control will use the default font specified in the display control panel unless changed with the SETFONT statement. The SETFONT statement has the syntax of: SETFONT window | dialog, typeface, height, weight {, flags} {,Control_ID} Height and weight can both be 0 in which case a default size and weight will be used. Weight ranges from 0 to 1000 with 700 being standard for bold fonts and 400 for normal fonts. Flags can be a combination of @SFITALIC, @SFUNDERLINE or @SFSTRIKEOUT for italicized and underlined fonts. If an ID is specified then the font of a control is changed. The height parameter is specified in points. 1 point is equal to 1/72nd of an inch. If you want a font that is 1/2 an inch high you would specify a point size of 36. Creating other types of controls Windows supports a wide variety of built in and third party controls. To create a control not directly supported by the CONTROL statement and dialog editor use the CONTROLEX statement and specify the class name of the control. The syntax of the CONTROLEX statement is: CONTROLEX parent, class, title, left, top, width, height, style, exStyle, ID The parent of the control must be specified and can be either a WINDOW or DIALOG variable. The dimensions of the control are in pixels and are automatically converted to device units for dialogs. This allows the same control definition to be used for both a dialog and a window. All control styles must be explicitly specified since the compiler can't predict what visual styles are common for the control. The only control styles automatically added are WS_VISIBLE and WS_CHILD. exStyle is the extended window style of the control. The following extended styles are predefined for use with CONTROLEX: @EXCLIENTEDGE - Specifies that a control has a 3D look — that is, a border with a sunken edge. @EXSTATICEDGE - Creates a control with a three-dimensional border style intended to be used for items that do not accept user input. @EXWINDOWEDGE - Specifies that a control has a border with a raised edge. @EXLEFT - Gives a control generic left-aligned properties. Default. @EXRIGHT - Gives a control generic right-aligned properties. This depends on the control class. After the control is created you can use the basic control manipulation functions on it such as SETFONT, SETCONTROLTEXT, SETSIZE. GETSIZE, etc. Other functionality of the specific control can be achieved by using SENDMESSAGE. The custom control is automatically destroyed when the window or dialog is closed so there is no need to use the DestroyWindow API function. The common control library is also automatically initialized when creating the control. The CONTROLEX statement will return the window handle of the created control when used with a window parent. If used with a dialog the handle to the control can be obtained with the GETCONTROLHANDLE function during the @IDINITDIALOG message. Example creating a progress bar control: CONST PBM_SETPOS = 0x402
Class names for the Windows common controls: Header Control - "SysHeader32" Toolbar Control - "ToolbarWindow32" ReBar Control - "ReBarWindow32" ToolTips Control - "tooltips_class32" TrackBar Control - "msctls_trackbar32" UpDown Control - "msctls_updown32" Progress Control - "msctls_progress32" HotKey Control - "msctls_hotkey32" ComboBoxEx - "ComboBoxEx32" Tab Control - "SysTabControl32" Animate Control - "SysAnimate32" Month Calendar Control - "SysMonthCal32" Date/Time Control - "SysDateTimePick32" IP Address Edit - "SysIPAddress32" Pager Control - "SysPager" NativeFont Control - "NativeFontCtl" The above list is not all inclusive as Microsoft adds new common control types with each release of Windows. The usage and messages the controls use can be found by searching Google or MSDN |