コード例 #1
0
        internal virtual void afterAppBarPos(bool isSameCoords, NativeMethods.Rect rect)
        {
            // apparently the taskbars like to pop up when app bars change
            if (Settings.Instance.EnableTaskbar && !Startup.IsShuttingDown)
            {
                AppBarHelper.SetWinTaskbarState(AppBarHelper.WinTaskbarState.AutoHide);
                AppBarHelper.SetWinTaskbarVisibility((int)NativeMethods.SetWindowPosFlags.SWP_HIDEWINDOW);
            }

            if (!isSameCoords)
            {
                var timer = new DispatcherTimer {
                    Interval = TimeSpan.FromSeconds(0.1)
                };
                timer.Start();
                timer.Tick += (sender1, args) =>
                {
                    // set position again, since WPF may have overridden the original change from AppBarHelper
                    setAppBarPosition(rect);

                    if (Screen.Primary && WindowManager.Instance.DesktopWindow != null)
                    {
                        WindowManager.Instance.DesktopWindow.ResetPosition();
                    }

                    timer.Stop();
                };
            }
        }
コード例 #2
0
ファイル: AppBarWindow.cs プロジェクト: rglamazda/cairoshell
 protected void UnregisterAppBar()
 {
     if (AppBarHelper.appBars.Contains(Handle))
     {
         AppBarHelper.RegisterBar(this, ActualWidth * dpiScale, desiredHeight * dpiScale);
     }
 }
コード例 #3
0
ファイル: AppBarWindow.cs プロジェクト: rglamazda/cairoshell
 protected void RegisterAppBar()
 {
     if (!Shell.IsCairoRunningAsShell && enableAppBar && !AppBarHelper.appBars.Contains(Handle))
     {
         appbarMessageId = AppBarHelper.RegisterBar(this, ActualWidth * dpiScale, desiredHeight * dpiScale, appBarEdge);
     }
 }
コード例 #4
0
 internal void setScreenPosition()
 {
     // set our position if running as shell, otherwise let AppBar do the work
     if (Shell.IsCairoRunningAsShell || !enableAppBar)
     {
         delaySetPosition();
     }
     else if (enableAppBar)
     {
         AppBarHelper.ABSetPos(this, ActualWidth * dpiScale, desiredHeight * dpiScale, appBarEdge);
     }
 }
コード例 #5
0
        private void OnSourceInitialized(object sender, EventArgs e)
        {
            // set up helper and get handle
            helper = new WindowInteropHelper(this);
            Handle = helper.Handle;

            // set up window procedure
            HwndSource source = HwndSource.FromHwnd(helper.Handle);

            source.AddHook(new HwndSourceHook(WndProc));

            // set initial DPI. We do it here so that we get the correct value when DPI has changed since initial user logon to the system.
            if (Screen.Primary)
            {
                Shell.DpiScale = PresentationSource.FromVisual(Application.Current.MainWindow).CompositionTarget.TransformToDevice.M11;
            }

            dpiScale = PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice.M11;

            setPosition();

            if (Shell.IsCairoRunningAsShell)
            {
                // set position again, on a delay, in case one display has a different DPI. for some reason the system overrides us if we don't wait
                delaySetPosition();
            }

            // register appbar
            if (!Shell.IsCairoRunningAsShell && enableAppBar)
            {
                appbarMessageId = AppBarHelper.RegisterBar(this, ActualWidth * dpiScale, desiredHeight * dpiScale, appBarEdge);
            }

            // hide from alt-tab etc
            Shell.HideWindowFromTasks(Handle);

            // register for full-screen notifications
            FullScreenHelper.Instance.FullScreenApps.CollectionChanged += FullScreenApps_CollectionChanged;

            postInit();
        }
コード例 #6
0
ファイル: AppBarWindow.cs プロジェクト: rglamazda/cairoshell
        internal virtual void AfterAppBarPos(bool isSameCoords, NativeMethods.Rect rect)
        {
            // apparently the TaskBars like to pop up when AppBars change
            if (Settings.Instance.EnableTaskbar && !Startup.IsShuttingDown)
            {
                AppBarHelper.HideWindowsTaskbar();
            }

            if (!isSameCoords)
            {
                var timer = new DispatcherTimer {
                    Interval = TimeSpan.FromSeconds(0.1)
                };
                timer.Start();
                timer.Tick += (sender1, args) =>
                {
                    // set position again, since WPF may have overridden the original change from AppBarHelper
                    SetAppBarPosition(rect);

                    timer.Stop();
                };
            }
        }
コード例 #7
0
        private void OnClosing(object sender, CancelEventArgs e)
        {
            IsClosing = true;

            customClosing();

            if (Startup.IsShuttingDown && Screen.Primary)
            {
                // unregister appbar
                if (AppBarHelper.appBars.Contains(Handle))
                {
                    AppBarHelper.RegisterBar(this, ActualWidth * dpiScale, desiredHeight * dpiScale);
                }

                // unregister full-screen notifications
                FullScreenHelper.Instance.FullScreenApps.CollectionChanged -= FullScreenApps_CollectionChanged;

                // dispose the full screen helper since we are the primary instance
                FullScreenHelper.Instance.Dispose();
            }
            else if (WindowManager.Instance.IsSettingDisplays || Startup.IsShuttingDown)
            {
                // unregister appbar
                if (AppBarHelper.appBars.Contains(Handle))
                {
                    AppBarHelper.RegisterBar(this, ActualWidth * dpiScale, desiredHeight * dpiScale);
                }

                // unregister full-screen notifications
                FullScreenHelper.Instance.FullScreenApps.CollectionChanged -= FullScreenApps_CollectionChanged;
            }
            else
            {
                IsClosing = false;
                e.Cancel  = true;
            }
        }
コード例 #8
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));
        }