Exemplo n.º 1
0
        public IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == NativeMethods.WM_MOUSEACTIVATE)
            {
                handled = true;
                return(new IntPtr(NativeMethods.MA_NOACTIVATE));
            }
            else if (msg == NativeMethods.WM_WINDOWPOSCHANGING)
            {
                // WM_WINDOWPOSCHANGING arrives here before the desktop window.
                if (!ToolbarOwner.IsOverlayOpen)
                {
                    // if the overlay isn't open, we always want to be on the bottom. modify the WINDOWPOS structure so that nothing can change our z-order.

                    // Extract the WINDOWPOS structure corresponding to this message
                    NativeMethods.WINDOWPOS wndPos = NativeMethods.WINDOWPOS.FromMessage(lParam);

                    // Determine if the z-order is changing (absence of SWP_NOZORDER flag)
                    // If we are intentionally setting our z-order, allow it. The desktop sets this flag whenever it decides to go to the bottom.
                    if (!ToolbarOwner.IsLowering && (wndPos.flags & NativeMethods.SetWindowPosFlags.SWP_NOZORDER) == 0)
                    {
                        // add the SWP_NOZORDER flag
                        wndPos.flags = wndPos.flags | NativeMethods.SetWindowPosFlags.SWP_NOZORDER;
                        wndPos.UpdateMessage(lParam);
                    }
                }
            }
            else if (msg == NativeMethods.WM_DISPLAYCHANGE)
            {
                SetPosition(((uint)lParam & 0xffff), ((uint)lParam >> 16));
                handled = true;
            }

            return(IntPtr.Zero);
        }
Exemplo n.º 2
0
        public IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == NativeMethods.WM_WINDOWPOSCHANGING)
            {
                if (!IsOverlayOpen)
                {
                    // if the overlay isn't open, we always want to be on the bottom. modify the WINDOWPOS structure so that we go to the bottom.

                    // Extract the WINDOWPOS structure corresponding to this message
                    NativeMethods.WINDOWPOS wndPos = NativeMethods.WINDOWPOS.FromMessage(lParam);

                    // Determine if the z-order is changing (absence of SWP_NOZORDER flag)
                    if ((wndPos.flags & NativeMethods.SetWindowPosFlags.SWP_NOZORDER) == 0)
                    {
                        if (!Startup.IsCairoRunningAsShell)
                        {
                            IntPtr lowestHwnd = Shell.GetLowestDesktopHwnd();
                            if (lowestHwnd != IntPtr.Zero)
                            {
                                wndPos.hwndInsertAfter = NativeMethods.GetWindow(lowestHwnd, NativeMethods.GetWindow_Cmd.GW_HWNDPREV);
                            }
                            else
                            {
                                wndPos.hwndInsertAfter = (IntPtr)NativeMethods.HWND_BOTTOMMOST;
                            }
                        }
                        else
                        {
                            wndPos.hwndInsertAfter = (IntPtr)NativeMethods.HWND_BOTTOMMOST;
                        }
                        wndPos.UpdateMessage(lParam);
                    }
                }
            }
            else if (msg == NativeMethods.WM_DISPLAYCHANGE && (Startup.IsCairoRunningAsShell))
            {
                SetPosition(((uint)lParam & 0xffff), ((uint)lParam >> 16));
                ReloadBackground();
                handled = true;
            }
            else if (msg == (int)NativeMethods.WM.SETTINGCHANGE &&
                     wParam.ToInt32() == (int)NativeMethods.SPI.SETDESKWALLPAPER)
            {
                ReloadBackground();

                return(new IntPtr(NativeMethods.MA_NOACTIVATE));
            }
            else if (msg == (int)NativeMethods.WM.SETTINGCHANGE &&
                     wParam.ToInt32() == (int)NativeMethods.SPI.SETWORKAREA)
            {
                ResetPosition();
                handled = true;
            }

            return(IntPtr.Zero);
        }
Exemplo n.º 3
0
        public IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == NativeMethods.WM_MOUSEACTIVATE)
            {
                handled = true;
                return(new IntPtr(NativeMethods.MA_NOACTIVATE));
            }
            else if (msg == NativeMethods.WM_SETFOCUS || msg == NativeMethods.WM_WINDOWPOSCHANGED)
            {
                if (!IsOverlayOpen && !IsFbdOpen)
                {
                    Shell.ShowWindowBottomMost(helper.Handle);
                    handled = true;
                }
            }
            else if (msg == NativeMethods.WM_WINDOWPOSCHANGING)
            {
                if (IsFbdOpen)
                {
                    // workaround so that folder browser window comes to front, but not the desktop

                    // Extract the WINDOWPOS structure corresponding to this message
                    NativeMethods.WINDOWPOS wndPos = NativeMethods.WINDOWPOS.FromMessage(lParam);

                    // Determine if the z-order is changing (absence of SWP_NOZORDER flag)
                    if (!((wndPos.flags & NativeMethods.SetWindowPosFlags.SWP_NOZORDER) == NativeMethods.SetWindowPosFlags.SWP_NOZORDER))
                    {
                        // add the SWP_NOZORDER flag
                        wndPos.flags = wndPos.flags | NativeMethods.SetWindowPosFlags.SWP_NOZORDER;
                        wndPos.UpdateMessage(lParam);
                    }
                }

                handled = true;
                return(new IntPtr(NativeMethods.MA_NOACTIVATE));
            }
            else if (msg == NativeMethods.WM_DISPLAYCHANGE && (Startup.IsCairoUserShell))
            {
                SetPosition(((uint)lParam & 0xffff), ((uint)lParam >> 16));
                BackgroundBrush = null;
                setBackground();
                handled = true;
            }
            else if (msg == (int)NativeMethods.WM.SETTINGCHANGE &&
                     wParam.ToInt32() == (int)NativeMethods.SPI.SPI_SETDESKWALLPAPER)
            {
                BackgroundBrush = null;
                setBackground();
                return(new IntPtr(NativeMethods.MA_NOACTIVATE));
            }

            return(IntPtr.Zero);
        }
 protected override void WndProc(ref Message m)
 {
     if (_enableOverride)
     {
         if (m.Msg == NativeMethods.WM_WINDOWPOSCHANGING)
         {
             // Extract the WINDOWPOS structure corresponding to this message
             NativeMethods.WINDOWPOS wndPos = NativeMethods.WINDOWPOS.FromMessage(m);
             wndPos.flags = wndPos.flags | NativeMethods.SetWindowPosFlags.SWP_NOZORDER;
             wndPos.UpdateMessage(m);
         }
     }
     base.WndProc(ref m);
 }
        public IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == (int)NativeMethods.WM.MOUSEACTIVATE)
            {
                handled = true;
                return(new IntPtr(NativeMethods.MA_NOACTIVATE));
            }
            else if (msg == (int)NativeMethods.WM.WINDOWPOSCHANGING)
            {
                if (!_desktopManager.IsOverlayOpen)
                {
                    // if the overlay isn't open, we always want to be on the bottom. modify the WINDOWPOS structure so that we always go to right above the desktop.
                    // the desktop will do the work of bringing us to the bottom.

                    // Extract the WINDOWPOS structure corresponding to this message
                    NativeMethods.WINDOWPOS wndPos = NativeMethods.WINDOWPOS.FromMessage(lParam);

                    // Determine if the z-order is changing (absence of SWP_NOZORDER flag)
                    if ((wndPos.flags & NativeMethods.SetWindowPosFlags.SWP_NOZORDER) == 0)
                    {
                        // if the overlay is not open, we want to be right above the desktop. otherwise, we want to be right above the overlay.
                        IntPtr ownerWnd = IntPtr.Zero;
                        if (_desktopManager.ShellWindow != null)
                        {
                            ownerWnd = _desktopManager.ShellWindow.Handle;
                        }
                        else if (_desktopManager.DesktopWindow != null)
                        {
                            ownerWnd = _desktopManager.AllowProgmanChild ? WindowHelper.GetLowestDesktopParentHwnd() : _desktopManager.DesktopWindow.Handle;
                        }

                        wndPos.hwndInsertAfter = NativeMethods.GetWindow(ownerWnd, NativeMethods.GetWindow_Cmd.GW_HWNDPREV);
                        wndPos.flags           = wndPos.flags | NativeMethods.SetWindowPosFlags.SWP_NOOWNERZORDER;
                        wndPos.UpdateMessage(lParam);
                    }
                }
            }
            else if (msg == (int)NativeMethods.WM.DISPLAYCHANGE)
            {
                SetPosition(((uint)lParam & 0xffff), ((uint)lParam >> 16));
                handled = true;
            }
            else if (msg == (int)NativeMethods.WM.DPICHANGED || msg == (int)NativeMethods.WM.DISPLAYCHANGE)
            {
                SetPosition();
            }

            return(IntPtr.Zero);
        }
