private Integer WindowProcedure(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam) { switch (uMsg) { case User32.WM_COPYDATA: //WM_COPYDATA COPYDATASTRUCT cds = Marshal.PtrToStructure <COPYDATASTRUCT>(lParam); if (cds.dwData == new IntPtr(0x00000001)) //Shell private constant: TCDM_NOTIFY { TRAYNOTIFYDATA data = Marshal.PtrToStructure <TRAYNOTIFYDATA>(cds.lpData); SystemTrayNotificationData notificationData = data.nid; if (notificationData.Size != Marshal.SizeOf(typeof(SystemTrayNotificationData))) { //Debugger.Break(); break; } int message = (int)data.dwMessage; SystemTrayNotificationEventArgs e = new((SystemTrayNotificationType)message, notificationData); systemTrayNotification?.Invoke(this, e); User32.SendMessage(oldTaskbar, User32.WM_COPYDATA, wParam, lParam); } /*case User32.WM_PAINT: * Graphics g = Graphics.FromHwnd(hWnd); * g.Clear(SystemColors.Control); * g.Dispose(); * break; * case User32.WM_RBUTTONDOWN: * _ = User32.SendMessage(new IntPtr(HWND_BROADCAST), WM_TASKBARCREATED, IntPtr.Zero, IntPtr.Zero);*/ break; } return(DefWindowProc(hWnd, uMsg, wParam, lParam)); }
public SystemTrayNotificationEventArgs(SystemTrayNotificationType type, SystemTrayNotificationData data) { Type = type; Data = data; }