Link to home
Start Free TrialLog in
Avatar of mrpinko
mrpinko

asked on

Finding the screen position of a system tray icon

hi gurus,

i have a system tray icon and would like to display a window at or around it. Is there any way i can get the location or dimensions of my tray icon?

thanks,
Gavin
Avatar of vbk_bgm
vbk_bgm

Hi,
The sys tray is a child window of the task bar. Hence you can obtain the rect in the foll way.
HWND hWndTask = FindWindow(_T("Shell_TrayWnd"), _T(""));
HWND hWndTray = NULL;
RECT rect;
for(HWND hWnd = GetWindow(hWndTask,GW_CHILD); hWnd != NULL; hWnd = GetWindow(hWnd,GW_HWNDNEXT))
    {
         TCHAR ClassName[MAX_PATH];
         if (GetClassName(hWnd,ClassName,MAX_PATH))
         {
              if (0 == lstrcmp(_T  ("TrayNotifyWnd"),ClassName))
              {
                   hWndTray = hWnd;
                   break;
              }
         }
    }
   
//get the rect in screen coordinates    
GetWindowRect(hWndTray,&rect);
ASKER CERTIFIED SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial