locating a notify icon

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

I'm writing an application that sits in the system tray and will display notification "bubble-style" popups. I want the notification popup to eminate from the icon (this must work regardless of where the taskbar is docked). I haven't been able to find an API to discover the exact position of my icon in the system tray. I create the NotifyIcon instance and it magically appears in the system tray so I'm not sure where to begin looking for this.

Any help would be appreciated.

Thanks,
Ben
 
* =?Utf-8?B?QmVu?= said:
I'm writing an application that sits in the system tray and will display notification "bubble-style" popups. I want the notification popup to eminate from the icon (this must work regardless of where the taskbar is docked). I haven't been able to find an API to discover the exact position of my icon in the system tray. I create the NotifyIcon instance and it magically appears in the system tray so I'm not sure where to begin looking for this.

<http://vbaccelerator.com/article.asp?id=4304>
 
I am trying to show a custom form as a notification balloon (not the standard yellow one with just plain text). This must work on windows 98 and above (sorry I should have mentioned this in my original post). Looking at the code from the link above it appears that there is no ability to change the balloon window, and it also appears only to work on ME and above.

I have the form all ready to go; I just need to know the coordinates to anchor it at.

Ben
 
Hi Ben,

Thanks for choosing MSDN Newsgroup!
My name is Ying Shen Yu, I'll be assist you on this issue.

From your description, my understanding to your question now is you
application shows an notify icon in the tray area, when the program popup
some info, you'd like to pop up a customized form instead of the ballon tip
and set the position just beside the notify icon.

Based on my research, there is no official APIs to get exact location of
the notify icon. However, you can get the position of the "notification
area" window instead by P/Invoke.
Then maybe we can show the customize window beside the notification area
as a workaround.

Through Spy++, we can see the caption of the tray icon area is
"Notification Area".
So we may use API FindWindow to get the window handle, then API
GetWindowRect should give you postion of the window in screen coordinates.
Here is a simple sample snippet just to clarify my idea:
<code>
[DllImport("user32.dll")]
public extern static IntPtr FindWindowEx(IntPtr parentWnd, IntPtr
childAfter, string lpClassName,string lpWindowName);
[DllImport("user32.dll")]
public extern static int GetWindowRect(IntPtr hWnd,out Rect lpRect);

private void button1_Click(object sender, System.EventArgs e)
{
Rect rc;
IntPtr hwnd = FindWindowEx(IntPtr.Zero,IntPtr.Zero,"Shell_TrayWnd",null);
hwnd = FindWindowEx(hwnd , IntPtr.Zero ,"TrayNotifyWnd",null);
hwnd = FindWindowEx(hwnd , IntPtr.Zero ,"SysPager",null);
if (hwnd != IntPtr.Zero)
{
hwnd = FindWindowEx(hwnd , IntPtr.Zero ,null,"Notification Area");
if (hwnd != IntPtr.Zero)
{
if ( GetWindowRect(hwnd,out rc) != 0)
{

System.Console.WriteLine(rc);
}
}
}
}

[StructLayout(LayoutKind.Sequential)]
public struct Rect
{
public int left;
public int top;
public int right;
public int bottom;
public override string ToString()
{
return "Left: " + left.ToString() + " Top: " +
top.ToString() + " Right: " + right.ToString() + "Bottom: " +
bottom.ToString();
}

}
</code>

If you have any further question on this issue, please feel free to reply
this thread.
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, "online" should be removed before
sending.
 
Back
Top