Exemplo n.º 6
0
 private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
 {
     if (_enableOverride)
     {
         if (msg == NativeMethods.WM_WINDOWPOSCHANGING)
         {
             Debug.WriteLine("WM_WINDOWPOSCHANGING");
             // Extract the WINDOWPOS structure corresponding to this message
             //lParam has the ptr to a WindowsPos structure if its our WM_WINDOWPOSCHANGING struct
             NativeMethods.WINDOWPOS wndPos = NativeMethods.WINDOWPOS.FromMessage(lParam);
             wndPos.flags = wndPos.flags | NativeMethods.SetWindowPosFlags.SWP_NOZORDER;
             wndPos.UpdateMessage(lParam);
             //handled = true;
         }
     }
     return(IntPtr.Zero);
 }
Exemplo n.º 7
0
        public IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == (int)NativeMethods.WM.WINDOWPOSCHANGING)
            {
                if (desktopManager.ShellWindow == null && !desktopManager.SpicySauce)
                {
                    // Extract the WINDOWPOS structure corresponding to this message
                    NativeMethods.WINDOWPOS wndPos = NativeMethods.WINDOWPOS.FromMessage(lParam);

                    // Determine if the z-order is changing (absence of SWP_NOZORDER flag)
                    if ((wndPos.flags & NativeMethods.SetWindowPosFlags.SWP_NOZORDER) == 0)
                    {
                        // get the lowest window, we want to insert after it
                        IntPtr lowestHwnd = Shell.GetLowestDesktopParentHwnd();

                        if (lowestHwnd != IntPtr.Zero)
                        {
                            wndPos.hwndInsertAfter = NativeMethods.GetWindow(lowestHwnd, NativeMethods.GetWindow_Cmd.GW_HWNDPREV);
                        }
                        else
                        {
                            // this will bring us lower but not always as low as we want to go; better than nothing
                            wndPos.hwndInsertAfter = (IntPtr)NativeMethods.WindowZOrder.HWND_BOTTOM;
                        }

                        wndPos.UpdateMessage(lParam);
                    }
                }
            }
            else if (msg == (int)NativeMethods.WM.DISPLAYCHANGE)
            {
                desktopManager.OnDisplayChange(lParam);
            }
            else if (msg == (int)NativeMethods.WM.DPICHANGED)
            {
                desktopManager.OnDpiChanged();
            }
            else if (msg == (int)NativeMethods.WM.SETTINGCHANGE &&
                     wParam.ToInt32() == (int)NativeMethods.SPI.SETWORKAREA)
            {
                desktopManager.OnSetWorkArea();
                handled = true;
            }

            return(IntPtr.Zero);
        }
Exemplo n.º 8
0
    private void WmWindowPosChanging(ref Message m)
    {
        // Extract the WINDOWPOS structure corresponding to this message
        NativeMethods.WINDOWPOS wndPos = NativeMethods.WINDOWPOS.FromMessage(m);

        // Determine if the size is changing (absence of SWP_NOSIZE flag)
        if (!((wndPos.flags & NativeMethods.SetWindowPosFlags.SWP_NOSIZE) == NativeMethods.SetWindowPosFlags.SWP_NOSIZE))
        {
            // Raise the LowLevelSizeChanging event
            SizeChangingEventArgs e = new SizeChangingEventArgs(this.Size, new Size(wndPos.cx, wndPos.cy));
            this.OnLowLevelSizeChanging(e);

            // Determine if the user canceled the size changing event
            if (e.Cancel)
            {
                // If so, add the SWP_NOSIZE flag
                wndPos.flags = wndPos.flags | NativeMethods.SetWindowPosFlags.SWP_NOSIZE;
                wndPos.UpdateMessage(m);
            }
        }

        // Determine if the position is changing (absence of SWP_NOMOVE flag)
        if (!((wndPos.flags & NativeMethods.SetWindowPosFlags.SWP_NOMOVE) == NativeMethods.SetWindowPosFlags.SWP_NOMOVE))
        {
            // Raise the LowLevelPositionChanging event
            PositionChangingEventArgs e = new PositionChangingEventArgs(this.Location, new Point(wndPos.x, wndPos.y));
            this.OnLowLevelPositionChanging(e);

            // Determine if the user canceled the position changing event
            if (e.Cancel)
            {
                // If so, add the SWP_NOMOVE flag
                wndPos.flags = wndPos.flags | NativeMethods.SetWindowPosFlags.SWP_NOMOVE;
                wndPos.UpdateMessage(m);
            }
        }

        base.WndProc(m);
    }
