next problem, send a click to a button

Windows specific forum
User avatar
wichtel
User
User
Posts: 71
Joined: Fri May 02, 2003 11:14 am
Location: Germany
Contact:

next problem, send a click to a button

Post 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?
PB 5.40 LTS, W7,8,10 64bit and Mint x64
User avatar
Michael Vogel
Addict
Addict
Posts: 2821
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: next problem, send a click to a button

Post 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...
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4997
Joined: Sun Apr 12, 2009 6:27 am

Re: next problem, send a click to a button

Post 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
Egypt my love
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: next problem, send a click to a button

Post by ts-soft »

simple use postmessage

greetings
Thomas
User avatar
wichtel
User
User
Posts: 71
Joined: Fri May 02, 2003 11:14 am
Location: Germany
Contact:

Re: next problem, send a click to a button

Post 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. :?
PB 5.40 LTS, W7,8,10 64bit and Mint x64
Post Reply