Button Control

 

About Button Control

 

Button is a control for user to switch on or off as the input to the application.

 

Although Button is a simple control, it can have many different appearances. With PocketC, you can create push buttons, radio buttons, check boxes, and group boxes. 

 

Push button is the default button appearance.  The styles are BS_PUSHBUTTON and BS_DEFPUSHBUTTON.  BS_PUSHBUTTON will simply be a default button shape.  BS_DEFPUSHBUTTON means the button is the default button.  It is drawn with a heavy black rectangle around the button.  When users click the Enter key, the default button is pressed.

 

When a button is pressed, an event will be returned from event() function.  Its value is 8.  We define PM_COMMAND as 8.  When we mention PM_COMMAND in other documentation, it means value 8.  PM stands for Pocket Message.  In order to find out which button has been pressed, programmer must call guiid() to obtain the button control ID which was pressed.

 

Check box is a square with a user-defined label.  User can select a state by click on the square. Four variations of check boxes are standard, automatic standard, three-state and automatic three-state. 

 

BS_CHECKBOX is the standard style.  BS_AUTOCHECKBOX is same as the standard style, except the Checkbox State is automatically switched between checked and unchecked.  BS_3STATE and BS_AUTO3STATE have one more intermediate state between checked and unchecked. A gray cross mark in the square indicates the extra state. 

 

By default, the checkbox is displayed on the left side of the label.  Style BS_RIGHTBUTTON will set the checkbox to the right side of the label.

 

Radio button is appears with a small round circle with user-defined text on its right.  It has fewer states than the Checkbox control.  BS_RADIOBUTTON indicates the standard style.  BS_AUTORADIOBUTTON behaves just like the automatically switched Checkbox button, except appears differently. 

 

In addition to all the button styles we have discussed, there is one more feature of the button control.  It is Group Boxes style.  By using BS_GROUPBOX, it draws a rectangle with label displayed on its upper left corner.  Its sole purpose is to organize all the buttons on the screen by grouping certain buttons together with rectangles.

 

 

Using Button Control

 

Following example shows how to display all types of buttons.  When a user clicks on any buttons, the edit box control will display the name of the button control.

 

/*  Interface Control -- Window */

 

#define      WS_CHILD                0x40000000 

/*Specifies a child window. This should not be changed after the window is created.*/

#define      WS_VISIBLE        0x10000000 

/*Specifies a window that is initially visible. This style can be turned on and off to change window visibility.*/

#define      WS_BORDER               0x00800000 

/*draw a border around the control*/

 

/*  Interface Control -- Button */

 

#define      BS_3STATE         0x0005     

#define      BS_AUTO3STATE           0x0006     

#define      BS_AUTOCHECKBOX         0x0003     

#define      BS_AUTORADIOBUTTON            0x0009     

#define      BS_CHECKBOX       0x0002     

#define      BS_DEFPUSHBUTTON        0x0001     

#define      BS_GROUPBOX       0x0007     

#define      BS_PUSHBUTTON           0x0000     

#define      BS_RADIOBUTTON          0x0004     

#define      BS_BOTTOM         0x0800     

#define      BS_CENTER         0x0300     

#define      BS_FLAT           0x8000     

#define      BS_LEFT           0x0100     

#define      BS_PUSHLIKE       0x1000     

#define      BS_RIGHT          0x0200     

#define      BS_RIGHTBUTTON          0x0100     

#define      BS_TOP            0x0400     

#define      BS_VCENTER        0x0C00     

 

 

#define PM_COMMAND 8

 

/* custom define values */

#define BTN_PUSH_ID               601

#define BTN_RADIO_ID               602

#define BTN_CHECKBOX_ID  603

#define BTN_GROUPBOX_ID  604

#define ED_MONITOR_ID           600

 

main()

{

     

int ev; int gui_msg;

 

createctrl("EDIT","",WS_BORDER|WS_CHILD|WS_VISIBLE,0,50,30,150,20, ED_MONITOR_ID);

createctrl("BUTTON","Push",WS_VISIBLE|WS_CHILD|WS_BORDER|BS_PUSHBUTTON,0,50,75,100,20, BTN_PUSH_ID);

createctrl("BUTTON","Radio",WS_VISIBLE|WS_CHILD|BS_AUTORADIOBUTTON,0,50,100,100,20, BTN_RADIO_ID);

createctrl("BUTTON","Checkbox",WS_VISIBLE|WS_CHILD|BS_AUTOCHECKBOX,0,50,125,100,20, BTN_CHECKBOX_ID);

createctrl("BUTTON","Groupbox",WS_VISIBLE|WS_CHILD|BS_GROUPBOX,0,50,150,100,60, BTN_GROUPBOX_ID);

 

while(1)

{

ev = event(0);

switch (ev){

 

case PM_COMMAND :

 

      gui_msg = guiid();

      switch  (gui_msg)

      {

            case BTN_PUSH_ID:

                  editset(ED_MONITOR_ID,"PushButton");

                  break;

            case BTN_RADIO_ID:

                  editset(ED_MONITOR_ID,"RadioButton");

                  break;

            case BTN_CHECKBOX_ID:

                  editset(ED_MONITOR_ID,"CheckBox");

                  break;

 

      };

     

      break;

};

}

}

 

Button Control Reference

 

 

 

BS_3STATE         0x0005      /*Creates a button that is the same as a check box, except that the box can be grayed as well as checked or unchecked. Use the grayed state to show that the state of the check box is not determined.*/

 

BS_AUTO3STATE           0x0006      /*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, grayed, and unchecked.*/

 

BS_AUTOCHECKBOX         0x0003      /*Creates a button that is the same as a check box, except that the check state automatically toggles between checked and unchecked each time the user selects the check box.*/

 

BS_AUTORADIOBUTTON            0x0009      /*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 unchecked.*/

 

BS_CHECKBOX       0x0002      /*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        0x0001      /*Creates a push button that behaves like a BS_PUSHBUTTON style button, but also has a heavy black border. 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       0x0007      /*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_PUSHBUTTON           0x0000      /*Creates a push button that posts a WM_COMMAND message to the owner window when the user selects the button.*/

 

BS_RADIOBUTTON          0x0004      /*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_BOTTOM         0x0800      /*Places text at the bottom of the button rectangle.*/

 

BS_CENTER         0x0300      /*Centers text horizontally in the button rectangle.*/

 

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

 

BS_LEFT           0x0100      /*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_PUSHLIKE       0x1000      /*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          0x0200      /*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          0x0100      /*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_TOP            0x0400      /*Places text at the top of the button rectangle.*/

 

BS_VCENTER        0x0C00      /*Places text in the middle (vertically) of the button rectangle.*/