Restored from previous forum. Originally posted by TerryHough.
I have a Button gadget with attached action code that works
perfectly.
As a result of other activities, I need to accomplish the
exact same actions when a condition is met. Is it possible
to simulate (or force) the Button selection event?
Thanks,
Terry
How to force a gadget action?
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by fweil.
LO,
... depends on what your program does ! For example you can imagine to have any remote or local possibility to set a variable in your app so that it will execute the same code.
Do you want exactly to find a way to "push the gadget" by software or only to have another way to execute the same code as it does when pushing it ?
Maybe you can give more details about your need.
As I understand your question at the moment, you just should set a variable enabling the same code section or procedure.
Rgrds
Francois Weil
14, rue Douer
F64100 Bayonne
LO,
... depends on what your program does ! For example you can imagine to have any remote or local possibility to set a variable in your app so that it will execute the same code.
Do you want exactly to find a way to "push the gadget" by software or only to have another way to execute the same code as it does when pushing it ?
Maybe you can give more details about your need.
As I understand your question at the moment, you just should set a variable enabling the same code section or procedure.
Rgrds
Francois Weil
14, rue Douer
F64100 Bayonne
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by TerryHough.
Hello Francois,
What I wanted to do was "push the gadget".
For some reason, when I put the code into a procedure and then
just call it based on the conditions met, I do not get the proper
results.
Probably has something to do with local versus global variables,
which I don't complete have in my mind.
I will study it a bit more and see if I can resolve my situation.
But it still would be nice to know how to "push the gadget" for
future reference.
Thanks for your response
Terry
Hello Francois,
What I wanted to do was "push the gadget".
For some reason, when I put the code into a procedure and then
just call it based on the conditions met, I do not get the proper
results.
Probably has something to do with local versus global variables,
which I don't complete have in my mind.
I will study it a bit more and see if I can resolve my situation.
But it still would be nice to know how to "push the gadget" for
future reference.
Thanks for your response
Terry
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by freak.
> What I wanted to do was "push the gadget".
Hi,
I think, this one does what you want. (tested with Win98SE and WinXP)
That's it, hope it helps...
Timo
> What I wanted to do was "push the gadget".
Hi,
I think, this one does what you want. (tested with Win98SE and WinXP)
Code: Select all
; Simulates a Click on a specific button
Procedure PushButton(gadget.l)
handle.l = GadgetID(gadget)
SendMessage_(handle, #WM_LBUTTONDOWN, #MK_LBUTTON, 0)
SendMessage_(handle, #WM_LBUTTONUP, #MK_LBUTTON, 0)
EndProcedure
; short Example:
OpenWindow(0, 0, 0, 100, 100, #PB_Window_SystemMenu, "Test")
CreateGadgetList(WindowID())
ButtonGadget(1, 10, 20, 80, 20, "Button 1")
ButtonGadget(2, 10, 60, 80, 20, "Press Button 1")
Repeat
Event = WaitWindowEvent()
If Event = #PB_EventGadget
Select EventGadgetID()
Case 1: MessageRequester("TEST","'Button 1' has been pushed!", 0)
Case 2: PushButton(1)
EndSelect
EndIf
Until Event = #PB_EventCloseWindow
End
Timo
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
> What I wanted to do was "push the gadget".
Do you mean something like the below? Even if you do, there are better
and proper ways to do what you want... you shouldn't do a "fake" push
like this just to run the code that belongs to the pushed gadget.
PB - Registered PureBasic Coder
> What I wanted to do was "push the gadget".
Do you mean something like the below? Even if you do, there are better
and proper ways to do what you want... you shouldn't do a "fake" push
like this just to run the code that belongs to the pushed gadget.
Code: Select all
If OpenWindow(0,100,150,450,200,#PB_Window_SystemMenu,"Test")
CreateGadgetList(WindowID())
b1=ButtonGadget(2,200,100,140,25,"(1) Click me...")
b2=ButtonGadget(3,200,150,140,25,"(2) ...and I will be pushed!")
Repeat
ev=WaitWindowEvent()
If ev=#PB_EventGadget
Select EventGadgetID()
Case 2
SendMessage_(b2,#WM_LBUTTONDOWN,0,0)
SendMessage_(b2,#WM_LBUTTONUP,0,0)
Case 3
MessageRequester("Button 2","Pushed!",0)
EndSelect
EndIf
Until ev=#PB_EventCloseWindow
EndIf
PB - Registered PureBasic Coder
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
> I think, this one does what you want.
Wow, Freak -- check out our posting times! We posted the exact same
code example within the same minute of each other!
Your post: 29 Aug 2002, 21:48:03
My post: 29 Aug 2002, 21:48:58
PB - Registered PureBasic Coder
> I think, this one does what you want.
Wow, Freak -- check out our posting times! We posted the exact same
code example within the same minute of each other!
Your post: 29 Aug 2002, 21:48:03
My post: 29 Aug 2002, 21:48:58
PB - Registered PureBasic Coder
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
> PB, you are right. There probably are better ways. At least,
> certainly more elegant solutions.
Well, in case you don't know, your gadget click routines should call
a procedure to do the work. So, in my example above, you would put
the MessageRequester code for button 2 in a procedure. Then, to
simulate "pushing the button" you just call the procedure for that
button, without actually pushing the button.
Know what I mean? I don't mean to sound condescending but I don't
know how much you know about programming...
PB - Registered PureBasic Coder
> PB, you are right. There probably are better ways. At least,
> certainly more elegant solutions.
Well, in case you don't know, your gadget click routines should call
a procedure to do the work. So, in my example above, you would put
the MessageRequester code for button 2 in a procedure. Then, to
simulate "pushing the button" you just call the procedure for that
button, without actually pushing the button.
Know what I mean? I don't mean to sound condescending but I don't
know how much you know about programming...
PB - Registered PureBasic Coder