/// <summary> /// 获取托盘图标的坐标 /// </summary> public static Rectangle GetIconRect(NotifyIcon icon) { RECT rect = new RECT(); NOTIFYICONIDENTIFIER notifyIcon = new NOTIFYICONIDENTIFIER(); notifyIcon.cbSize = Marshal.SizeOf(notifyIcon); //use hWnd and id of NotifyIcon instead of guid is needed notifyIcon.hWnd = GetHandle(icon); notifyIcon.uID = GetId(icon); int hresult = Shell_NotifyIconGetRect(ref notifyIcon, out rect); //rect now has the position and size of icon return(new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top)); }
private static extern int Shell_NotifyIconGetRect([In] ref NOTIFYICONIDENTIFIER identifier, [Out] out RECT iconLocation);