Button control help

The button controls can create buttons, checkboxes and radio buttons.

Function help:

Real API_Button_Create (Real Parent Handle, Real X, Real Y, Real Width, Real Height, Real Style Flags, Real Extended Style Flags);

This function creates a new button control.

Argument list:
(0) Parent Handle: Identifies the window handle of the window to create this control on.
(1) X: The horizontal position of the control in pixels, relative to the parent window.
(2) Y: The vertical position of the control in pixels, relative to the parent window.
(3) Width: The horizontal size of the control in pixels.
(4) Height: The vertical size of the control in pixels.
(5) Style Flags: The style flags, supports the Global Control Styles and the following styles:

BS_3STATE
Creates a button that is the same as a check box, except that the box can be grayed as well as checked or cleared. Use the grayed state to show that the state of the check box is not determined.
Don't use this style in combination with other styles.

BS_AUTO3STATE
Creates a button that is the same as a three-state check box, except that the box changes its state when the user selects it. The state cycles through checked, indeterminate, and cleared.

BS_AUTOCHECKBOX
Creates a button that is the same as a check box, except that the check state automatically toggles between checked and cleared each time the user selects the check box.
Don't use this style in combination with other styles.

BS_AUTORADIOBUTTON
Creates a button that is the same as a radio button, except that when the user selects it, the system automatically sets the button's check state to checked and automatically sets the check state for all other buttons in the same group to cleared.
Don't use this style in combination with other styles.

BS_CHECKBOX
Creates a small, empty check box with text. By default, the text is displayed to the right of the check box. To display the text to the left of the check box, combine this flag with the BS_LEFTTEXT style (or with the equivalent BS_RIGHTBUTTON style).

BS_DEFPUSHBUTTON
Creates a push button that behaves like a BS_PUSHBUTTON style button, but has a distinct appearance.

BS_GROUPBOX
Creates a rectangle in which other controls can be grouped. Any text associated with this style is displayed in the rectangle's upper left corner.
Don't use this style in combination with other styles.

BS_LEFTTEXT
Places text on the left side of the radio button or check box when combined with a radio button or check box style. Same as the BS_RIGHTBUTTON style.

BS_RADIOBUTTON
Creates a small circle with text. By default, the text is displayed to the right of the circle. To display the text to the left of the circle, combine this flag with the BS_LEFTTEXT style (or with the equivalent BS_RIGHTBUTTON style). Use radio buttons for groups of related, but mutually exclusive choices.

BS_BITMAP
Specifies that the button only displays a bitmap.

BS_BOTTOM
Places text at the bottom of the button rectangle.

BS_CENTER
Centers text horizontally in the button rectangle.

BS_ICON
Specifies that the button only displays an icon.

BS_FLAT
Specifies that the button is two-dimensional; it does not use the default shading to create a 3-D image.

BS_LEFT
Left-justifies the text in the button rectangle. However, if the button is a check box or radio button that does not have the BS_RIGHTBUTTON style, the text is left justified on the right side of the check box or radio button.

BS_MULTILINE
Wraps the button text to multiple lines if the text string is too long to fit on a single line in the button rectangle.

BS_NOTIFY
This function enables the use of more secondary check functions.

BS_PUSHLIKE
Makes a button (such as a check box, three-state check box, or radio button) look and act like a push button. The button looks raised when it isn't pushed or checked, and sunken when it is pushed or checked.

BS_RIGHT
Right-justifies text in the button rectangle. However, if the button is a check box or radio button that does not have the BS_RIGHTBUTTON style, the text is right justified on the right side of the check box or radio button.

BS_RIGHTBUTTON
Positions a radio button's circle or a check box's square on the right side of the button rectangle. Same as the BS_LEFTTEXT style.

BS_TEXT
Specifies that the button displays text.

BS_TOP
Places text at the top of the button rectangle.

BS_VCENTER
Places text in the middle (vertically) of the button rectangle.

Style flags can be separated by a bitwise or '|' operator.

(6) Extended Style Flags: This can be any combination of the Global Extended Control Styles.

Return value:
If this function succeeds, it returns the Control ID of the control, otherwise it returns 0.


Real API_Button_GetCheck ( Real Control ID )

This function returns the check state of a button which is created with the BS_AUTOCHECKBOX, BS_AUTORADIOBUTTON, BS_AUTO3STATE, BS_CHECKBOX, BS_RADIOBUTTON, or BS_3STATE style.

Argument list:
(0) Control ID, the Control ID returned by API_Button_Create.

Return value:
When failed, this function returns false (0), otherwise it returns one of the following values:

BST_CHECKED - The control is checked.
BST_INDETERMINATE - The control is grayed. (Only BS_3STATE or BS_AUTO3STATE)
BST_UNCHECKED - The control is cleared. (not checked)

Real API_Button_SetCheck ( Real Control ID , Real Check state )

This function sets the check state of a button which is created with the BS_AUTOCHECKBOX, BS_AUTORADIOBUTTON, BS_AUTO3STATE, BS_CHECKBOX, BS_RADIOBUTTON, or BS_3STATE style.

Argument list:
(0) Control ID, the Control ID returned by API_Button_Create.
(1) Check state, the state to set the control to, one of the following:

BST_CHECKED - The control is checked.
BST_INDETERMINATE - The control is grayed. (Only BS_3STATE or BS_AUTO3STATE)
BST_UNCHECKED - The control is cleared. (not checked)

Return value:
This function always returns false (0).
Real API_Button_SetImage ( Real Control ID , Real Image Type, Real Image resource handle )

This function changes the image assigned to a button.

Argument list:
(0) Control ID, the Control ID returned by API_Button_Create.
(1) Image type:
0 - The image is a bitmap, argument2 specifies a bitmap resource handle, see API_Resource_LoadBitmap.
1 - The image is an icon, argument2 specifies a icon resource handle, see API_Resource_LoadIcon.
(2) The resource handle to the image.

Return value:
This function returns the handle to the previous image resource handle or false (0) otherwise.
Real API_Button_GetImage ( Real Control ID , Real Image Type )

This function gets the image assigned to a button.

Argument list:
(0) Control ID, the Control ID returned by API_Button_Create.
(1) Image type:
0 - The image is a bitmap, this function returns a bitmap resource handle.
1 - The image is an icon, this function returns a icon resource handle.

Return value:
This function returns the handle to the image resource handle or false (0) otherwise.

Secondary check commands for buttons:

BN_CLICKED - The button is clicked.
BN_DBLCLK - The button is double clicked, the button must be created with BS_NOTIFY.
BN_KILLFOCUS - The button loosed focus, the button must be created with BS_NOTIFY
BN_SETFOCUS - The button gained focus, the button must be created with BS_NOTIFY

Example:

Command = API_Check_Command (1); // Check commands for check handle 1

if ( Command == Button1 ) // Button1 sends a command
{
Second = API_Check_SecondaryCommand (1); // Check the command type

if ( Second == BN_DBLCLK) // The button is double-clicked
{
show_message ("You double-clicked Button1.");
}

}



Example code:

Button1 =API_Button_Create(Win, 5,5,100,20,0,0);
// Create a button

Checkbox1 =API_Button_Create(Win, 5,25,100,20,BS_AUTOCHECKBOX,0);
// Create a checkbox


Radio1 = API_Button_Create (Win,5,45,100,20,BS_AUTORADIOBUTTON,0);
// Create a radio control

Return to help index