// The AppBarManager calls this to return information regarding the location of the notification area.
        // With Explorer, the notification area is always in an AppBar, but we do not have that assumption.
        public void FillTrayHostSizeData(ref APPBARDATAV2 abd)
        {
            TrayHostSizeData msd = trayHostSizeData;

            abd.rc    = msd.rc;
            abd.uEdge = (uint)msd.edge;
        }
Example #2
0
 private void FillTrayHostSizeData(ref APPBARDATAV2 abd)
 {
     if (trayHostSizeDelegate != null)
     {
         TrayHostSizeData msd = trayHostSizeDelegate();
         abd.rc    = msd.rc;
         abd.uEdge = (uint)msd.edge;
     }
     else
     {
         CairoLogger.Instance.Info("TrayService: TrayHostSizeDelegate is null");
     }
 }
Example #3
0
        private IntPtr appBarMessage_GetTaskbarPos(APPBARMSGDATAV3 amd, ref bool handled)
        {
            IntPtr       hShared = SHLockShared((IntPtr)amd.hSharedMemory, (uint)amd.dwSourceProcessId);
            APPBARDATAV2 abd     = (APPBARDATAV2)Marshal.PtrToStructure(hShared, typeof(APPBARDATAV2));

            if (_explorerHelper._notificationArea != null)
            {
                _explorerHelper._notificationArea.FillTrayHostSizeData(ref abd);
            }

            Marshal.StructureToPtr(abd, hShared, false);
            SHUnlockShared(hShared);
            handled = true;
            return((IntPtr)1);
        }
Example #4
0
 private bool AppBarMessageAction(APPBARMSGDATAV3 amd)
 {
     // only handle ABM_GETTASKBARPOS, send other AppBar messages to default handler
     switch ((ABMsg)amd.dwMessage)
     {
     case ABMsg.ABM_GETTASKBARPOS:
         IntPtr       hShared = SHLockShared((IntPtr)amd.hSharedMemory, (uint)amd.dwSourceProcessId);
         APPBARDATAV2 abd     = (APPBARDATAV2)Marshal.PtrToStructure(hShared, typeof(APPBARDATAV2));
         FillTrayHostSizeData(ref abd);
         Marshal.StructureToPtr(abd, hShared, false);
         SHUnlockShared(hShared);
         CairoLogger.Instance.Debug("TrayService: Responded to ABM_GETTASKBARPOS");
         return(true);
     }
     return(false);
 }
Example #5
0
        private IntPtr appBarMessage_QuerySetPos(APPBARMSGDATAV3 amd, ref bool handled)
        {
            // These two messages use shared memory, and forwarding over the message as-is doesn't
            // seem to allow Explorer to access the shared memory. Here we grab the existing (old)
            // shared memory and allocate it into new shared memory, then update AppBarMessageData
            // and forward it on to Explorer.

            if (EnvironmentHelper.IsAppRunningAsShell)
            {
                // some day we will manage AppBars if we are shell, but today is not that day.
                return(IntPtr.Zero);
            }

            // Get Explorer tray handle and PID
            IntPtr ignoreHwnd = IntPtr.Zero;
            IntPtr explorerTray;

            if (_explorerHelper._notificationArea != null)
            {
                ignoreHwnd = _explorerHelper._notificationArea.Handle;
            }
            explorerTray = WindowHelper.FindWindowsTray(ignoreHwnd);

            GetWindowThreadProcessId(explorerTray, out uint explorerPid);

            // recreate shared memory so that Explorer gets access to it
            IntPtr hSharedOld = SHLockShared((IntPtr)amd.hSharedMemory, (uint)amd.dwSourceProcessId);
            IntPtr hSharedNew = SHAllocShared(IntPtr.Zero, (uint)Marshal.SizeOf(typeof(APPBARDATAV2)), explorerPid);

            // Copy the data from the old shared memory into the new
            IntPtr hSharedData = SHLockShared(hSharedNew, explorerPid);

            if (hSharedData == IntPtr.Zero)
            {
                // Failed, bail out bail out!
                SHFreeShared(hSharedNew, explorerPid);
                return(IntPtr.Zero);
            }

            APPBARDATAV2 abdOld = (APPBARDATAV2)Marshal.PtrToStructure(hSharedOld, typeof(APPBARDATAV2));

            Marshal.StructureToPtr(abdOld, hSharedData, false);
            SHUnlockShared(hSharedData);

            // Update AppBarMessageData with the new shared memory handle and PID
            amd.hSharedMemory     = (long)hSharedNew;
            amd.dwSourceProcessId = (int)explorerPid;

            // Prepare structs to send onward
            IntPtr hAmd = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(APPBARMSGDATAV3)));

            Marshal.StructureToPtr(amd, hAmd, false);

            COPYDATASTRUCT copyData = new COPYDATASTRUCT
            {
                cbData = Marshal.SizeOf(typeof(APPBARMSGDATAV3)),
                dwData = (IntPtr)0,
                lpData = hAmd
            };
            IntPtr hCopyData = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(COPYDATASTRUCT)));

            Marshal.StructureToPtr(copyData, hCopyData, false);

            IntPtr result = SendMessage(explorerTray, (int)WM.COPYDATA, (IntPtr)amd.abd.hWnd, hCopyData);

            handled = true;

            // It's possible that Explorer modified the data we sent, so read the data back out.
            IntPtr hSharedFromExplorer = SHLockShared(hSharedNew, explorerPid);

            if (hSharedFromExplorer != IntPtr.Zero)
            {
                APPBARDATAV2 abdNew = (APPBARDATAV2)Marshal.PtrToStructure(hSharedFromExplorer, typeof(APPBARDATAV2));
                SHUnlockShared(hSharedFromExplorer);

                Marshal.StructureToPtr(abdNew, hSharedOld, false);
                SHUnlockShared(hSharedOld);
            }

            SHFreeShared(hSharedNew, explorerPid);

            return(result);
        }