Page 1 of 1
next problem, send a click to a button
Posted: Tue Jul 27, 2010 7:58 pm
by wichtel
This used to work to simulate a click onto a button.
Code: Select all
Procedure Oclick(id.l)
gid.l=GadgetID(id)
If IsWindowEnabled_(gid)
SendMessage_(gid,#WM_LBUTTONDOWN,0,0)
SendMessage_(gid,#WM_LBUTTONUP,0,0)
EndIf
EndProcedure
In 4.50 it does no longer work.
The button gets selected, but not clicked.
What has changed?
Re: next problem, send a click to a button
Posted: Tue Jul 27, 2010 8:27 pm
by Michael Vogel
I am using a code like this...
Code: Select all
Procedure Oclick(win,gadget)
win=WindowID(win)
#PB_Shortcut_SrodFlag=1<<16
PostMessage_(win,#WM_COMMAND,#PB_Shortcut_SrodFlag|gadget,0)
EndProcedure
OpenWindow(0, 0, 0, 222, 200, "ButtonGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 200, 20, "Standard Button")
ButtonGadget(1, 10, 40, 200, 20, "STARTS ANOTHER EVENT", #PB_Button_Left)
ButtonGadget(2, 10, 70, 200, 20, "Right Button", #PB_Button_Right)
ButtonGadget(3, 10,100, 200, 60, "Multiline Button (längerer Text wird automatisch umgebrochen)", #PB_Button_MultiLine)
ButtonGadget(4, 10,170, 200, 20, "Toggle Button", #PB_Button_Toggle)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget,#PB_Event_Menu
gadget=EventGadget()
Debug gadget
If gadget=1
Oclick(0,3)
EndIf
EndSelect
ForEver
BTW, the code lines for creating the gadgets are from the help file – the multiline button does not show the second line here, seems to be an issue I never saw before...
Re: next problem, send a click to a button
Posted: Tue Jul 27, 2010 9:09 pm
by RASHAD
@wichtel Hi
Try the next
Code: Select all
Procedure Oclick(id.l)
GetCursorPos_(cp.POINT)
GetWindowRect_(GadgetID(id),r.RECT)
SetCursorPos_((r\left+5),(r\top+5))
mouse_event_(#MOUSEEVENTF_LEFTDOWN,0,0,0,0)
mouse_event_(#MOUSEEVENTF_LEFTUP,0,0,0,0)
SetCursorPos_(cp\x,cp\y)
EndProcedure
Re: next problem, send a click to a button
Posted: Tue Jul 27, 2010 9:15 pm
by ts-soft
simple use postmessage
greetings
Thomas
Re: next problem, send a click to a button
Posted: Wed Jul 28, 2010 8:58 am
by wichtel
Thanks everybody.
@Michael Vogel:
Your code works. I did not know about that call. But it leaves the focus on the button 1 even so button 3 is "clicked" afterwards. So it can be used to "click" something without showing.
Btw, the multiline button shows both lines on my system (W7 64bit, running 32bit PB)
@Rashad:
Your code works as well, and leaves the focus on the "clicked" button.
It really moves the mouse, so it might become handy for another thing I need to do.
@Thomas:
Your hint seems to do exactly what my code did before, so I am using this now:
Code: Select all
Procedure Oclick(id.l)
gid.l=GadgetID(id)
If IsWindowEnabled_(gid)
PostMessage_(gid,#WM_LBUTTONDOWN,0,0)
PostMessage_(gid,#WM_LBUTTONUP,0,0)
EndIf
EndProcedure
Could somebody explain why sendmessage worked in the past and now does no longer work with 4.50?
Sorry folks, I did not work with PB for a longer period of time and now have to make some additions to older code and stumble about things that "suddenly" stopped working.
