Button – Giavapps Windows API

 

 

api_button_create(ParentHandle, X, Y, W, H, Flags, ExFlags) This function creates a button.

ParentHandle: parent handle.
X: x coordinate.
Y: y coordinate.
W: width.
H: height.
Flags: Flags of the control. Flags must be separated with the symbol "|".
ExFlags: extended flags of the control. Flags must be separated with the symbol "|".

 

Flags

 

This control supports the Window Styles and you can specify any of the styles listed below:

 

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.

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.

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.

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. If the button is in a dialog box, the user can select the button by pressing the ENTER key, even when the button does not have the input focus. This style is useful for enabling the user to quickly select the most likely (default) option.

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.

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_OWNERDRAW Creates an owner-drawn button. Do not combine the BS_OWNERDRAW style with any other button styles.

BS_PUSHBUTTON Creates a push button that posts a WM_COMMAND message to the owner window when the user selects the button.

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_USERBUTTON Obsolete, but provided for compatibility with 16-bit versions of Windows. Applications should use BS_OWNERDRAW instead.

BS_BITMAP Specifies that the button 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 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 Enables the button to send notification codes to its parent window. This flag is required in order to use api_button_ger_doubleclicked(). You may also need to add the BS_RADIOBUTTON or BS_OWNERDRAW style.

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.

 

Extended Flags

 

This control supports the Extended Window Styles.

 

Return Value

 

If the function succeeds, the return value is a handle to the new button.

If the function fails, the return value is false.

To get extended error information, call api_control_get_last_error().

 

Control Functions

 

api_button_set_checked(ButtonHandle, Checked) Sets the check state of a radio button or check box.

ButtonHandle: it must be a ButtonHandle.
Checked: the check state to set.

The argument Checked can be one of the following values:

BST_CHECKED Sets the button state to checked.

BST_INDETERMINATE Sets the button state to grayed, indicating an indeterminate state. Use this value only if the button has the BS_3STATE or BS_AUTO3STATE style.

BST_UNCHECKED Sets the button state to cleared.

 

api_button_get_checked(ButtonHandle) Returns the check state of a radio button or check box.

ButtonHandle: it must be a ButtonHandle.

The returned value can be one of the following values:

BST_CHECKED Button is checked.

BST_INDETERMINATE Button is grayed, indicating an indeterminate state. Applies only if the button has the BS_3STATE or BS_AUTO3STATE style.

BST_UNCHECKED Button is cleared.

 

api_button_set_highlight(ButtonHandle, Highlight) Sets the highlight state of a button. The highlight state indicates whether the button is highlighted as if the user had pushed it.

ButtonHandle: it must be a ButtonHandle.
Highlight: true to highlight the button; otherwise false.

 

api_button_get_state(ButtonHandle) Gets the check state of a radio button or check box. The return value specifies the current state of the button.

ButtonHandle: it must be a ButtonHandle.

You can use the following values to extract information about the state:

BST_CHECKED Indicates the button is checked. A radio button is checked when it contains a dot; a check box is checked when it contains an X.

BST_FOCUS Specifies the focus state. A nonzero value indicates that the button has the keyboard focus.

BST_INDETERMINATE Indicates the button is grayed because the state of the button is indeterminate. This value applies only if the button has the BS_3STATE or BS_AUTO3STATE style.

BST_PUSHED Specifies the highlight state. A nonzero value indicates that the button is highlighted. A button is automatically highlighted when the user positions the cursor over it and presses and holds the left mouse button. The highlighting is removed when the user releases the mouse button.

BST_UNCHECKED Indicates the button is cleared. Same as a return value of zero.

 

api_button_get_clicked(ButtonHandle) This function returns true if the user clicks on the button with handle ButtonHandle or false otherwise.

ButtonHandle: it must be a ButtonHandle.

 

api_button_get_doubleclicked(ButtonHandle) This function returns true if the user doubleclicks on the button with handle ButtonHandle. (This function works only with BS_NOTIFY style)

ButtonHandle: it must be a ButtonHandle.

 

api_button_set_bitmap(ButtonHandle, BitmapHandle) Associates a bitmap image with the button with the specified ButtonHandle. The return value is a handle to the bitmap previously associated with the button, if any; otherwise, it is false.

ButtonHandle: it must be a ButtonHandle.
BitmapHandle: it must be a BitmapHandle.

 

api_button_set_icon(ButtonHandle, IconHandle) Associates an icon with the button with the specified ButtonHandle. The return value is a handle to the icon previously associated with the button, if any; otherwise, it is false.

ButtonHandle: it must be a ButtonHandle.
IconHandle: it must be an IconHandle.

 

BS_ICON or BS_BITMAP set? api_button_set_bitmap() or api_button_set_icon() called? Result
Yes Yes Show icon only.
No Yes Show icon and text.
Yes No Show text only.
No No Show text only.

 

Code Examples

 

Creating a Button

 

button = api_button_create(window,10,10,100,32,WS_VISIBLE | WS_CHILD,0);

 

Creating a Check Box

 

button = api_button_create(window,10,32,100,32,WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,0);

 

Creating a Radio Button

 

button = api_button_create(window,10,64,100,32,WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON,0);

 

Checking if the User clicks on a given Button

 

Step Event:

 

if(api_button_get_clicked(button))
{
api_messagebox(window, “Clicked!”, “INFO”, MB_OK);
}

 

Associating an Icon with a Button

 

icon = api_icon_add(“myicon.ico”);
api_button_set_icon(button,icon);

 

I am Luigi Piscopo, also known as DJ GiDeejay / Producer / Remixer in the music world. I am a Producer with a lot of experience in photo editing, video editing, audio editing, graphic design, web design, programming and promotion.

Leave a Reply

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

*