RectangleEquals
RectangleEquals

Reputation: 1825

Finding and simulating a click on a system tray icon?

I need to figure out how to programmatically find and select a context menu item from a separate application's system tray icon. The only way I could imagine accomplishing this was to use mouse_event() with some hard-coded x/y values, and set the icon to always be shown. Aside from the hacky use of hard-coding in general, the problem here is the assumption that the icon will retain it's position (which is likely to break any time another application loads/unloads). I was wondering if anybody knew any other way to go about this?

Upvotes: 5

Views: 6858

Answers (2)

Mark Hall
Mark Hall

Reputation: 54532

See this MSDN Forum article which discusses how to find the systemTray's Handle. The article then references a CodeProject Article on how to find the handle of the application you are searching for. I have not tried this but it looks like it might be a viable starting point.

Upvotes: 2

Jonathan Potter
Jonathan Potter

Reputation: 37122

Depending on how the application has been written, selecting the item from the context menu will cause a WM_COMMAND message to be posted to a window belonging to the application. You can use a tool like Spy++ to check for this. If this is the case then all you would have to do (in theory) is simulate that message.

If the application does not use WM_COMMAND to receive selections from the context menu, your job is much harder. There is no documented method of discovering the position and identify of system tray items, and so your method of hard-coding the x/y values is probably the best option you have.

Upvotes: 4

Related Questions