Exemplo n.º 9
0
        public IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == NativeMethods.WM_WINDOWPOSCHANGING)
            {
                if (!IsOverlayOpen)
                {
                    // if the overlay isn't open, we always want to be on the bottom. modify the WINDOWPOS structure so that nothing can change our z-order.

                    // Extract the WINDOWPOS structure corresponding to this message
                    NativeMethods.WINDOWPOS wndPos = NativeMethods.WINDOWPOS.FromMessage(lParam);

                    // Determine if the z-order is changing (absence of SWP_NOZORDER flag)
                    // If we are intentionally setting our z-order, allow it
                    if (!IsLowering && (wndPos.flags & NativeMethods.SetWindowPosFlags.SWP_NOZORDER) == 0)
                    {
                        // add the SWP_NOZORDER flag
                        wndPos.flags = wndPos.flags | NativeMethods.SetWindowPosFlags.SWP_NOZORDER;
                        wndPos.UpdateMessage(lParam);
                    }
                }
            }
            else if (msg == NativeMethods.WM_DISPLAYCHANGE && (Startup.IsCairoRunningAsShell))
            {
                SetPosition(((uint)lParam & 0xffff), ((uint)lParam >> 16));
                ReloadBackground();
                handled = true;
            }
            else if (msg == (int)NativeMethods.WM.SETTINGCHANGE &&
                     wParam.ToInt32() == (int)NativeMethods.SPI.SETDESKWALLPAPER)
            {
                ReloadBackground();

                return(new IntPtr(NativeMethods.MA_NOACTIVATE));
            }

            return(IntPtr.Zero);
        }
        public IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == NativeMethods.WM_MOUSEACTIVATE)
            {
                handled = true;
                return(new IntPtr(NativeMethods.MA_NOACTIVATE));
            }
            else if (msg == NativeMethods.WM_WINDOWPOSCHANGING)
            {
                // WM_WINDOWPOSCHANGING arrives here before the desktop window.
                if (!ToolbarOwner.IsOverlayOpen)
                {
                    // if the overlay isn't open, we always want to be on the bottom. modify the WINDOWPOS structure so that we always go to right above the desktop.
                    // the desktop will do the work of bringing us to the bottom.

                    // Extract the WINDOWPOS structure corresponding to this message
                    NativeMethods.WINDOWPOS wndPos = NativeMethods.WINDOWPOS.FromMessage(lParam);

                    // Determine if the z-order is changing (absence of SWP_NOZORDER flag)
                    if ((wndPos.flags & NativeMethods.SetWindowPosFlags.SWP_NOZORDER) == 0)
                    {
                        // be right above the desktop.
                        wndPos.hwndInsertAfter = NativeMethods.GetWindow(ToolbarOwner.Handle, NativeMethods.GetWindow_Cmd.GW_HWNDPREV);
                        wndPos.flags           = wndPos.flags | NativeMethods.SetWindowPosFlags.SWP_NOOWNERZORDER;
                        wndPos.UpdateMessage(lParam);
                    }
                }
            }
            else if (msg == NativeMethods.WM_DISPLAYCHANGE)
            {
                SetPosition(((uint)lParam & 0xffff), ((uint)lParam >> 16));
                handled = true;
            }

            return(IntPtr.Zero);
        }
