JanetTerra
Oct 31, 2007
- "Changed two instances of handles passed as long to handles passed as ulong"
JanetTerra
Oct 31, 2007
- "Changed two instances of handles passed as long to handles passed as ulong"
The PUSHLIKE Stylebits
Stylebits allows checkboxes and radiobuttons to appear to be pushed rather than selected. Stefan Pendl, always generous with explanations and code, offered button information in response to a query posed at the Liberty BASIC yahoo! message group. (See the original message #27196.)
For a better understanding, the following controls are all defined as buttons by Windows:
- button
- groupbox
- bmpbutton
- checkbox
- radiobutton
You can use the style _BS_PUSHLIKE to change the radiobutton and checkbox into a pushbutton, that will keep its state.These buttons are called toggle buttons, they are raised when inactive and sunken when active. To find out more about toggle buttons, read the information at the MSDN Library.
Stefan's Demo
Stefan was kind enough to grant permission for his yahoo! code to be republished here. Using the _BS_PUSHLIKE stylebits, a checkbox and two grouped radiobuttons are altered from their usual forms to button forms. The change in style does not alter the set and unset properties.nomainwin groupbox #main.gb, "Toggle Radiobuttons", 10, 10, 120, 100 stylebits #main.bt, _BS_PUSHLIKE, 0, 0, 0 radiobutton #main.bt, "Toggle", [pushed], [pushed], 20, 30, 100, 30 stylebits #main.bt1, _BS_PUSHLIKE, 0, 0, 0 radiobutton #main.bt1, "Toggle1", [pushed], [pushed], 20, 70, 100, 30 stylebits #main.bt2, _BS_PUSHLIKE, 0, 0, 0 checkbox #main.bt2, "Toggle Checkbox", [pushed], [pushed], 20, 120, 100, 30 open "Toggle demo" for window as #main #main, "trapclose [quit]" wait [pushed] wait [quit] close #main endStylebits, Graphics and the API call, "SendMessageA"
Creating graphic buttons using _BS_BITMAP and CallDLL #user32, "SendMessageA" has been discussed by Alyce Watson in API Corner - Easy BMP Buttons (LB Newsletter #123) and also in Stylebits - Buttons. In these next two demos, the graphics are drawn and captured within the program. You could easily substitute your own code for loading the bitmaps from file.
Button Event Handlers: Branch Label or Sub?
As is the case with most event handlers, the button event handler can be either a branch label or a sub. The advantage of using a sub with grouped checkboxes or radiobuttons is that the control handle is automatically passed into the sub. With careful parsing of the control handle extension and the use of Select Case, code becomes much more efficient than is possible with branch labels. The following demo contains just four radiobuttons within a group, but could easily serve a group of 100 radiobuttons or more.
A List of Stylebits
You can get a list of all dwStyles and dwExStyles available with the Stylebits command at the MSDN Library Center. Be sure to precede these constants with an underscore (if constant is BS_PUSHLIKE, then LB Stylebits is _BS_PUSHLIKE) when using Windows constants in your Liberty BASIC programs.