private bool AppBarMessageAction(NativeMethods.APPBARMSGDATAV3 amd) { // only handle ABM_GETTASKBARPOS, send other AppBar messages to default handler switch ((NativeMethods.ABMsg)amd.dwMessage) { case NativeMethods.ABMsg.ABM_GETTASKBARPOS: IntPtr hShared = NativeMethods.SHLockShared((IntPtr)amd.hSharedMemory, (uint)amd.dwSourceProcessId); NativeMethods.APPBARDATAV2 abd = (NativeMethods.APPBARDATAV2)Marshal.PtrToStructure(hShared, typeof(NativeMethods.APPBARDATAV2)); if (menubarSizeDelegate != null) { NativeMethods.MenuBarSizeData msd = menubarSizeDelegate(); abd.rc = msd.rc; abd.uEdge = (uint)msd.edge; } else { CairoLogger.Instance.Info("TrayService: MenuBarSizeDelegate is null"); } Marshal.StructureToPtr(abd, hShared, false); NativeMethods.SHUnlockShared(hShared); CairoLogger.Instance.Debug("TrayService: Responded to ABM_GETTASKBARPOS"); return(true); } return(false); }
public IntPtr WndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam) { switch ((NativeMethods.WM)msg) { case NativeMethods.WM.COPYDATA: if (lParam == IntPtr.Zero) { CairoLogger.Instance.Debug("TrayService: CopyData is null"); break; } NativeMethods.COPYDATASTRUCT copyData = (NativeMethods.COPYDATASTRUCT)Marshal.PtrToStructure(lParam, typeof(NativeMethods.COPYDATASTRUCT)); switch ((int)copyData.dwData) { case 0: // AppBar message if (Marshal.SizeOf(typeof(NativeMethods.APPBARMSGDATAV3)) == copyData.cbData) { NativeMethods.APPBARMSGDATAV3 amd = (NativeMethods.APPBARMSGDATAV3)Marshal.PtrToStructure(copyData.lpData, typeof(NativeMethods.APPBARMSGDATAV3)); if (Marshal.SizeOf(typeof(NativeMethods.APPBARDATAV2)) != amd.abd.cbSize) { CairoLogger.Instance.Debug("TrayService: Size incorrect for APPBARMSGDATAV3"); break; } if (AppBarMessageAction(amd)) { return((IntPtr)1); } } else { CairoLogger.Instance.Debug("TrayService: AppBar message received, but with unknown size"); } break; case 1: NativeMethods.SHELLTRAYDATA trayData = (NativeMethods.SHELLTRAYDATA)Marshal.PtrToStructure(copyData.lpData, typeof(NativeMethods.SHELLTRAYDATA)); if (trayDelegate != null) { if (trayDelegate(trayData.dwMessage, trayData.nid)) { return((IntPtr)1); } CairoLogger.Instance.Debug("TrayService: Ignored notify icon message"); } else { CairoLogger.Instance.Info("TrayService: TrayDelegate is null"); } break; case 3: NativeMethods.WINNOTIFYICONIDENTIFIER iconData = (NativeMethods.WINNOTIFYICONIDENTIFIER)Marshal.PtrToStructure(copyData.lpData, typeof(NativeMethods.WINNOTIFYICONIDENTIFIER)); if (iconDataDelegate != null) { return(iconDataDelegate(iconData.dwMessage, iconData.hWnd, iconData.uID, iconData.guidItem)); } CairoLogger.Instance.Info("TrayService: IconDataDelegate is null"); break; } break; case NativeMethods.WM.WINDOWPOSCHANGED: NativeMethods.WINDOWPOS wpos = (NativeMethods.WINDOWPOS)Marshal.PtrToStructure(lParam, typeof(NativeMethods.WINDOWPOS)); if ((wpos.flags & NativeMethods.SetWindowPosFlags.SWP_SHOWWINDOW) != 0) { NativeMethods.SetWindowLong(HwndTray, NativeMethods.GWL_STYLE, NativeMethods.GetWindowLong(HwndTray, NativeMethods.GWL_STYLE) & ~(int)NativeMethods.WindowStyles.WS_VISIBLE); CairoLogger.Instance.Debug("TrayService: Shell_TrayWnd became visible; hiding"); } break; } if (msg == (int)NativeMethods.WM.COPYDATA || msg == (int)NativeMethods.WM.ACTIVATEAPP) { IntPtr fwdResult = IntPtr.Zero; NativeMethods.EnumWindows((enumHwnd, enumLParam) => { if (enumHwnd != HwndTray && enumHwnd != hWnd) { StringBuilder className = new StringBuilder(256); NativeMethods.GetClassName(enumHwnd, className, 256); if (className.ToString() == "Shell_TrayWnd") { fwdResult = NativeMethods.SendMessage(enumHwnd, msg, wParam, lParam); } } return(true); }, 0); return(fwdResult); } return(NativeMethods.DefWindowProc(hWnd, msg, wParam, lParam)); }