Exemplo n.º 11
0
        private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == appbarMessageId && appbarMessageId != -1)
            {
                switch ((NativeMethods.AppBarNotifications)wParam.ToInt32())
                {
                case NativeMethods.AppBarNotifications.PosChanged:
                    AppBarHelper.ABSetPos(this, ActualWidth * dpiScale, desiredHeight * dpiScale, appBarEdge);
                    break;

                case NativeMethods.AppBarNotifications.WindowArrange:
                    if ((int)lParam != 0)     // before
                    {
                        Visibility = Visibility.Collapsed;
                    }
                    else     // after
                    {
                        Visibility = Visibility.Visible;
                    }

                    break;

                case NativeMethods.AppBarNotifications.FullScreenApp:
                    AppBarHelper.SetWinTaskbarVisibility((int)NativeMethods.SetWindowPosFlags.SWP_HIDEWINDOW);
                    break;
                }
                handled = true;
            }
            else if (msg == (int)NativeMethods.WM.ACTIVATE && enableAppBar && !Shell.IsCairoRunningAsShell && !Startup.IsShuttingDown)
            {
                AppBarHelper.AppBarActivate(hwnd);
            }
            else if (msg == (int)NativeMethods.WM.WINDOWPOSCHANGING)
            {
                // Extract the WINDOWPOS structure corresponding to this message
                NativeMethods.WINDOWPOS wndPos = NativeMethods.WINDOWPOS.FromMessage(lParam);

                // Determine if the z-order is changing (absence of SWP_NOZORDER flag)
                // If we are intentionally trying to become topmost, make it so
                if (isRaising && (wndPos.flags & NativeMethods.SetWindowPosFlags.SWP_NOZORDER) == 0)
                {
                    // Sometimes Windows thinks we shouldn't go topmost, so poke here to make it happen.
                    wndPos.hwndInsertAfter = (IntPtr)NativeMethods.WindowZOrder.HWND_TOPMOST;
                    wndPos.UpdateMessage(lParam);
                }
            }
            else if (msg == (int)NativeMethods.WM.WINDOWPOSCHANGED && enableAppBar && !Shell.IsCairoRunningAsShell && !Startup.IsShuttingDown)
            {
                AppBarHelper.AppBarWindowPosChanged(hwnd);
            }
            else if (msg == (int)NativeMethods.WM.DPICHANGED)
            {
                if (Screen.Primary)
                {
                    Shell.DpiScale = (wParam.ToInt32() & 0xFFFF) / 96d;
                }

                dpiScale = (wParam.ToInt32() & 0xFFFF) / 96d;

                setScreenProperties(ScreenSetupReason.DpiChange);
            }
            else if (msg == (int)NativeMethods.WM.DISPLAYCHANGE)
            {
                setScreenProperties(ScreenSetupReason.DisplayChange);
                handled = true;
            }
            else if (msg == (int)NativeMethods.WM.DEVICECHANGE && (int)wParam == 0x0007)
            {
                setScreenProperties(ScreenSetupReason.DeviceChange);
                handled = true;
            }

            // call custom implementations' window procedure
            return(customWndProc(hwnd, msg, wParam, lParam, ref handled));
        }
Exemplo n.º 12
0
        public IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == (int)NativeMethods.WM.WINDOWPOSCHANGING)
            {
                if (!IsOverlayOpen)
                {
                    // if the overlay isn't open, we always want to be on the bottom. modify the WINDOWPOS structure so that we go to the bottom.

                    // Extract the WINDOWPOS structure corresponding to this message
                    NativeMethods.WINDOWPOS wndPos = NativeMethods.WINDOWPOS.FromMessage(lParam);

                    // Determine if the z-order is changing (absence of SWP_NOZORDER flag)
                    if ((wndPos.flags & NativeMethods.SetWindowPosFlags.SWP_NOZORDER) == 0)
                    {
                        if (!Shell.IsCairoRunningAsShell)
                        {
                            IntPtr lowestHwnd = Shell.GetLowestDesktopHwnd();
                            if (lowestHwnd != IntPtr.Zero)
                            {
                                wndPos.hwndInsertAfter = NativeMethods.GetWindow(lowestHwnd, NativeMethods.GetWindow_Cmd.GW_HWNDPREV);
                            }
                            else
                            {
                                wndPos.hwndInsertAfter = (IntPtr)NativeMethods.WindowZOrder.HWND_BOTTOM;
                            }
                        }
                        else
                        {
                            wndPos.hwndInsertAfter = (IntPtr)NativeMethods.WindowZOrder.HWND_BOTTOM;
                        }
                        wndPos.UpdateMessage(lParam);
                    }
                }
            }
            else if (msg == (int)NativeMethods.WM.DISPLAYCHANGE && Shell.IsCairoRunningAsShell)
            {
                ResetPosition();
                ReloadBackground();

                handled = true;
            }
            else if (msg == (int)NativeMethods.WM.DPICHANGED && Shell.IsCairoRunningAsShell)
            {
                // delay changing things when we are shell. it seems that AppBars do this automagically
                // if we don't, the system moves things to bad places
                var timer = new DispatcherTimer {
                    Interval = TimeSpan.FromSeconds(0.1)
                };
                timer.Start();
                timer.Tick += (sender1, args) =>
                {
                    ResetPosition();
                    ReloadBackground();
                    timer.Stop();
                };
            }
            else if (msg == (int)NativeMethods.WM.SETTINGCHANGE &&
                     wParam.ToInt32() == (int)NativeMethods.SPI.SETDESKWALLPAPER)
            {
                ReloadBackground();

                return(new IntPtr(NativeMethods.MA_NOACTIVATE));
            }
            else if (msg == (int)NativeMethods.WM.SETTINGCHANGE &&
                     wParam.ToInt32() == (int)NativeMethods.SPI.SETWORKAREA)
            {
                ResetPosition();
                handled = true;
            }

            return(IntPtr.Zero);
        }
