May 11, 2024, 10:27:58 AM

News:

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


Emulate control press?

Started by JoaoAfonso, November 01, 2009, 08:12:54 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JoaoAfonso

Good evening.
Thought I would see this in other posts, but couldn't find it: how can I emulate a button press?

Thanks in advance.

SUB dhandler1
INT state=1
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
CASE @IDCLOSEWINDOW
CLOSEDIALOG d1,@IDOK
CASE @IDCONTROL
SELECT @CONTROLID
(...)
CASE 1
SELECT state
CASE 0
*emulate button 7*
CASE 1
MESSAGEBOX 0,"First state","test"
state=2
CASE 2
MESSAGEBOX 0,"Second state","test"
state=0
ENDSELECT
CASE 7:'requisitar
MESSAGEBOX 0,"Emulated button 7 press","test"
(...)

JoÃÆ'ƒÂÃ,£o Afonso
Viriato
-----------------
Iberia MUD
www.iberiamud.com
iberiamud.com:5900

Bruce Peaslee

I think one way to do it is to jump to the rojutine that would be called by the button press, rather than send a "press button" message.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles


JoaoAfonso

Peaslee, that is an easy solution indeed, but anyway, as a challenge, I would like to make it as button 7 calling the routine, and button 1 emulates pressing button control 7.
Ficko, I believe I would ask for help in the near future about that function :) Anyway, I am not after emulate press a key from keyboard, but a button from my dialog... I believe that with a sendmessage, to my dialog, can make it work, but just don't know the arguments.
Thanks for the answers, both helped me and solved my code problem. But as we are talking about it, I would be glad to know if with sendmessage I could emulate! (ah, and eventually if I can emulate a control button press via sendmessage, I surely can do the same for emulate a key press from keyboard)
Thanks!
JoÃÆ'ƒÂÃ,£o Afonso
Viriato
-----------------
Iberia MUD
www.iberiamud.com
iberiamud.com:5900

zaphod

I dont know if this is what you search ...
For simulate a button click :

Const bm_click=0xF5
Sendmessage(windowid,bm_click,0,0,buttonid)

And windows api :
for keyboard : keybd_event
for mouse : mouse_event

sapero

If the button is in a dialog box and the dialog box is not active, the BM_CLICK message might fail. If you send a valid WM_COMMAND (0x111) message, it will not fail:
SendMessage d1, 0x0111, controlID | (notifycode<<16), GetControlHandle(d1, controlID)
For just a click, notifycode is zero (BN_CLICKED), so put only controlID as the third parameter:
SendMessage d1, 0x0111, controlID, GetControlHandle(d1, controlID)
When you put zero instead GetControlHandle, you will simulate a menu item:
SendMessage d1, 0x0111, menuID, 0
To simulate an accelerator, simulate menu with notifycode set to 1 (one):
SendMessage d1, 0x0111, menuID | 65536, 0

JoaoAfonso

explendid! thank you all for the answers!
JoÃÆ'ƒÂÃ,£o Afonso
Viriato
-----------------
Iberia MUD
www.iberiamud.com
iberiamud.com:5900