Menu events between threads

Just starting out? Need help? Post your questions and find answers here.
Olby
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Jan 12, 2009 10:33 am
Contact:

Menu events between threads

Post by Olby »

Hi, I'm having a hard time figuring out how to send menu events from auxiliary to the main thread for processing.

I use PostMessage_ at the moment:

Code: Select all

PostMessage_(WindowID(#Main),#PB_Event_Menu,-1,GetMenuItemID_(MenuID(#Menu_Main_Dummy),#Menu_Jobs_Dummy))
but the problem is that GetMenuItemID_ doesn't return proper item id and triggers wrong menu item - I guess due to the fact that target item was created in the main thread (and not auxiliary one).

Any ideas on how to get the right item id's? Thanks.
Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Menu events between threads

Post by c4s »

I'm not sure if that is what you need, however I'm using the following code to simulate menu events (on Windows):

Code: Select all

Macro WindowEventMenuSimulate(WindowNr, MenuItemID)
	PostMessage_(WindowID(WindowNr), #WM_COMMAND, MenuItemID | (1 << 16), 0)
EndMacro


; For the sake of completeness, simulating Gadget events:
Macro WindowEventGadgetSimulate(WindowNr, GadgetNr, EventType)
	PostMessage_(WindowID(WindowNr), #WM_COMMAND, GadgetNr | (EventType << 16), GadgetID(GadgetNr))
EndMacro

; There is also an internal PB function for this, but you never know if it will change so I'm always using the previous one:
Import ""
	PB_Gadget_SendGadgetCommand(hWnd, EventType)
EndImport
PB_Gadget_SendGadgetCommand(GadgetID(GadgetNr), EventType)
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Re: Menu events between threads

Post by tinman »

c4s wrote:

Code: Select all

; There is also an internal PB function for this, but you never know if it will change so I'm always using the previous one:
Import ""
	PB_Gadget_SendGadgetCommand(hWnd, EventType)
EndImport
djes reported here http://www.purebasic.fr/english/viewtop ... 78#p357378 that PB_Gadget_SendGadgetCommand does not work when using the threadsafe option, so as you say safer to stick with PostMessage_().
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Menu events between threads

Post by c4s »

@tinman
Thanks for the information! I just knew it. :wink:
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Olby
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Jan 12, 2009 10:33 am
Contact:

Re: Menu events between threads

Post by Olby »

@c4s
Yeah it did the trick. Thank you guys!
Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)
Post Reply