June 18, 2024, 08:45:17 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Set and hold a button pressed

Started by r.budras, October 19, 2017, 04:59:23 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

r.budras

Hi All

Is there a possibility to set and hold a button pressed by code,
just like the setstate command for checkboxes or radiobuttons ?

Looking forward to hear from You

Reinhard


Andy

Hi Reinhard,

Firstly, it's nice to see someone new here, so welcome Reinhard!

Now, can you clarify the question:

Do you want a button to look like it has been pressed OR do you want to repeat something as if the button was pressed?

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

r.budras

Hi Andy
Thanks for Your quick respond
I want a button to look like it has been ans is pressed.

Andy

To make a button look like it has been pressed is quite easy.

In a window, before you say:

WAITUNTIL d1 = 0    '(where d1 in this case is the window)

Do this.....

setfocus d1,button_7    '(set the focus to the button you want to look like it has been pressed).
WAITUNTIL d1 = 0
END

Let me have a think on the other issue...
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Andy

October 19, 2017, 06:30:14 AM #4 Last Edit: October 19, 2017, 06:31:56 AM by Andy
You could do this:

Between

setfocus d1,button_7 AND
WAITUNTIL d1 = 0

you could:

setfocus d1,button_7

GOSUB DoThis()   'or just leave out GOSUB that it...  DoThis()
GOSUB DoThat()
GOSUB DoTheOther()

WAITUNTIL d1 = 0
END

So the button will look like it has been pressed, you can do what you want it to as if the user pressed the button.

If you want to go a little further you could then set the focus back to the whole window, like this...

setfocus d1,button_7

DoThis() 
DoThat()
DoTheOther()

SETFOCUS d1
WAITUNTIL d1 = 0
END

Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

r.budras


fasecero

There's another way to do it but it requires a bit of work.


$INCLUDE "windowssdk.inc"

' flag variable
INT someOption = 1 ' 1 yes, 0 no

' interface
CONST BUTTON_1 = 1
CONST BUTTON_2 = 2
WINDOW w1
OPENWINDOW w1,0,0,244,250,@CAPTION,0,"Select an option",&mainhandler
CENTERWINDOW w1

' message loop
WAITUNTIL ISWINDOWCLOSED(w1)

' procedure
SUB mainhandler(), INT
BOOL checked = 0

SELECT @MESSAGE
CASE @IDCREATE
ButtonCheckCreate(w1, BUTTON_1, 60, 40, 120, 40, "Yes")
ButtonCheck(w1, BUTTON_1, 1)
ButtonCheckCreate(w1, BUTTON_2, 60, 120, 120, 40, "No")
ButtonCheck(w1, BUTTON_2, 0)
CASE @IDCLOSEWINDOW
CLOSEWINDOW w1
CASE @IDCONTROL
SELECT @CONTROLID
CASE BUTTON_1
IF @NOTIFYCODE = 0
/*button clicked*/
someOption = 1
updateButtons(someOption)
ENDIF
CASE BUTTON_2
IF @NOTIFYCODE = 0
/*button clicked*/
someOption = 0
updateButtons(someOption)
ENDIF
ENDSELECT
ENDSELECT
RETURN 0
ENDSUB

SUB updateButtons(INT option)
ButtonCheck(w1, BUTTON_1, option = 1)
ButtonCheck(w1, BUTTON_2, option = 0)
ENDSUB

SUB ButtonCheckCreate(window w, INT ctrlID, INT x, INT y, INT width, INT height, string text)
INT dwStyles = WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX | BS_PUSHLIKE
INT hwnd = CreateWindowEx(0, "BUTTON", text, dwStyles, x, y, width, height, w.hwnd, ctrlID, GetModuleHandle(0), NULL)
_SendMessage(hwnd, WM_CHANGEUISTATE, MAKELONG(UIS_SET, UISF_HIDEFOCUS), 0) ' remove focus rectangle
ENDSUB

SUB ButtonCheck(window w, INT ctrlID, BOOL check)
CheckDlgButton(w.hwnd, ctrlID, check)
ENDSUB

SUB ButtonIsChecked(window w, INT ctrlID), INT
RETURN IsDlgButtonChecked(w.hwnd, ctrlID)
ENDSUB


r.budras

Whow, that looks great.
I will try this until tomorrow.

Thank You all for Your support

LarryMc

I don't know if there's any way my Push-Button Library might help you but you may want to have a look see just in case

http://www.ionicwind.com/forums/index.php?topic=2269.msg19737#msg19737

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

r.budras

Thank You, LarryMc :)
I hope to see all my great helpers on Oktoberfest Munich in 2018 ;)