Exemplo n.º 13
0
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case NativeMethods.WindowsMessage.WM_NCACTIVATE:
                if (m.WParam == IntPtr.Zero)
                {
                    m.Result = NativeMethods.MESSAGE_HANDLED;
                }
                InvalidateWindow();
                break;

            case NativeMethods.WindowsMessage.WM_SETCURSOR:
            case NativeMethods.WindowsMessage.WM_ACTIVATEAPP:
            case NativeMethods.WindowsMessage.WM_SIZE:
            case NativeMethods.WindowsMessage.WM_MOVE:
            {
                base.WndProc(ref m);
                InvalidateWindow();
            }
            break;

            case NativeMethods.WindowsMessage.WM_NCUAHDRAWCAPTION:
            case NativeMethods.WindowsMessage.WM_NCUAHDRAWFRAME:
            {
                InvalidateWindow();
            }
            break;

            case NativeMethods.WindowsMessage.WM_NCPAINT:
                if (NativeMethods.IsWindowVisible(FormHandle))
                {
                    DrawWindow(m.WParam);
                    m.Result = NativeMethods.MESSAGE_HANDLED;
                }
                break;

            case NativeMethods.WindowsMessage.WM_NCCALCSIZE:
                if (m.WParam != IntPtr.Zero)
                {
                    NativeMethods.NCCALCSIZE_PARAMS ncsize = (NativeMethods.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.NCCALCSIZE_PARAMS));
                    NativeMethods.WINDOWPOS         wp     = (NativeMethods.WINDOWPOS)Marshal.PtrToStructure(ncsize.lppos, typeof(NativeMethods.WINDOWPOS));
                    // store original frame sizes
                    if (!_bStoreSize)
                    {
                        _bStoreSize     = true;
                        _iCaptionHeight = ncsize.rect2.Top - ncsize.rect0.Top;
                        _iFrameHeight   = ncsize.rect0.Bottom - ncsize.rect2.Bottom;
                        _iFrameWidth    = ncsize.rect2.Left - ncsize.rect0.Left;
                    }
                    if (!_bResetSize)
                    {
                        ncsize.rect0 = CalculateFrameSize(wp.x, wp.y, wp.cx, wp.cy);
                        ncsize.rect1 = ncsize.rect0;
                    }
                    Marshal.StructureToPtr(ncsize, m.LParam, false);
                    m.Result = (IntPtr)0x400;                            //WVR_VALIDRECTS;
                }
                else
                {
                    NativeMethods.RECT rc = (NativeMethods.RECT)m.GetLParam(typeof(NativeMethods.RECT));
                    rc = CalculateFrameSize(rc.Left, rc.Top, rc.Right - rc.Left, rc.Bottom - rc.Top);;
                    Marshal.StructureToPtr(rc, m.LParam, true);
                    m.Result = IntPtr.Zero;                            //MESSAGE_PROCESS;
                }

                base.WndProc(ref m);


                break;

            default:
                base.WndProc(ref m);
                break;
            }
        }
