Hallo Leute,
versuche gerade verzweifelt bei einem Compact Framework 1.1 Projekt ein NotifyIcon in der Taskbar zu erzeugen. Habe hierzu die API Methode Shell_NotifyIcon() gefunden aber leider komme ich damit nicht zurecht.
Mein bisheriger Code:
[DllImport("coredll.dll")]
internal static extern int Shell_NotifyIcon(int dwMessage, ref NOTIFYICONDATA pnid);
struct NOTIFYICONDATA
{
int cbSize;
IntPtr hWnd;
int uID;
int uFlags;
int uCallbackMessage;
IntPtr hIcon;
char mychar;
}
Tja und hier fängt nun mein Problem an, wie kann ich denn dies nun in C# realisieren? Kennt jemand eine Seite wo man ein Beispiel findet, habe leider nichts gefunden 🙁
Vielen Dank für die Hilfe
Andi
Hallo ich hab es jetzt ein bisschen was gefunden was eigentlich funktionieren sollte aber leider wird das TrayIcon nicht angezeigt weiss jemand warum?
// Extract icon from the application's exe
// This requires that app icon were set in the project properties
string szPath = Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName;
ExtractIconEx(szPath, 0, 0, ref hIcon, 1);
// Fill NOTIFYICONDATA with data
NOTIFYICONDATA nid = new NOTIFYICONDATA();
// In our struct definition we have omitted emebedded wchar array size 64 - we need to account for it
int cbSize = Marshal.SizeOf(nid) + 64 * Marshal.SystemDefaultCharSize;
// Allocate memory
IntPtr pData = LocalAlloc(LPTR, cbSize);
// Set fields of the NOTIFYICONDATA (see SDK documentation)
nid.cbSize = cbSize;
nid.hIcon = hIcon;
nid.hWnd = LocalAlloc(LPTR,Marshal.SizeOf(this));
nid.uCallbackMessage = 0;
nid.uID = 1;
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
Marshal.StructureToPtr(nid, pData, false);
// Add tooltip
char[] arrTooltip = "My tooltip".ToCharArray();
Marshal.Copy(arrTooltip, 0, (IntPtr)(pData.ToInt32() + Marshal.SizeOf(nid)), arrTooltip.Length);
// Register with shell
bool ret = Shell_NotifyIcon(NIM_ADD, pData);
//Free memory
LocalFree(pData);
Thx
andi