private void frmAbout_Load(object sender, EventArgs e) { // AeroGlassをかける if (enableGlass) { this.BackColor = Color.Black; panel1.BackColor = Color.Black; okButton.Font = new Font(Properties.Resources.AboutFont, okButton.Font.Size, okButton.Font.Style); label1.Text = string.Empty; pictureBox1.Visible = false; panel1.DrawText = version; panel1.TextFont = new Font(Properties.Resources.AboutFont, 9, FontStyle.Regular); panel1.TextLocation = new Point(55, 35); panel1.TextSize = new Size(panel1.Width - panel1.TextLocation.X, panel1.Height - panel1.TextLocation.Y); panel1.GlowSize = 10; panel1.DrawImage = icons.icon48; panel1.DrawImageRectangle = new Rectangle(3, 37, 48, 48); ResetDwmBlurBehind(); m_glassMargins = new DwmApi.MARGINS(-1, 0, 0, 0); if (DwmApi.DwmIsCompositionEnabled()) { DwmApi.DwmExtendFrameIntoClientArea(this.Handle, m_glassMargins); } this.FormBorderStyle = FormBorderStyle.FixedDialog; } else { label1.Text = version; pictureBox1.Image = icons.icon48; this.BackColor = SystemColors.Control; } }
// This is a trick to get Windows to treat glass as part of the caption // area I learned from Daniel Moth. protected override void WndProc(ref Message msg) { base.WndProc(ref msg); // let the normal winproc process it const int WM_DWMCOMPOSITIONCHANGED = 0x031E; const int WM_NCHITTEST = 0x84; const int HTCLIENT = 0x01; switch (msg.Msg) { case WM_NCHITTEST: if (HTCLIENT == msg.Result.ToInt32()) { // it's inside the client area // Parse the WM_NCHITTEST message parameters // get the mouse pointer coordinates (in screen coordinates) Point p = new Point(); p.X = (msg.LParam.ToInt32() & 0xFFFF); // low order word p.Y = (msg.LParam.ToInt32() >> 16); // hi order word // convert screen coordinates to client area coordinates p = PointToClient(p); // if it's on glass, then convert it from an HTCLIENT // message to an HTCAPTION message and let Windows handle it from then on if (PointIsOnGlass(p)) { msg.Result = new IntPtr(2); } } break; case WM_DWMCOMPOSITIONCHANGED: OperatingSystem os = Environment.OSVersion; if ((os.Platform == PlatformID.Win32NT) && (os.Version.Major >= 6)) { if (DwmApi.DwmIsCompositionEnabled()) { m_glassMargins = null; if (m_blurRegion != null) { m_blurRegion.Dispose(); m_blurRegion = null; } // ガラス効果が使える enableGlass = true; } // ガラス効果は使えない enableGlass = false; } break; case 0xf: break; } }
/// <summary> /// ウィンドウ透過をON/OFF /// </summary> public void EnableTransparency(bool enable) { if (!IsActive) { return; } if (enable) { // 現在のウィンドウ情報を記憶 StoreWindowSize(); // ウィンドウサイズ変更 if (this.TopmostWhenTransparent) { EnableTopmost(true); } SetSize(this.NormalClientSize); // 全面をGlassにする DwmApi.DwmExtendIntoClientAll(hWnd); // 枠無しウィンドウにする EnableBorderless(true); } else { // ウィンドウスタイルを戻す EnableBorderless(false); // 操作の透過をやめる EnableUnfocusable(false); // 枠のみGlassにする // ※ 本来のウィンドウが枠のみで無かった場合は残念ながら表示が戻りません DwmApi.MARGINS margins = new DwmApi.MARGINS(0, 0, 0, 0); DwmApi.DwmExtendFrameIntoClientArea(hWnd, margins); // ウィンドウサイズ変更 if (this.TopmostWhenTransparent) { EnableTopmost(false); } SetSize(this.NormalWindowSize); } // ウィンドウ再描画 WinApi.ShowWindow(hWnd, WinApi.SW_SHOW); }
private void InitAreo() { if (EnvironmentHelper.SupportAreo && EnvironmentHelper.DwmIsCompositionEnabled) { _glassMargins = new DwmApi.MARGINS(0, this._menuStrip.Height, 0, 0); _RenderMode = RenderMode.TopWindow; if (DwmApi.DwmIsCompositionEnabled()) { DwmApi.DwmExtendFrameIntoClientArea(this.Handle, _glassMargins); } this.Invalidate(); this._menuStrip.Invalidate(); } }
protected override void OnActivated(EventArgs e) { base.OnActivated(e); if (shadowType == MetroFormShadowType.AeroShadow && IsAeroThemeEnabled() && IsDropShadowSupported()) { int val = 2; DwmApi.DwmSetWindowAttribute(Handle, 2, ref val, 4); var m = new DwmApi.MARGINS { cyBottomHeight = 1, cxLeftWidth = 0, cxRightWidth = 0, cyTopHeight = 0 }; DwmApi.DwmExtendFrameIntoClientArea(Handle, ref m); } }
/// <summary> /// ウィンドウ透過をON/OFF /// </summary> public void EnableTransparent(bool enable) { if (!IsActive) { return; } if (enable) { // 現在のウィンドウ情報を記憶 StoreWindowSize(); // 全面をGlassにする DwmApi.DwmExtendIntoClientAll(hWnd); // 枠無しウィンドウにする EnableBorderless(true); // ウィンドウ再描画 WinApi.ShowWindow(hWnd, WinApi.SW_SHOW); SetSize(GetSize()); } else { // ウィンドウスタイルを戻す EnableBorderless(false); // 操作の透過をやめる EnableClickThrough(false); // 枠のみGlassにする // ※ 本来のウィンドウが枠のみで無かった場合は残念ながら表示が戻りません DwmApi.MARGINS margins = new DwmApi.MARGINS(0, 0, 0, 0); DwmApi.DwmExtendFrameIntoClientArea(hWnd, margins); // サイズ変更イベントを発生させる SetSize(GetSize()); } // ウィンドウ再描画 WinApi.ShowWindow(hWnd, WinApi.SW_SHOW); }
/// <summary> /// Removes the aero glass composition for this form depending on the form border style that the form had the last time the aero glass composition was enabled for it. /// No checks and validation are made, so use it carefully. /// </summary> /// <returns> /// If it succeeded, it returns 0 (DwmApi.HRESULT.S_OK), otherwise it returns the windows error code. /// </returns> protected DwmApi.HRESULT RemoveAeroGlassCompositionCore() { DwmApi.HRESULT hResult; if (this.FormBorderStylePrevAeroGlassCompositionEnable.Value == FormBorderStyle.None) { DwmApi.DWM_BLURBEHIND dwm_blurBehind; dwm_blurBehind = new DwmApi.DWM_BLURBEHIND(false); hResult = this.DwmEnableBlurBehindWindow(ref dwm_blurBehind); } else { DwmApi.MARGINS margins; margins = new DwmApi.MARGINS(); hResult = this.DwmExtendFrameIntoClientArea(ref margins); } return(hResult); }
private void InitAreo() { if (EnvironmentHelper.SupportAreo && EnvironmentHelper.DwmIsCompositionEnabled) { _glassMargins = new DwmApi.MARGINS(0, this._menuStrip.Height, 0, 0); //m_glassMargins = new DwmApi.MARGINS(0, 150 ,0, 0); _RenderMode = RenderMode.TopWindow; if (DwmApi.DwmIsCompositionEnabled()) { DwmApi.DwmExtendFrameIntoClientArea(this.Handle, _glassMargins); } // reset window border style in case DwmEnableBlurBehindWindow was set //this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow; this.Invalidate(); this._menuStrip.Invalidate(); } }
/// <summary> /// ウィンドウ透過をON/OFF /// </summary> public void EnableTransparency(bool enable) { if (!IsActive) return; if (enable) { // 現在のウィンドウ情報を記憶 StoreWindowSize(); // ウィンドウサイズ変更 EnableTopmost(this.TopmostWhenTransparent); SetSize(this.NormalClientSize); // 全面をGlassにする DwmApi.DwmExtendIntoClientAll (hWnd); // 枠無しウィンドウにする EnableBorderless(true); } else { // ウィンドウスタイルを戻す EnableBorderless(false); // 枠のみGlassにする // ※ 本来のウィンドウが枠のみで無かった場合は残念ながら表示が戻りません DwmApi.MARGINS margins = new DwmApi.MARGINS (0, 0, 0, 0); DwmApi.DwmExtendFrameIntoClientArea (hWnd, margins); // ウィンドウサイズ変更 EnableTopmost(false); SetSize(this.NormalWindowSize); } // ウィンドウ再描画 WinApi.ShowWindow(hWnd, WinApi.SW_SHOW); }
private void GlassAb_Load(object sender, EventArgs e) { OpacityT.Start(); try { if (Environment.OSVersion.Version.Major > 5) { ResetDwmBlurBehind(); this.Paint+=new PaintEventHandler(OnPaint); m_glassMargins = new DwmApi.MARGINS(-1, 0, 0, 0); m_RenderMode = RenderMode.EntireWindow; IsGlass = true; if (DwmApi.DwmIsCompositionEnabled()) DwmApi.DwmExtendFrameIntoClientArea(this.Handle, m_glassMargins); // reset window border style in case DwmEnableBlurBehindWindow was set //this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow; this.Invalidate(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка"); } //this.Text = IsGlass.ToString() + " " + Environment.OSVersion.Version.Major.ToString(); //this.SetStyle(ControlStyles.OptimizedDoubleBuffer,true); //moveLine.Start(); }
protected override void WndProc(ref Message msg) { base.WndProc(ref msg); // let the normal winproc process it if (IsGlass) { const int WM_DWMCOMPOSITIONCHANGED = 0x031E; const int WM_NCHITTEST = 0x84; const int HTCLIENT = 0x01; switch (msg.Msg) { case WM_NCHITTEST: if (HTCLIENT == msg.Result.ToInt32()) { // it's inside the client area // Parse the WM_NCHITTEST message parameters // get the mouse pointer coordinates (in screen coordinates) Point p = new Point(); p.X = (msg.LParam.ToInt32() & 0xFFFF);// low order word p.Y = (msg.LParam.ToInt32() >> 16); // hi order word // convert screen coordinates to client area coordinates p = PointToClient(p); // if it's on glass, then convert it from an HTCLIENT // message to an HTCAPTION message and let Windows handle it from then on if (PointIsOnGlass(p)) msg.Result = new IntPtr(2); } break; case WM_DWMCOMPOSITIONCHANGED: if (!DwmApi.DwmIsCompositionEnabled()) { m_RenderMode = RenderMode.None; m_glassMargins = null; if (m_blurRegion != null) { m_blurRegion.Dispose(); m_blurRegion = null; } } break; } } }
/// <summary> /// Applies the aero glass composition using the 'ExtendFrameIntoClientArea' method (see https://msdn.microsoft.com/en-us/library/windows/desktop/aa969512%28v=vs.85%29.aspx). /// No checks and validation are made, so use it carefully. /// </summary> /// <param name="pMarInset"> /// A 'DwmApi.MARGINS' structure that describes the margins to use when extending the frame into the client area /// </param> /// <returns> /// If it succeeded, it returns 0 (DwmApi.HRESULT.S_OK), otherwise it returns the windows error code. /// </returns> protected DwmApi.HRESULT DwmExtendFrameIntoClientArea([In] ref DwmApi.MARGINS pMarInset) { return(DwmApi.DwmExtendFrameIntoClientArea(this.Handle, ref pMarInset)); }
protected override void WndProc(ref Message m) { if (DesignMode) { base.WndProc(ref m); return; } switch (m.Msg) { case (int)WinApi.Messages.WM_SYSCOMMAND: var sc = m.WParam.ToInt32() & 0xFFF0; switch (sc) { case (int)WinApi.Messages.SC_MOVE: if (!Movable) { return; } break; case (int)WinApi.Messages.SC_MAXIMIZE: break; case (int)WinApi.Messages.SC_RESTORE: break; } break; case (int)WinApi.Messages.WM_NCLBUTTONDBLCLK: case (int)WinApi.Messages.WM_LBUTTONDBLCLK: if (!MaximizeBox) { return; } break; case (int)WinApi.Messages.WM_NCHITTEST: var ht = HitTestNca(m.HWnd, m.WParam, m.LParam); if (ht != WinApi.HitTest.HTCLIENT) { m.Result = (IntPtr)ht; return; } break; case (int)WinApi.Messages.WM_DWMCOMPOSITIONCHANGED: break; case WmNcpaint: // box shadow if (_mAeroEnabled) { var v = 2; DwmApi.DwmSetWindowAttribute(Handle, 2, ref v, 4); var margins = new DwmApi.MARGINS(1, 1, 1, 1); DwmApi.DwmExtendFrameIntoClientArea(Handle, ref margins); } break; } base.WndProc(ref m); switch (m.Msg) { case (int)WinApi.Messages.WM_GETMINMAXINFO: OnGetMinMaxInfo(m.HWnd, m.LParam); break; case (int)WinApi.Messages.WM_SIZE: if (_windowButtonList != null) { YamuiFormButton btn; _windowButtonList.TryGetValue(WindowButtons.Maximize, out btn); if (WindowState == FormWindowState.Normal && btn != null) { btn.Text = @"1"; } if (WindowState == FormWindowState.Maximized && btn != null) { btn.Text = @"2"; } } break; } if (m.Msg == WmNchittest && (int)m.Result == Htclient) // drag the form { m.Result = (IntPtr)Htcaption; } }
/// <summary> /// ウィンドウを再描画させる /// </summary> /// <param name="item"></param> private void UpdateWindow(WindowItem item) { long ws; long wsex; IntPtr hWnd = item.Handle; if (!WinApi.IsWindow(hWnd)) { comboBoxWindowClass.Items.Remove(item); return; // ウィンドウが存在しない } ws = item.OriginalStyles; wsex = item.OriginalExStyles; // ウィンドウスタイルを初期状態に一度戻す WinApi.SetWindowLong(hWnd, WinApi.GWL_EXSTYLE, wsex); WinApi.SetWindowLong(hWnd, WinApi.GWL_STYLE, ws); // 操作を透過させる(受け付けなくする) if (item.Clickthrough) { wsex |= WinApi.WS_EX_LAYERED; wsex |= WinApi.WS_EX_TRANSPARENT; } if (item.ColorKey || item.HasAlpha) { wsex |= WinApi.WS_EX_LAYERED; } if (item.NoBorder) { // 枠無しウィンドウにする ws &= ~WinApi.WS_OVERLAPPEDWINDOW; } // ウィンドウスタイルを適用 WinApi.SetWindowLong(hWnd, WinApi.GWL_EXSTYLE, wsex); WinApi.SetWindowLong(hWnd, WinApi.GWL_STYLE, ws); byte alpha = 0xFF; if (item.HasAlpha) { alpha = (byte)(0xFF * item.Opacity / 100); } if (item.ColorKey || item.HasAlpha) { uint flags = (item.ColorKey ? WinApi.LWA_COLORKEY : 0) | (item.HasAlpha? WinApi.LWA_ALPHA : 0); WinApi.COLORREF crKey = new WinApi.COLORREF(item.KeyColor.R, item.KeyColor.G, item.KeyColor.B); WinApi.SetLayeredWindowAttributes(hWnd, crKey, alpha, flags); } else { //WinApi.SetLayeredWindowAttributes(hWnd, new WinApi.COLORREF(0), 0xFF, 0); } WinApi.RECT rect; WinApi.GetWindowRect(hWnd, out rect); // 一度強制的にリサイズをする WinApi.SetWindowPos( hWnd, (item.Topmost ? WinApi.HWND_TOPMOST : WinApi.HWND_NOTOPMOST), rect.left, rect.top, (rect.right - rect.left + 1), (rect.bottom - rect.top), WinApi.SWP_NOMOVE | WinApi.SWP_NOZORDER | WinApi.SWP_FRAMECHANGED | WinApi.SWP_NOOWNERZORDER | WinApi.SWP_NOACTIVATE | WinApi.SWP_ASYNCWINDOWPOS ); // 再描画と同時に最前面状態を切り替え WinApi.SetWindowPos( hWnd, (item.Topmost? WinApi.HWND_TOPMOST : WinApi.HWND_NOTOPMOST), rect.left, rect.top, (rect.right - rect.left), (rect.bottom - rect.top), WinApi.SWP_ASYNCWINDOWPOS | WinApi.SWP_FRAMECHANGED | WinApi.SWP_NOCOPYBITS | WinApi.SWP_NOACTIVATE | WinApi.SWP_SHOWWINDOW ); // 透明化状態を切り替え if (item.Transparent) { if (!item.IsChild) { // エアロによる透明化範囲を全体に適用 DwmApi.DwmExtendIntoClientAll(hWnd); } } else { if (!item.IsChild) { // DWMによる透明化範囲をなくす DwmApi.MARGINS margins = new DwmApi.MARGINS(0, 0, 0, 0); DwmApi.DwmExtendFrameIntoClientArea(hWnd, ref margins); //DwmApi.DwmSetWindowAttribute(hWnd, DwmApi.DWMWINDOWATTRIBUTE.DWMWA_NCRENDERING_POLICY, DwmApi.DWMNCRENDERINGPOLICY.DWMNCRP_DISABLED, Marshal.SizeOf(typeof(int))); } } }