Exemplo n.º 14
0
        public IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == NativeMethods.WM_MOUSEACTIVATE)
            {
                handled = true;
                return(new IntPtr(NativeMethods.MA_NOACTIVATE));
            }

            if (msg == appbarMessageId && appbarMessageId != -1 && Configuration.Settings.Instance.TaskbarMode == 0)
            {
                switch ((NativeMethods.AppBarNotifications)wParam.ToInt32())
                {
                case NativeMethods.AppBarNotifications.PosChanged:
                    // Reposition to the top of the screen.
                    AppBarHelper.ABSetPos(this, Screen, ActualWidth * dpiScale, ActualHeight * dpiScale, appBarEdge);
                    break;

                case NativeMethods.AppBarNotifications.FullScreenApp:
                    //SetFullScreenMode((int)lParam == 1);

                    break;

                case NativeMethods.AppBarNotifications.WindowArrange:
                    if ((int)lParam != 0)        // before
                    {
                        Visibility = Visibility.Collapsed;
                    }
                    else                             // after
                    {
                        Visibility = Visibility.Visible;
                    }

                    break;
                }
                handled = true;
            }
            else if (msg == NativeMethods.WM_ACTIVATE && Configuration.Settings.Instance.TaskbarMode == 0)
            {
                AppBarHelper.AppBarActivate(hwnd);
            }
            else if (msg == NativeMethods.WM_WINDOWPOSCHANGING)
            {
                // Extract the WINDOWPOS structure corresponding to this message
                NativeMethods.WINDOWPOS wndPos = NativeMethods.WINDOWPOS.FromMessage(lParam);

                // Determine if the z-order is changing (absence of SWP_NOZORDER flag)
                // If we are intentionally trying to become topmost, make it so
                if (isRaising && (wndPos.flags & NativeMethods.SetWindowPosFlags.SWP_NOZORDER) == 0)
                {
                    // Sometimes Windows thinks we shouldn't go topmost, so poke here to make it happen.
                    wndPos.hwndInsertAfter = (IntPtr)NativeMethods.HWND_TOPMOST;
                    wndPos.UpdateMessage(lParam);
                }
            }
            else if (msg == NativeMethods.WM_WINDOWPOSCHANGED && Settings.Instance.TaskbarMode == 0)
            {
                AppBarHelper.AppBarWindowPosChanged(hwnd);
            }
            else if (msg == NativeMethods.WM_DPICHANGED)
            {
                if (!(Settings.Instance.EnableMenuBarMultiMon || Configuration.Settings.Instance.EnableTaskbarMultiMon))
                {
                    Startup.ResetScreenCache();
                    Screen = System.Windows.Forms.Screen.PrimaryScreen;
                }

                if (Screen.Primary)
                {
                    Shell.DpiScale = (wParam.ToInt32() & 0xFFFF) / 96d;
                }

                dpiScale = (wParam.ToInt32() & 0xFFFF) / 96d;
                AppBarHelper.ABSetPos(this, Screen, this.ActualWidth * dpiScale, this.ActualHeight * dpiScale, appBarEdge);
            }
            else if (msg == NativeMethods.WM_DISPLAYCHANGE)
            {
                if (!(Settings.Instance.EnableMenuBarMultiMon || Configuration.Settings.Instance.EnableTaskbarMultiMon))
                {
                    Startup.ResetScreenCache();
                    Screen = System.Windows.Forms.Screen.PrimaryScreen;
                }

                setPosition(((uint)lParam & 0xffff), ((uint)lParam >> 16));
                handled = true;
            }

            return(IntPtr.Zero);
        }
