public VMMain() { Model = new MMain(); AppWindowVisibility = Visibility.Hidden; MainWindowWidth = SDSystem.WindowWidth; HotkeyManager.GetInstance().RegisterHotKey("ShowWindow", LKey.None, RKey.F2, ShowWindow); Swatches = new SwatchesProvider().Swatches; Window win = Application.Current.MainWindow; PresentationSource source = PresentationSource.FromVisual(win); Matrix matrix = source.CompositionTarget.TransformFromDevice; double widthRatio = matrix.M11; double heightRatio = matrix.M22; double screenWidth = SystemParameters.PrimaryScreenWidth * widthRatio; double screenHeight = SystemParameters.PrimaryScreenHeight * heightRatio; MainWindowHeight = SystemParameters.WorkArea.Size.Height * heightRatio; MainWindowLeft = screenWidth - MainWindowWidth; MessageBoxMessage = "Are you sure delete this desktop page?"; DesktopWindowManager.GetInstance().ThemeDark = DesktopWindowManager.GetInstance().ThemeDark; DesktopWindowManager.GetInstance().ThemeColor = DesktopWindowManager.GetInstance().ThemeColor; IsThemeDark = DesktopWindowManager.GetInstance().ThemeDark; }
private void checkBox1_CheckedChanged(object sender, System.EventArgs e) { if (!initMiddle) { DesktopWindowManager.EnableComposition(checkBox1.Checked); } }
static App() { if (!DesktopWindowManager.IsDwmEnabled()) { MessageBox.Show("Desktop Window Manager service must be enabled to run", "Tweetz"); Environment.Exit(1); } }
private void PaintBehindWindow(IDeviceContext destDc, Rectangle screenBounds) { if (!DesktopWindowManager.IsAeroEnabled()) { TopLevelWindow desktopWindow = TopLevelWindow.DesktopWindow; IntPtr desktopDc = desktopWindow.GetHdc(); NativeMethods.BitBlt(destDc.GetHdc(), 0, 0, screenBounds.Width, screenBounds.Height, desktopDc, screenBounds.X, screenBounds.Y, CopyPixelOperation.SourceCopy); desktopWindow.ReleaseHdc(); return; } IntPtr dc = destDc.GetHdc(); for (int index = _visisbleWindows.Count - 1; index > -1; index--) { var window = _visisbleWindows[index]; if (window.Handle == ExcludeWindowBehindBlur) { continue; } Rectangle windowBounds = window.Bounds; var inter = Rectangle.Intersect(screenBounds, windowBounds); if (inter == Rectangle.Empty) { continue; } var localPoint = inter.Location; NativeMethods.ScreenToClient(window.Handle, ref localPoint); var myLocalPoint = new Point(Math.Abs(screenBounds.X - inter.X), Math.Abs(screenBounds.Y - inter.Y)); IntPtr windowDc = window.GetHdc(); if (index == _visisbleWindows.Count - 2) { NativeMethods.AlphaBlend(dc, myLocalPoint.X, myLocalPoint.Y, inter.Width, inter.Height, windowDc, localPoint.X, localPoint.Y, inter.Width, inter.Height, BlendFunction.Default); } else { NativeMethods.BitBlt(dc, myLocalPoint.X, myLocalPoint.Y, inter.Width, inter.Height, windowDc, localPoint.X, localPoint.Y, CopyPixelOperation.SourceCopy); } window.ReleaseHdc(); } destDc.ReleaseHdc(); }
private void form_Resize(object sender, EventArgs e) { Form form = sender as Form; if ((DesktopWindowManager.IsCompositionEnabled() && GetGlassEnabled(form)) || form.IsDesignMode()) { InvalidateNonGlassClientArea(form); } }
/// <summary> /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs"/> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { if (Visible) { VisualStyleRenderer vs = null; if (Application.RenderWithVisualStyles || DesktopWindowManager.IsCompositionEnabled()) { vs = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active); vs.DrawParentBackground(e.Graphics, base.ClientRectangle, this); } // Draw image Rectangle r = DeflateRect(base.ClientRectangle, base.Padding); if (this.Image != null) { Rectangle ir = CalcImageRenderBounds(this.Image, r, base.RtlTranslateAlignment(this.ImageAlign)); if (this.ImageList != null && this.ImageIndex == 0) { if (vs != null & !this.IsDesignMode() & DesktopWindowManager.IsCompositionEnabled()) { vs.DrawGlassIcon(e.Graphics, r, this.ImageList, this.ImageIndex); } else { this.ImageList.Draw(e.Graphics, r.X, r.Y, r.Width, r.Height, this.ImageIndex); } } else { if (vs != null & !this.IsDesignMode() & DesktopWindowManager.IsCompositionEnabled()) { vs.DrawGlassImage(e.Graphics, r, this.Image); } else { e.Graphics.DrawImage(this.Image, r); } } } // Draw text if (this.Text.Length > 0) { TextFormatFlags tff = CreateTextFormatFlags(this.TextAlign, this.AutoEllipsis, this.UseMnemonic); if (this.IsDesignMode() || vs == null || !DesktopWindowManager.IsCompositionEnabled()) { Brush br = DesktopWindowManager.IsCompositionEnabled() ? SystemBrushes.ActiveCaptionText : SystemBrushes.ControlText; e.Graphics.DrawString(Text, Font, br, base.ClientRectangle); } else { vs.DrawGlowingText(e.Graphics, base.ClientRectangle, Text, Font, ForeColor, tff); } } } }
private void ConfigureWindowFrame() { // System.Diagnostics.Debug.WriteLine($"ConfigureWindowFrame: compEnab={DesktopWindowManager.IsCompositionEnabled()},parentForm={(parentForm == null ? "null" : parentForm.Name)}"); ConfigureStyles(); if (!SupportFunctions.IsMono && DesktopWindowManager.IsCompositionEnabled()) { titleBar.BackColor = Color.Black; try { if (!parentForm.GetWindowAttribute <bool>(DesktopWindowManager.GetWindowAttr.NonClientRenderingEnabled)) { parentForm.SetWindowAttribute(DesktopWindowManager.SetWindowAttr.NonClientRenderingPolicy, DesktopWindowManager.NonClientRenderingPolicy.Enabled); } parentForm.ExtendFrameIntoClientArea(new Padding(0)); NativeMethods.SetWindowPos(this.Handle, IntPtr.Zero, this.Location.X, this.Location.Y, this.Width, this.Height, NativeMethods.SetWindowPosFlags.FrameChanged); if (!SupportFunctions.IsMono) { parentForm?.ExtendFrameIntoClientArea(new Padding(0) { Top = titleBar.Visible ? titleBar.Height : 0 }); } } catch { titleBar.BackColor = commandArea.BackColor; } } else { titleBar.BackColor = commandArea.BackColor; } if (parentForm == null) { return; } if (!SuppressParentFormCaptionSync) { parentForm.Text = Title; } if (!SuppressParentFormIconSync && titleImageIcon != null) { parentForm.Icon = TitleIcon; parentForm.ShowIcon = true; } parentForm.CancelButton = cancelButton; parentForm.AcceptButton = nextButton; parentForm.AutoScaleMode = AutoScaleMode.Font; if (!SupportFunctions.IsMono) { parentForm.SetWindowThemeAttribute(NativeMethods.WindowThemeNonClientAttributes.NoDrawCaption | NativeMethods.WindowThemeNonClientAttributes.NoDrawIcon | NativeMethods.WindowThemeNonClientAttributes.NoSysMenu); } parentForm.Invalidate(); }
public Rect GetCorrectedCellBounds(int row, int col, IntPtr hWnd) { User32.RECT border = DesktopWindowManager.GetWindowBorderSize(hWnd); Rect bounds = GetCellBounds(row, col); bounds.Offset(-border.Left, -border.Top); bounds.Width += border.Left + border.Right; bounds.Height += border.Top + border.Bottom; return(bounds); }
private void InitializeForm() { // Set basic variables this.FormBorderStyle = FormBorderStyle.None; this.Name = "Surface"; this.ShowIcon = false; this.ShowInTaskbar = false; this.StartPosition = FormStartPosition.Manual; if (DesktopWindowManager.IsCompositionEnabled()) { // This window should be on top of every other window this.TopMost = true; // Combine monitor screen sizes and set form size to combined size Rectangle rOutput = new Rectangle(); foreach (Screen oScreen in Screen.AllScreens) { rOutput = Rectangle.Union(rOutput, oScreen.Bounds); } this.Left = Screen.AllScreens.Min(s => s.Bounds.Left); this.Top = Screen.AllScreens.Min(s => s.Bounds.Top); this.Width = rOutput.Width; this.Height = rOutput.Height; // Store offset in class field ScreenOffset = new Size(this.Location); // Reset transparent color this.BackColor = TransparentColor; this.TransparencyKey = TransparentColor; // Set opacity value this.Opacity = GetFormOpacity(HighSign.Properties.Settings.Default.Opacity); // We have composition enabled, use standard mode RenderMethod = RenderMode.Standard; } else { // This window should not be on top, and should be hidden this.TopMost = false; this.Hide(); // We don't have composition enabled, we need to render using compatiblity mode RenderMethod = RenderMode.Compatible; } // Update graphics object with new size InitializeGraphics(); }
/// <summary> /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs"/> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { if (Visible) { VisualStyleRenderer vs = null; //if (Application.RenderWithVisualStyles || DesktopWindowManager.IsCompositionEnabled()) //{ // vs = new VisualStyleRenderer(VisualStyleElement.Window.Caption.Active); // //vs.DrawParentBackground(e.Graphics, base.ClientRectangle, this); //} // Draw image //Rectangle r = DeflateRect(base.ClientRectangle, base.Padding); //if (this.Image != null) //{ // //Rectangle ir = CalcImageRenderBounds(this.Image, r, base.RtlTranslateAlignment(this.ImageAlign)); // if (this.ImageList != null && this.ImageIndex == 0) // { // if (vs != null && !this.IsDesignMode() && DesktopWindowManager.IsCompositionEnabled()) // vs.DrawGlassIcon(e.Graphics, r, this.ImageList, this.ImageIndex); // else // this.ImageList.Draw(e.Graphics, r.X, r.Y, r.Width, r.Height, this.ImageIndex); // } // else // { // if (vs != null && !this.IsDesignMode() && DesktopWindowManager.IsCompositionEnabled()) // vs.DrawGlassImage(e.Graphics, r, this.Image); // else // e.Graphics.DrawImage(this.Image, r); // } //} // Draw text if (this.Text.Length > 0) { if (this.IsDesignMode() || vs == null || !DesktopWindowManager.IsCompositionEnabled()) { //DesktopWindowManager.IsCompositionEnabled() ? SystemBrushes.ActiveCaptionText : Brush br = new SolidBrush(Color.FromArgb(255, 1, 163, 215)); StringFormat sf = new StringFormat(StringFormat.GenericDefault); if (this.GetRightToLeftProperty() == System.Windows.Forms.RightToLeft.Yes) { sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft; } e.Graphics.DrawString(Text, Font, br, base.ClientRectangle, sf); } else { TextFormatFlags tff = CreateTextFormatFlags(base.RtlTranslateAlignment(this.TextAlign), this.AutoEllipsis, this.UseMnemonic); vs.DrawGlowingText(e.Graphics, base.ClientRectangle, Text, Font, ForeColor, tff); } } } }
private void middlePage_Initialize(object sender, AeroWizard.WizardPageInitEventArgs e) { initMiddle = true; if (!System.IO.File.Exists(System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.System), "dwmapi.dll"))) { checkBox1.Enabled = false; } else { checkBox1.Checked = DesktopWindowManager.IsCompositionEnabled(); } wizardControl1.FinishButtonText = "Finish"; initMiddle = false; }
/// <summary> /// Primary function for painting the button. This method should be overridden instead of OnPaint. /// </summary> /// <param name="graphics">The graphics.</param> /// <param name="bounds">The bounds.</param> protected override void PaintButton(Graphics graphics, Rectangle bounds) { if (Application.RenderWithVisualStyles) { try { VisualStyleRenderer rnd = new VisualStyleRenderer(StyleClass, StylePart, (int)ButtonState); if (this.IsDesignMode() || !DesktopWindowManager.IsCompositionEnabled()) { rnd.DrawParentBackground(graphics, bounds, this); rnd.DrawBackground(graphics, bounds); } else { rnd.DrawGlassBackground(graphics, bounds, bounds); } return; } catch { } } else { base.PaintButton(graphics, bounds); /*Rectangle sr = this.ClientRectangle; * sr.Offset(0, sr.Height * ((int)ButtonState - 1)); * graphics.Clear(this.Parent.BackColor); * if (imageStrip != null) * { * Bitmap bmp = imageStrip.Clone(sr, imageStrip.PixelFormat); * if (this.IsDesignMode() || !DesktopWindowManager.IsCompositionEnabled()) * { * base.ImageList.Draw(graphics, bounds.X, bounds.Y, bounds.Width, bounds.Height, ((int)ButtonState - 1)); * } * else * { * VisualStyleRendererExtender.DrawGlassImage(null, graphics, bounds, bmp); * } * } * else * using (Brush br = new SolidBrush(this.BackColor)) * graphics.FillRectangle(br, sr);*/ } }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Control.Paint" /> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs" /> that contains the event data.</param> protected override void OnPaint(PaintEventArgs e) { if (!this.IsDesignMode() && SupportGlass && DesktopWindowManager.IsCompositionEnabled()) { try { e.Graphics.Clear(System.Drawing.Color.Black); } catch { } } else { if (this.IsDesignMode() || rnd == null || !Application.RenderWithVisualStyles) { try { e.Graphics.Clear(BackColor); } catch { } } else { rnd.DrawBackground(e.Graphics, ClientRectangle, e.ClipRectangle); } } base.OnPaint(e); }
public AppShellViewModel() { var desktopManager = new DesktopManager().AddTo(this); var processManager = new WindowManager().AddTo(this); _desktopWindowManager = new DesktopWindowManager().AddTo(this); Title = new ReactiveProperty <string>("Robock"); Status = StatusTextService.Instance.ObserveProperty(w => w.Status).ToReactiveProperty(); Status.Throttle(TimeSpan.FromSeconds(30)).Subscribe(_ => StatusTextService.Instance.Status = "Ready").AddTo(this); Tabs = new ReactiveCollection <TabViewModel> { new AboutTabViewModel() }; Tabs.ToCollectionChanged().Subscribe(w => { if (!(w.Value is DesktopViewModel model) || !model.IsPrimary) { return; } VirtualScreen.SelectedIndex.Value = w.Index; model.IsSelected.Value = true; }); VirtualScreen = new VirtualScreenViewModel(); // Subscribe desktopManager.Desktops.CollectionChangedAsObservable().Subscribe(w => { if (w.Action != NotifyCollectionChangedAction.Add || !(w.NewItems[0] is Desktop desktop)) { return; } var viewModel = new DesktopViewModel(desktop, processManager, _desktopWindowManager).AddTo(this); Tabs.Insert(desktop.No - 1, viewModel); VirtualScreen.Desktops.Insert(desktop.No - 1, viewModel); }).AddTo(this); desktopManager.Initialize(); processManager.Start(); }
private void GlassifyForm(Form form, Graphics g = null) { if (!(DesktopWindowManager.IsCompositionEnabled() && GetGlassEnabled(form)) && !form.IsDesignMode()) { return; } if (g == null) { g = form.CreateGraphics(); } GlassFormProperties prop; if (!formProps.TryGetValue(form, out prop)) { return; } // Paint the glass effect. if (prop.GlassMargins == new Padding(-1)) { g.FillRectangle(Brushes.Black, form.ClientRectangle); } else { using (var r = new Region(form.ClientRectangle)) { r.Exclude(GetNonGlassArea(form, prop)); g.FillRegion(Brushes.Black, r); } } if (!form.IsDesignMode()) { form.ExtendFrameIntoClientArea(prop.GlassMargins); } }
private void UpdateInternal() { if (IsUpdateLocked() || !Visible) { return; } BufferImage.Clear(Bounds.Size); bool aeroEnabled = DesktopWindowManager.IsAeroEnabled() && !DesktopWindowManager.IsAeroOpaque(); if (BackgroundBlur && !aeroEnabled) { DrawCustomBackgroundBlur(BufferImage); } Draw(BufferImage); if (Height == 0) { Height = 1; } Point location = Bounds.Location; Size size = Bounds.Size; IntPtr hdcSrc = BufferImage.Dc; Point point = Point.Empty; Form.UpdateLayered(BufferImage.Dc, ref location, ref size, hdcSrc, ref point, 0); if (BackgroundBlur && aeroEnabled) { var blurBounds = new Rectangle(ContentPadding.Left, ContentPadding.Top, Width - (ContentPadding.Right), Height - (ContentPadding.Bottom)); DesktopWindowManager.EnableBlurBehindWindow(this, blurBounds); } }
protected override void PaintButton(Graphics graphics, Rectangle bounds) { if (Application.RenderWithVisualStyles || DesktopWindowManager.IsCompositionEnabled()) { try { VisualStyleRenderer rnd = new VisualStyleRenderer(StyleClass, StylePart, (int)ButtonState); if (this.IsDesignMode() || !DesktopWindowManager.IsCompositionEnabled()) { rnd.DrawParentBackground(graphics, this.Bounds, this); rnd.DrawBackground(graphics, this.Bounds, bounds); } else { rnd.DrawGlassBackground(graphics, this.Bounds, bounds); } return; } catch { } } //base.PaintButton(graphics, bounds); Rectangle sr = this.ClientRectangle; sr.Offset(0, sr.Height * ((int)ButtonState - 1)); graphics.Clear(this.Parent.BackColor); if (imageStrip != null) { graphics.DrawImage(imageStrip, this.Bounds, sr, GraphicsUnit.Pixel); } else { using (Brush br = new SolidBrush(this.BackColor)) graphics.FillRectangle(br, sr); } }
private void DisableIncompatibleControls() { tbOpacity.Enabled = lblOpacity.Enabled = DesktopWindowManager.IsCompositionEnabled(); }
private static bool HasGlass() { return(isMin6 && DesktopWindowManager.IsCompositionEnabled()); }
public DesktopViewModel(Desktop desktop, WindowManager windowManager, DesktopWindowManager desktopWindowManager) : base($":Desktop: Desktop {desktop.No}") { _desktop = desktop; _desktopWindowManager = desktopWindowManager; // 仮想スクリーン周りの計算 _offsetX = (SystemParameters.VirtualScreenLeft < 0 ? -1 : 1) * SystemParameters.VirtualScreenLeft; _offsetY = (SystemParameters.VirtualScreenTop < 0 ? -1 : 1) * SystemParameters.VirtualScreenTop; // タブの選択状態 IsSelected = new ReactiveProperty <bool>(false); IsSelected.Subscribe(w => { if (w && CanRender()) { RenderEditor(); } else { _desktopWindowManager.Stop(0); _desktopWindowManager.Stop(1); } }).AddTo(this); // DPI 周り DpiService.Instance.ObserveProperty(w => w.CurrentDpi).Where(_ => CanRender()).Subscribe(w => { RenderEditor(); RenderPreview(); }).AddTo(this); // エディター EditorAspectRatio = new ReactiveProperty <string>(FakeImg.Default); EditorAreaLeft = new ReactiveProperty <int>(); EditorAreaTop = new ReactiveProperty <int>(); EditorAreaHeight = new ReactiveProperty <int>(); EditorAreaWidth = new ReactiveProperty <int>(); new[] { EditorAreaLeft, EditorAreaTop, EditorAreaHeight, EditorAreaWidth }.CombineLatest().Throttle(TimeSpan.FromMilliseconds(50)) .Where(w => CanRender()).Subscribe(w => RenderEditor()).AddTo(this); desktopWindowManager.Thumbnails[0].ObserveProperty(w => w.Size).Subscribe(w => { // EditorAspectRatio.Value = FakeImg.HxW(RobockUtil.AspectRatio(w.Width, w.Height)); }).AddTo(this); // 選択範囲 SelectedAreaLeft = new ReactiveProperty <int>(); SelectedAreaTop = new ReactiveProperty <int>(); SelectedAreaHeight = new ReactiveProperty <int>(); SelectedAreaWidth = new ReactiveProperty <int>(); new[] { SelectedAreaLeft, SelectedAreaTop, SelectedAreaHeight, SelectedAreaWidth }.CombineLatest().Throttle(TimeSpan.FromMilliseconds(50)) .Where(w => CanRender()).Subscribe(w => RenderPreview()).AddTo(this); // プレビュー AspectRatio = FakeImg.HxW(RobockUtil.AspectRatio(_desktop.Width, _desktop.Height)); PreviewAreaLeft = new ReactiveProperty <int>(); PreviewAreaTop = new ReactiveProperty <int>(); PreviewAreaHeight = new ReactiveProperty <int>(); PreviewAreaWidth = new ReactiveProperty <int>(); new[] { PreviewAreaLeft, PreviewAreaTop, PreviewAreaHeight, PreviewAreaWidth }.CombineLatest().Throttle(TimeSpan.FromMilliseconds(50)) .Where(w => CanRender()).Subscribe(w => { // RenderPreview(); }); desktopWindowManager.Thumbnails[0] .ObserveProperty(w => w.IsRendering) .Where(w => w && CanRender()) .Subscribe(w => { // RenderPreview(); }).AddTo(this); // 親 GridAreaLeft = new ReactiveProperty <int>(); GridAreaTop = new ReactiveProperty <int>(); // 他 Windows = windowManager.Windows.ToReadOnlyReactiveCollection(w => new WindowViewModel(w)); SelectedWindow = new ReactiveProperty <WindowViewModel>(); SelectedWindow.Where(w => w != null && CanRender()).Subscribe(w => { _desktopWindowManager.Stop(0); _desktopWindowManager.Stop(1); RenderEditor(); }).AddTo(this); ApplyWallpaperCommand = new[] { SelectedWindow.Select(w => w != null), _desktopWindowManager.Thumbnails[0].ObserveProperty(w => w.IsRendering), desktop.ObserveProperty(w => w.IsConnecting).Select(w => !w) }.CombineLatest().Select(w => w.All(v => v)).ToReactiveCommand(); ApplyWallpaperCommand.Subscribe(() => { Task.Run(async() => { await _desktop.Handshake(); var rect = SelectedAreaHeight.Value != 0 ? CalcRenderingRect() : new RECT { top = 0, left = 0, bottom = _desktopWindowManager.Thumbnails[0].Size.Height, right = _desktopWindowManager.Thumbnails[0].Size.Width }; await _desktop.ApplyWallpaper(SelectedWindow.Value.Handle, SelectedAreaHeight.Value != 0 ? CalcRenderingRect() : rect); }); }).AddTo(this); DiscardWallpaperCommand = new[] { SelectedWindow.Select(w => w != null), desktop.ObserveProperty(w => w.IsConnecting) }.CombineLatest().Select(w => w.All(v => v)).ToReactiveCommand(); DiscardWallpaperCommand.Subscribe(() => Task.Run(async() => await _desktop.DiscardWallpaper())).AddTo(this); ReloadWindowsCommand = new ReactiveCommand(); ReloadWindowsCommand.Subscribe(_ => windowManager.ForceUpdate()).AddTo(this); }
void DesktopWindowManager_CompositionChanged(object sender, System.EventArgs e) { events.AppendFormat("{0:s}: Composition ({1})\n", System.DateTime.Now, DesktopWindowManager.IsCompositionEnabled() ? "On" : "Off"); }