/// <summary> /// Sets opacity and/or transparent color. /// </summary> /// <param name="allowTransparency">Set or remove WS_EX_LAYERED style that is required for transparency. If false, other parameters are not used.</param> /// <param name="opacity">Opacity from 0 (completely transparent) to 255 (opaque). Does not change if null. If less than 0 or greater than 255, makes 0 or 255.</param> /// <param name="colorKey">Make pixels of this color completely transparent. Does not change if null. The alpha byte is not used.</param> /// <exception cref="AuWndException"/> /// <remarks> /// Uses API <msdn>SetLayeredWindowAttributes</msdn>. /// On Windows 7 works only with top-level windows, on newer OS also with controls. /// </remarks> public void SetTransparency(bool allowTransparency, int?opacity = null, ColorInt?colorKey = null) { var est = ExStyle; bool layered = (est & WS2.LAYERED) != 0; if (allowTransparency) { uint col = 0, f = 0; byte op = 0; if (colorKey != null) { f |= 1; col = (uint)colorKey.GetValueOrDefault().ToBGR(); } if (opacity != null) { f |= 2; op = (byte)AMath.MinMax(opacity.GetValueOrDefault(), 0, 255); } if (!layered) { SetExStyle(est | WS2.LAYERED); } if (!Api.SetLayeredWindowAttributes(this, col, op, f)) { ThrowUseNative(); } } else if (layered) { SetExStyle(est & ~WS2.LAYERED); //tested: resets attributes, ie after adding WS2.LAYERED the window will be normal } }
static AVersion() { Api.RTL_OSVERSIONINFOW x = default; x.dwOSVersionInfoSize = Api.SizeOf(x); if (0 == Api.RtlGetVersion(ref x)) { _winver = AMath.MakeUshort(x.dwMinorVersion, x.dwMajorVersion); //use this because Environment.OSVersion.Version (GetVersionEx) lies, even if we have correct manifest when is debugger present } else { Debug.Fail("RtlGetVersion"); var v = Environment.OSVersion.Version; _winver = AMath.MakeUshort(v.Minor, v.Major); } _minWin8 = _winver >= Win8; _minWin8_1 = _winver >= Win8_1; _minWin10 = _winver >= Win10; _is32BitOS = sizeof(IntPtr) == 4 && !(Api.IsWow64Process(Api.GetCurrentProcess(), out _isWow64) && _isWow64); }
//Alternative to returning HTCAPTION on WM_NCITTEST. //void _DragMoveWindow() //{ // _tb._InMoveSize(true); // try { // var w = (AWnd)this; // var pp = AMouse.XY; // Util.ADragDrop.SimpleDragDrop(w, MButtons.Left, o => { // if(o.Msg.message != Api.WM_MOUSEMOVE) return; // var p = AMouse.XY; if(p == pp) return; // var r = w.Rect; // w.MoveLL(r.left + (p.x - pp.x), r.top + (p.y - pp.y)); // pp = p; // }); // } // finally { _tb._InMoveSize(false); } //} bool _WmNchittest(ref Message m) { int h; if (ModifierKeys == Keys.Shift) //move { h = Api.HTCAPTION; } else //resize? { if (_tb._border == TBBorder.None || (!_tb.Sizable && _tb._border < TBBorder.Thick)) { return(false); } var w = this.Hwnd(); LPARAM xy = m.LParam; int x = AMath.LoShort(xy), y = AMath.HiShort(xy); if (_tb.Sizable) { RECT r; int b; if (_tb._border < TBBorder.ThreeD) { b = (int)_tb._border; r = w.Rect; } else { w.GetWindowInfo_(out var k); r = k.rcWindow; b = k.cxWindowBorders; } int bx = Math.Min(b, r.Width / 2), by = Math.Min(b, r.Height / 2); int x1 = r.left + bx, x2 = r.right - bx - 1, y1 = r.top + by, y2 = r.bottom - by - 1; if (x < x1) { h = y < y1 ? Api.HTTOPLEFT : (y > y2 ? Api.HTBOTTOMLEFT : Api.HTLEFT); } else if (x > x2) { h = y < y1 ? Api.HTTOPRIGHT : (y > y2 ? Api.HTBOTTOMRIGHT : Api.HTRIGHT); } else if (y < y1) { h = Api.HTTOP; } else if (y > y2) { h = Api.HTBOTTOM; } else { return(false); } } else //disable resizing if border is natively sizable { if (_tb._border < TBBorder.Thick) { return(false); } w.GetWindowInfo_(out var k); k.rcWindow.Inflate(-k.cxWindowBorders, -k.cyWindowBorders); if (k.rcWindow.Contains(x, y)) { return(false); } h = Api.HTBORDER; } } m.Result = (IntPtr)h; return(true); }
public void SetLevel(int level) { this.level = (ushort)AMath.MinMax(level, 0, 0xffff); }