|
Post by pablosl on Jan 31, 2019 20:11:16 GMT -5
Hello,
I would like to know How to click a normal button (not bmpbutton) and then it keeps depressed.
Thanks, -Pablo
|
|
|
Post by Chris Iverson on Jan 31, 2019 22:52:55 GMT -5
You can't do it directly with a button(since that's not a button's behavior), but you can simulate it by using STYLEBITS to tell a checkbox or radiobox to look like/pretend to be a button.
'Form created with the help of Freeform 3 v07-15-08 'Generated on Jan 31, 2019 at 21:47:57
[setup.main.Window]
'-----Begin code for #main
nomainwin WindowWidth = 275 WindowHeight = 250 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
'-----Begin GUI objects code
checkbox #main.checkbox1, "Checkbox 1", [checkbox1Set], [checkbox1Reset], 15, 12, 95, 25
stylebits #main.checkbox2, _BS_PUSHLIKE, 0, 0, 0 checkbox #main.checkbox2, "Checkbox 2", [checkbox2Set], [checkbox2Reset], 15, 42, 95, 25
radiobutton #main.radiobutton3, "RadioButton 1", [radiobutton3Set], [radiobutton3Reset], 10, 92, 109, 25
stylebits #main.radiobutton4, _BS_PUSHLIKE, 0, 0, 0 radiobutton #main.radiobutton4, "RadioButton 2", [radiobutton4Set], [radiobutton4Reset], 10, 122, 109, 25
stylebits #main.radiobutton5, _BS_PUSHLIKE, 0, 0, 0 radiobutton #main.radiobutton5, "RadioButton 3", [radiobutton5Set], [radiobutton5Reset], 10, 152, 109, 25
'-----End GUI objects code
open "untitled" for window as #main print #main, "font ms_sans_serif 10" print #main, "trapclose [quit.main]"
[main.inputLoop] 'wait here for input event wait
[checkbox1Set] 'Perform action for the checkbox named 'checkbox1'
'Insert your own code here
wait
[checkbox1Reset] 'Perform action for the checkbox named 'checkbox1'
'Insert your own code here
wait
[checkbox2Set] 'Perform action for the checkbox named 'checkbox2'
'Insert your own code here
wait
[checkbox2Reset] 'Perform action for the checkbox named 'checkbox2'
'Insert your own code here
wait
[radiobutton3Set] 'Perform action for the radiobutton named 'radiobutton3'
'Insert your own code here
wait
[radiobutton3Reset] 'Perform action for the radiobutton named 'radiobutton3'
'Insert your own code here
wait
[radiobutton4Set] 'Perform action for the radiobutton named 'radiobutton4'
'Insert your own code here
wait
[radiobutton4Reset] 'Perform action for the radiobutton named 'radiobutton4'
'Insert your own code here
wait
[radiobutton5Set] 'Perform action for the radiobutton named 'radiobutton5'
'Insert your own code here
wait
[radiobutton5Reset] 'Perform action for the radiobutton named 'radiobutton5'
'Insert your own code here
wait
[quit.main] 'End the program close #main end
Checkbox 2 behaves like a checkbox, but looks like a button: clicking it once will "press" it and hold it, and clicking it again will release it, just like a checkbox(checked/unchecked).
Radiobuttons 2 and 3 behave like radiobuttons; if you select one, it stays "pressed" until you press a different one. You can think of this like the favorite station selectors on old car radios, or the control buttons on cassette players.
|
|
|
Post by BeeTrap on Feb 2, 2019 9:14:23 GMT -5
Nice bit of code, Chris. I could not find "_BS_PUSHLIKE" in any version of the Liberty BASIC Help File. I did finally find it used in "APIradiobuttons.bas" in Newsletter #101, "Button Stylebits" and "Stylebits - Toggle Buttons", both from the OLD Liberty BASIC Community Wiki. There was a reference to a post in "Liberty BASIC yahoo! message group. (See the original message #27196.)" that I have not followed up on yet. This shows that I have not read all the info that I have saved. Is there a complete list of ALL Stylebits available?
|
|
|
Post by Chris Iverson on Feb 3, 2019 0:35:29 GMT -5
It's not listed as part of LB because it's not an LB thing. STYLEBITS is a command for interfacing with Win32 window styles directly. The "bits" and the meanings of each code are defined by Windows itself. You can find definitions of window styles on MSDN, Microsoft's official documentation for Windows programming. It starts here, with the overview of Window styles that apply to EVERY window. docs.microsoft.com/en-us/windows/desktop/winmsg/window-styles. From there, each window class(like buttons, textbox, etc) has their own additional custom styles that apply only to that class. You can tell the difference by the prefix. WS_ is a general window style. BS_ is a button-class window style. WS_ styles can(generally) be used with any control(although, depending on what that control is, adding that style may not actually do anything.) However, you cannot use window styles defined for one specific class in another one. Adding BS_PUSHLIKE to random controls will at best do nothing, and at worst mess the control up, as it's possible for it to confuse the value of BS_PUSHLIKE with the value of one of it's own actual styles. To use a given window style in LB, just add another underscore(_) to the beginning of the name. LB has them defined with _ as a prefix to separate predefined system styles from user-made variables. (For example, the style name is BS_PUSHLIKE, as defined by Windows. To use it in LB, you use _BS_PUSHLIKE.) The values are often given for the various styles, as well. This is useful to LB, because sometimes, Microsoft will add new styles to controls, and until an update to LB is issued, those constants won't get added(and sometimes not then, I think it might depend on the lower-level tooling that LB is made on.). You can still use it by making your own variable with that value and passing it in to the STYLEBITS command. If you can't find a value for a given style on MSDN, it's often available by googling around. For example, BS_PUSHLIKE has a value of 4096. (Hex value 0x1000). You can make a variable to use the style, like this: style = 4096 stylebits #main.button, style, 0, 0, 0
|
|
|
Post by BeeTrap on Feb 3, 2019 8:55:22 GMT -5
Thank you for that explanation, it helped me more than you may know. I have been on the MSDN pages, but was never sure how that actually tied in with Liberty BASIC. Once again, thanks!
|
|
|
Post by tsh73 on Feb 3, 2019 16:36:58 GMT -5
I would grunt that Microsoft spoils good thing. Before I used to get 3d button, with visible depression then clicked. Now on Win10 I have flat buttons. I do not see depressed button (instead of selected radiobutton / checkbox). I just see same button but a bit different color (say pale blue instead of light gray). Not intuitive at all.
|
|
|
Post by Chris Iverson on Feb 4, 2019 0:06:44 GMT -5
I would grunt that Microsoft spoils good thing. Before I used to get 3d button, with visible depression then clicked. Now on Win10 I have flat buttons. I do not see depressed button (instead of selected radiobutton / checkbox). I just see same button but a bit different color (say pale blue instead of light gray). Not intuitive at all. Yeah, while there is a difference, it's a small one. Raymond Chen, one of the developers for the Windows shell, notes that the effect was ruined as far back as Windows XP, stating that:He notes on the same page that the PUSHLIKE style isn't actually used very much(indicated by the fact that he had to make that post in the first place). Try to think of a program you used recently(besides my little demo up there) that used them. He also notes a rather important UX detail on the same page: Basically, he's saying that making a checkbox or a radiobutton look like an ordinary pushbutton can be confusing to end users, due to it causing a button to not behave how one expects a button to behave. If you want something that has the behavior of a checkbox or a radiobutton, his suggestion is to just use one of those, with the history of Windows UX making it clear what each is supposed to do. Making a control look like one type of control, but behave like a completely different one can very much cause issues for inexperienced end-users. At this point, I'm pretty sure this is one of those things that, if they were remaking Windows from scratch, they'd just leave out completely, and that the only reason it's still there is backwards compatibility.
|
|