.NET Framework 1.0/1.1中给我们提供了一个NotifyIcon类,使用这个类我们可以非常方便的实现系统托盘(SystemTray)图标。可是不知道微软是为了
兼容性还是为了
偷懒,只实现了
NOTIFYICONDATA结构的v5.0之前版本,也就是说不支持5.0及以后的balloon tip功能
。
Shell struct v5.0 and later中的NOTIFYICONDATA结构定义为:
而微软Framework 1.0/1.1中实现的NOTIFYICONDATA是:
Shell struct v5.0 and later中的NOTIFYICONDATA结构定义为:
typedef
struct _NOTIFYICONDATA {
DWORD cbSize;
HWND hWnd;
UINT uID;
UINT uFlags;
UINT uCallbackMessage;
HICON hIcon;
TCHAR szTip[64];
DWORD dwState;
DWORD dwStateMask;
TCHAR szInfo[256];
union {
UINT uTimeout;
UINT uVersion;
};
TCHAR szInfoTitle[64];
DWORD dwInfoFlags;
GUID guidItem;
} NOTIFYICONDATA, *PNOTIFYICONDATA;
DWORD cbSize;
HWND hWnd;
UINT uID;
UINT uFlags;
UINT uCallbackMessage;
HICON hIcon;
TCHAR szTip[64];
DWORD dwState;
DWORD dwStateMask;
TCHAR szInfo[256];
union {
UINT uTimeout;
UINT uVersion;
};
TCHAR szInfoTitle[64];
DWORD dwInfoFlags;
GUID guidItem;
} NOTIFYICONDATA, *PNOTIFYICONDATA;
而微软Framework 1.0/1.1中实现的NOTIFYICONDATA是:
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto, Pack=1)]
public class NOTIFYICONDATA
{
public int cbSize;
public IntPtr hWnd;
public int uID;
public int uFlags;
public int uCallbackMessage;
public IntPtr hIcon;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=0x40)]
public string szTip;
public NOTIFYICONDATA()
{
this.cbSize = Marshal.SizeOf( typeof(NativeMethods.NOTIFYICONDATA));
}
}
public class NOTIFYICONDATA
{
public int cbSize;
public IntPtr hWnd;
public int uID;
public int uFlags;
public int uCallbackMessage;
public IntPtr hIcon;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=0x40)]
public string szTip;
public NOTIFYICONDATA()
{
this.cbSize = Marshal.SizeOf( typeof(NativeMethods.NOTIFYICONDATA));
}
}
不过稍微感到欣慰的是在Framework 2.0中,NotifyIcon支持了v5.0以后的Balloon Tip功能。
本文转自博客园鸟食轩的博客,原文链接:http://www.cnblogs.com/birdshome/,如需转载请自行联系原博主。