Exemplo n.º 15
0
        public IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == appbarMessageId && appbarMessageId != -1)
            {
                switch ((NativeMethods.AppBarNotifications)wParam.ToInt32())
                {
                case NativeMethods.AppBarNotifications.PosChanged:
                    // Reposition to the top of the screen.
                    AppBarHelper.ABSetPos(this, Screen, this.ActualWidth * dpiScale, this.ActualHeight * dpiScale, AppBarHelper.ABEdge.ABE_TOP);
                    break;

                case NativeMethods.AppBarNotifications.FullScreenApp:
                    // we have our own implementation now

                    /*if ((int)lParam == 1)
                     * {
                     *  CairoLogger.Instance.Debug("Cairo leaving on-top");
                     *  this.Topmost = false;
                     *  Shell.ShowWindowBottomMost(this.handle);
                     *
                     *  if (Settings.Instance.EnableTaskbar)
                     *  {
                     *      Startup.TaskbarWindow.SetFullScreenMode(true);
                     *  }
                     * }
                     * else
                     * {
                     *  CairoLogger.Instance.Debug("Cairo entering on-top");
                     *  this.Topmost = true;
                     *  Shell.ShowWindowTopMost(this.handle);
                     *
                     *  if (Settings.Instance.EnableTaskbar)
                     *  {
                     *      Startup.TaskbarWindow.SetFullScreenMode(false);
                     *  }
                     * }
                     */
                    break;

                case NativeMethods.AppBarNotifications.WindowArrange:
                    if ((int)lParam != 0)        // before
                    {
                        this.Visibility = Visibility.Collapsed;
                    }
                    else                             // after
                    {
                        this.Visibility = Visibility.Visible;
                    }

                    break;
                }
                handled = true;
            }
            else if (msg == NativeMethods.WM_ACTIVATE)
            {
                AppBarHelper.AppBarActivate(hwnd);
            }
            else if (msg == NativeMethods.WM_WINDOWPOSCHANGING)
            {
                // Extract the WINDOWPOS structure corresponding to this message
                NativeMethods.WINDOWPOS wndPos = NativeMethods.WINDOWPOS.FromMessage(lParam);

                // Determine if the z-order is changing (absence of SWP_NOZORDER flag)
                // If we are intentionally trying to become topmost, make it so
                if (isRaising && (wndPos.flags & NativeMethods.SetWindowPosFlags.SWP_NOZORDER) == 0)
                {
                    // Sometimes Windows thinks we shouldn't go topmost, so poke here to make it happen.
                    wndPos.hwndInsertAfter = (IntPtr)NativeMethods.HWND_TOPMOST;
                    wndPos.UpdateMessage(lParam);
                }
            }
            else if (msg == NativeMethods.WM_WINDOWPOSCHANGED)
            {
                AppBarHelper.AppBarWindowPosChanged(hwnd);
            }
            else if (msg == NativeMethods.WM_DPICHANGED)
            {
                if ((Settings.Instance.EnableMenuBarMultiMon || Configuration.Settings.Instance.EnableTaskbarMultiMon) && !Startup.IsSettingScreens)
                {
                    Startup.ScreenSetup(); // update Cairo window list based on new screen setup
                }
                else if (!(Settings.Instance.EnableMenuBarMultiMon || Configuration.Settings.Instance.EnableTaskbarMultiMon))
                {
                    Startup.ResetScreenCache();
                    Screen = System.Windows.Forms.Screen.PrimaryScreen;
                }

                if (Screen.Primary)
                {
                    Shell.DpiScale = (wParam.ToInt32() & 0xFFFF) / 96d;
                }

                this.dpiScale = (wParam.ToInt32() & 0xFFFF) / 96d;
                setPosition();
                AppBarHelper.ABSetPos(this, Screen, this.ActualWidth * dpiScale, this.ActualHeight * dpiScale, AppBarHelper.ABEdge.ABE_TOP);
            }
            else if (msg == NativeMethods.WM_DISPLAYCHANGE)
            {
                if ((Settings.Instance.EnableMenuBarMultiMon || Configuration.Settings.Instance.EnableTaskbarMultiMon) && !Startup.IsSettingScreens && Screen.Primary)
                {
                    Startup.ScreenSetup(); // update Cairo window list based on new screen setup
                }
                else if (!(Settings.Instance.EnableMenuBarMultiMon || Configuration.Settings.Instance.EnableTaskbarMultiMon))
                {
                    Startup.ResetScreenCache();
                    Screen = System.Windows.Forms.Screen.PrimaryScreen;
                }

                setPosition(((uint)lParam & 0xffff), ((uint)lParam >> 16));
                handled = true;
            }
            else if (msg == NativeMethods.WM_DEVICECHANGE && (int)wParam == 0x0007)
            {
                if ((Settings.Instance.EnableMenuBarMultiMon || Configuration.Settings.Instance.EnableTaskbarMultiMon) && !Startup.IsSettingScreens && Screen.Primary)
                {
                    Startup.ScreenSetup(); // update Cairo window list based on new screen setup
                }
            }

            return(IntPtr.Zero);
        }
Exemplo n.º 16
0
        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));
        }