Click here to Skip to main content
16,022,413 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I'm trying to convert a struct I have defined to match the NOTIFYICONDATA in C++(I think I have it right) and I am trying to convert this into a NotifyIcon object in C#. First I am receiving the SHELLTRAYDATA that an application sends with Shell_NotifyIcon. My SHELLTRAYDATA was defined as such:
C++
public struct NID_XX
{
    public UInt32 cbSize;
    public IntPtr hWnd;
    public uint uID;
    public uint uFlags;
    public uint uCallbackMessage;
    public IntPtr hIcon;
}
public struct PSHELLTRAYDATA
{
    public UInt32 dwUnknown;
    public UInt32 dwMessage;
    public NID_XX nid;
}

Now from my understanding NID_XX is equivalent to NOTIFYICONDATA but I can't seem to find out how to convert this into a NotifyIcon. I am working mostly in C# but I do have a C++ DLL I am using to receive this data, so if something else needs to be done in C++ that won't be an issue.
Posted
Updated 14-Dec-10 18:35pm
v2
Comments
Radhakrishnan G. 15-Dec-10 0:01am    
You can use .NET TrayIcon control

1 solution

use DllImport attribute to call the Shell_NotifyIcon() API, and marshal the patameter to CLR type

check this link Platform Invoke Data Types[^]
C#
// BOOL Shell_NotifyIcon(
//  __in  DWORD dwMessage,
//  __in  PNOTIFYICONDATA lpdata
//);
[DllImport("Shell32.dll", CharSet = CharSet.Unicode)]
public static extern Int32 Shell_NotifyIcon(UInt32 message, ref NotifyIconData iconData);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900