I am trying to figure out a way of retrieving/enumerating menu items that pops up from one of my application system tray icons when I right click on it, and seeing which menu item is checked.
So far what I've done...
I've used Winspector to find that the tray icon itself for the application does not have its own window class, so I retrieved its handle through the "ToolbarWindow32" class, by getting a handle on the tray process, getting a count of the "Button"s inside the tray, and iterating through each one to find the application that I am trying to access.
for(int iButton=0; iButton<iButtonsCount; iButton++)
{
DWORD dwBytesRead = -1;
TBBUTTON buttonData;
SendMessage(hWndTray, TB_GETBUTTON, iButton, (LPARAM)lpData);
ReadProcessMemory(hTrayProc, lpData, &buttonData,
sizeof(TBBUTTON), &dwBytesRead);
DWORD dwExtraData[2] = { 0,0 };
ReadProcessMemory(hTrayProc, (LPVOID)buttonData.dwData,
dwExtraData, sizeof(dwExtraData), &dwBytesRead);
HWND hWndOfIconOwner = (HWND) dwExtraData[0];
int iIconId = (int) dwExtraData[1];
if( !(buttonData.fsState & TBSTATE_HIDDEN) )
{
HMENU hMenu = GetMenu(hWndOfIconOwner);
}
}
If you take a look at the last if statement, I check whether the current icon is showing, and if it is it gets the handle to the menu. I'm not too sure whether doing GetMenu is actually getting the handle of the same menu as when I right click on it.
Basically, if I right click on the icon, it pops up a menu, and there is a menu item with a submenu with a list of items which can be checked. All I want to do see which ones is checked.
Thanks for any response in advance.
noit