How to create pushed toggle button?

Just starting out? Need help? Post your questions and find answers here.
Michael Korolev
User
User
Posts: 53
Joined: Wed Nov 01, 2006 3:02 pm
Location: Russia/Krasnoyarsk
Contact:

How to create pushed toggle button?

Post by Michael Korolev »

How I can create PUSHED toggle button?

I want to create this: my program launches and reads settings - and in one case someone toggle button is pushed, in another case it's released...

I can't find ANY info about ButtonGadgets commands in PureBasic Help... are they supported?

Please, use simple english. My english is too far from perfect. :)
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Win Api:

Code: Select all

SendMessage_(GadgetID(#togglebutton), #BM_CLICK, 0, 0)
For example,

Code: Select all

 If OpenWindow(0, 0, 0, 222, 200, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
    ButtonGadget(4, 10,10, 80, 40, "Toggle", #PB_Button_Toggle)
    SendMessage_(GadgetID(4), #BM_CLICK, 0, 0)
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
I may look like a mule, but I'm not a complete ass.
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

In Windows a checkbox can have a button appearance, wich toggles the way you want :)

The above is only a poor substitute :)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8433
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Apply this flag: #PB_Button_Toggle

The help file has a "Gadget" link, on which you can find detailed help on all the individual gadgets. The buttongadget help has a demo program showing this flag in action, along with some others.

srod, I don't think you've ever beaten me before... :twisted:
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I'm sure I have somewhere along the line! :D
I may look like a mule, but I'm not a complete ass.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1252
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

For new comers it's probably best to use as much native PB commands as possible since that is what the help file refers to.

Example... instead of API:
SendMessage_(GadgetID(4), #BM_CLICK, 0, 0)

use:
SetGadgetState(4,1)
Image Image
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Bugger me, I didn't know you could do that! :)

I looked in the help manual for exactly that, didn't see it and thus didn't try it!

An omission from the help manual methinks!

Mind you, it equates to a check box anyhow and so should have been obvious! :oops:
I may look like a mule, but I'm not a complete ass.
Michael Korolev
User
User
Posts: 53
Joined: Wed Nov 01, 2006 3:02 pm
Location: Russia/Krasnoyarsk
Contact:

Post by Michael Korolev »

Thanks Paul! :)

I suggested that SetGadgetState doesn't work with ButtonGadget, because no "ButtonGadget" was in SetGadgetState supported gadgets list. But it works!

WinAPI command will be useful too :) Thanks to all!
localmotion34
Enthusiast
Enthusiast
Posts: 665
Joined: Fri Sep 12, 2003 10:40 pm
Location: Tallahassee, Florida

Post by localmotion34 »

SendMessage_(GadgetID(#togglebutton), #BM_SETCHECK, 0, state)

Code: Select all

!.WHILE status != dwPassedOut
! Invoke AllocateDrink, dwBeerAmount
!MOV Mug, Beer
!Invoke Drink, Mug, dwBeerAmount
!.endw
Edwin Knoppert
Addict
Addict
Posts: 1073
Joined: Fri Apr 25, 2003 11:13 pm
Location: Netherlands
Contact:

Post by Edwin Knoppert »

Wow, billy messed it up for checkboxes having the 'pushlike' style(#PB_Button_Toggle) when the app is XP themed.

On click the effect is the same as for an ordinary button, the released state.
You'll have to remove the mouse from the button area.
Then it shows itself pressed again.

A bit poor.
mestnyi
Addict
Addict
Posts: 1001
Joined: Mon Nov 25, 2013 6:41 am

Re: How to create pushed toggle button?

Post by mestnyi »

How I can create PUSHED toggle button?
I know that the purebasic has a flag #PB_Button_Toggle, but I would like to receive it by api.
can you help?
User avatar
mk-soft
Always Here
Always Here
Posts: 5409
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: How to create pushed toggle button?

Post by mk-soft »

Why?
Is native for all OS

Code: Select all

SendMessage_(GadgetID(4), #BM_GETCHECK, 0, 0)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
mestnyi
Addict
Addict
Posts: 1001
Joined: Mon Nov 25, 2013 6:41 am

Re: How to create pushed toggle button?

Post by mestnyi »

I meant this. :D
I know that purebasic has the flag #PB_Button_Toggle, but I would like to get the same result with winapi.
you can help?

SetWindowLongPtr_(handle, #GWL_STYLE, GetWindowLongPtr_(handle, #GWL_STYLE)|#BS_PUSHLIKE|#BS_CHECKBOX)
Post Reply