| Header file: | button.h |
| Object name: | fBUTTON |
| Object index: | 1 of 2 Objects (Other object: fRADIOCONTROLLER) |
The button is a general purpose button. This class is a wrapper for the API window class button. However, the button covers a lot of scope. The button, with the appropriate options, can be either a button, a radio button, a checkbox, a togglebutton, or a group box.
This component is derived from _GUIBASE, and inherits the properties from that.
| Name | Description | Value |
| Name | Description | Value |
| bsNormal | This is a standard button - no frills, nothing wonderful, yhadda yhadda... | WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BSCENTER | BS_NOTIFY | WS_TABSTOP |
| bsCheckBox | With this option, the button becomes a checkbox - click once to check, and again to uncheck! Neat! | WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX | BS_NOTIY | WS_TABSTOP |
| bsRadioButton | A radio button it will be with this option. Select one radio button, and the rest of the group become unselected. See the fRADIOCONTROLLER for an easier way of handling things with multiple radio buttons. | WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON | BS_NOTIFY | WS_TABSTOP |
| bsToggleButton | This button looks like a button, but works like a checkbox. Push it in, it stays. Push again, it releases. Rather useful. If you want these to act like a set of radio buttons (say a mode selection toolbar), then you can use the fRADIOCONTROLLER to make these behave that way. | WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX | BS_PUSHLIKE | BS_NOTIFY | WS_TABSTOP |
| bsGroupBox | Here we have a nice looking group-box type thing. Exactly why this is in the button class, I don't know. Anyway, muck around with it. Any buttons and things that you want in this, just make them children of this window. Please note that this has some redrawing problems which are currently unsolvable. | WS_VISIBLE | WS_CHILD | BS_GROUPBOX | BS_NOTIFY | WS_CLIPCHILDREN | WS_CLIPSIBLINGS |
| The following options are a little different. Whereas the above options are a mixture of styles to create one type of object, the following styles are by themselves. You can mix them up to make more customised objects. You mix the styles with the OR (|) operator. You can even mix them with the above styles to enhance them further. Mix and match away! | ||
| esButton | This style makes the object a pushbutton. | BS_PUSHBUTTON |
| esDefaultButton | This style adds a thick black border around that button and makes it respond to the enter key. Use gently! I have not been able to remove this style once applied! | BS_DEFPUSHBUTTON |
| esToggle | Makes the button a toggle button. | BS_PUSHLIKE |
| esCheck | This makes the button like a checkbox. | BS_AUTOCHECKBOX |
| esManualCheck | This makes the button a checkbox - but with one difference. Instead of automatically swapping states, you will need to intercept the clicks and swap the state of the button. | BS_CHECKBOX |
| esRadio | This makes the button a radio button. | BS_AUTORADIOBUTTON |
| esManualRadio | This makes the button a radio button - but with one difference. Instead of changing state automatically within a group, you will need to intercept the clicks and change the states of the buttons. | BS_RADIOBUTTON |
| esOwnerDraw | Draw your own button! By setting this style, you will need to intercept the WM_PAINT (OnPaint) message, and draw the button for Windows. | BS_OWNERDRAW |
| esShowBitmap | This style makes the button show a bitmap. You would set the bitmap through methods shown in the next table. | BS_BITMAP |
| esShowIcon | Instead of a bitmap, you can make the button display an icon. Use the methods shown in the next table to apply an icon. | BS_ICON |
| esMultiline | This style may come in handy... ordinarily, if you set the text of a button, it will simply be put on the screen in one long line, regardless of how many times you have put '\n' in the string. With this style, the button interprets this '\n', and actually makes multiple lines. | BS_MULTILINE |
| esTextLeft | This makes the text of the button go on the left side of the button - and will also swap the side of the radio/check box. | BS_LEFTTEXT |
| esTextRight | This style makes the text go to the right of the button - and may possibly swap the side of the radio/check box, if you have one. | BS_RIGHTTEXT |
| esTextCenter | This style centres the text in the button's area. | BS_CENTER |
| esTextBottom | This style places the text on the bottom of the buttons area. | BS_BOTTOM |
| esTextTop | This style places the text at the top of the button's area. | BS_TOP |
| Prototype | Description |
| void SetButtonColour(COLORREF Colour); | This sets the button's background colour. Please note that this only works in conjunction with the GUI controller, as Windows seems to think it's funny to make this work as a callback function... |
| void UnsetButtonColour(void); | This function takes away the button's colouring. This function is only available with the GUI controller. |
| void Checked(bool Check); | This function sets whether the button is checked or not (applies to radio buttons, checkboxes, or toggle buttons). Pass TRUE to check, FALSE to uncheck. |
| bool Checked(void); | This function checks to see whether the button is checked or unchecked. It returns TRUE if it is checked, or otherwise it returns FALSE. This function works for checkboxes, radio buttons, and toggle buttons. |
| void SetBitmap(HBITMAP Bitmap); | This function sets the bitmap to be displayed on the button. The esBitmap style must be applied for this to work. You also need to pass along the handle to a bitmap. |
| void SetIcon(HICON Icon); | This function sets the icon to be displayed on the button. The esIcon style must be applied for this to work. You will need to supply a handle to an icon. |
| void MakeDefault(void); | Gives the button a thick black border and makes the button respond to the enter key. |
| void UnMakeDefault(void); | This removes the thick black border and revokes the right of the button to be activated with the enter key. This function has not removed the style in my experience (ie. Doesn't work). Use this accordingly. |
| void SimulateClick(void); | This function simulates a click on the button. Could be handy... |
Please note that the events listed here are done in pairs; one as a property, and the other as a function. The property is assigned a function name, ie. Object.OnClick = &FunctionName, whilst the function is called to verify that an event has occured. Please see the chapter on event handling for information on how to use these correctly.
| Prototype | Description | Sent under |
|
bool CheckClicked(wParam, lParam); void (*OnClick)(fBUTTON* Sender); | This event occurs when the button is clicked. | WM_COMMAND |
|
bool CheckDoubleClicked(wParam, lParam); void (*OnDoubleClick)(fBUTTON* Sender); | This event occurs when the button has been double clicked. This really only applies to groupboxes and radio buttons. | WM_COMMAND |
|
bool CheckHilite(wParam, lParam); void (*OnHilite)(fBUTTON* Sender); | This event occurs only when the button is ownerdrawn. When the button is in it's down state, this event will be called. You are meant to draw the button now in the down (or hilighted) state. | WM_COMMAND |
|
bool CheckPaint(wParam, lParam); void (*OnPaint)(fBUTTON* Sender); | This event is sent when the button needs to be repainted. So get to it! Note that this message is only sent with the bsOwnerDraw style. | WM_COMMAND |
|
bool CheckUnHilite(wParam, lParam); void (*OnUnHilite)(fBUTTON* Sender); | This event is sent when the button is un-hilighted, or the mouse button has let go. You should redraw the button in the up (or unhilighted) state. | WM_COMMAND |
The following snippet gives a basic idea of how to use this component.
//Wherever you do your initialisation...
fBUTTON Button;
//Make the button, with the parent as Window,
//and the text "Click me!"
Button.CreateWin(&Window, "Click me!", BUTTON_ID, bsUsual, bsNormal);
| Back to index | The FreeFoote Foundation Classes Documentation |