public static extern IntPtr CreateWindowEx( WS_EX dwExStyle, string lpClassName, string lpWindowName, WS dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam);
public MessageWindow(CS classStyle, WS style, WS_EX exStyle, Rect location, string name, WndProc callback) { // A null callback means just use DefWindowProc. _wndProcCallback = callback; _className = "MessageWindowClass+" + Guid.NewGuid().ToString(); var wc = new WNDCLASSEX { cbSize = Marshal.SizeOf(typeof(WNDCLASSEX)), style = classStyle, lpfnWndProc = s_WndProc, hInstance = NativeMethods.GetModuleHandle(null), hbrBackground = NativeMethods.GetStockObject(StockObject.NULL_BRUSH), lpszMenuName = "", lpszClassName = _className, }; NativeMethods.RegisterClassEx(ref wc); GCHandle gcHandle = default(GCHandle); try { gcHandle = GCHandle.Alloc(this); IntPtr pinnedThisPtr = (IntPtr)gcHandle; Handle = NativeMethods.CreateWindowEx( exStyle, _className, name, style, (int)location.X, (int)location.Y, (int)location.Width, (int)location.Height, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, pinnedThisPtr); } finally { gcHandle.Free(); } _dispatcher = Dispatcher.CurrentDispatcher; }
/// <summary> /// Obtain the edge vertical and horizontal offset /// based on the current type of window /// </summary> /// <remarks> /// ThreeDBorderWindow : WINDOWEDGE + CLIENTEDGE + THICKFRAME /// SingleBorderWindow : WINDOWEDGE + THICKFRAME /// ToolWindow : WINDOWEDGE + TOOLWINDOW + THICKFRAME /// </remarks> /// <returns>The width and height offset</returns> private EdgeOffset GetEdgeOffset() { EdgeOffset edgeOffset = new EdgeOffset(); WS_EX ws_ex = UnsafeNativeMethods.GetWindowStyleEx(_hWnd); WS ws = UnsafeNativeMethods.GetWindowStyle(_hWnd); if ((ws_ex & WS_EX.WINDOWEDGE) == WS_EX.WINDOWEDGE) { edgeOffset.FixedFrame = new Size() { Width = SystemParameters.FixedFrameVerticalBorderWidth, Height = SystemParameters.FixedFrameHorizontalBorderHeight }; } if ((ws_ex & WS_EX.CLIENTEDGE) == WS_EX.CLIENTEDGE) { edgeOffset.ThickBorder = new Size() { Width = SystemParameters.ThickVerticalBorderWidth, Height = SystemParameters.ThickHorizontalBorderHeight }; } if ((ws_ex & WS_EX.TOOLWINDOW) == WS_EX.TOOLWINDOW) { edgeOffset.ThinBorder = new Size() { Width = SystemParameters.ThinVerticalBorderWidth, Height = SystemParameters.ThinHorizontalBorderHeight }; } if ((ws & WS.THICKFRAME) == WS.THICKFRAME) { edgeOffset.ResizeFrame = new Size() { Width = SystemParameters.ResizeFrameVerticalBorderWidth, Height = SystemParameters.ResizeFrameHorizontalBorderHeight }; } return(edgeOffset); }
public MessageWindow(CS classStyle, WS style, WS_EX exStyle, Rect location, string name, WndProc callback) { // A null callback means just use DefWindowProc. _wndProcCallback = callback; _className = "MessageWindowClass+" + Guid.NewGuid().ToString(); var wc = new WNDCLASSEX { cbSize = Marshal.SizeOf(typeof(WNDCLASSEX)), style = classStyle, lpfnWndProc = s_WndProc, hInstance = NativeMethods.GetModuleHandle(null), hbrBackground = NativeMethods.GetStockObject(StockObject.NULL_BRUSH), lpszMenuName = "", lpszClassName = _className, }; NativeMethods.RegisterClassEx(ref wc); var gcHandle = default(GCHandle); try { gcHandle = GCHandle.Alloc(this); var pinnedThisPtr = (IntPtr)gcHandle; Handle = NativeMethods.CreateWindowEx( exStyle, _className, name, style, (int)location.X, (int)location.Y, (int)location.Width, (int)location.Height, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, pinnedThisPtr); } finally { gcHandle.Free(); } }
public unsafe static IntPtr CreateWindowExW( WS_EX dwExStyle, string lpClassName, string lpWindowName, WS dwStyle, int X, int Y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInst, object lpParam) { fixed(char *c = lpClassName) { return(CreateWindowExW(dwExStyle, c, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInst, lpParam)); } }
private static void WindowButtons_Changed(Window window, DpChangedEventArgs <WindowButton> args) { window.InvokeOnHandle(() => { WS style = window.GetWindowStyle(); WS_EX styleEx = window.GetWindowStyleEx(); SetBitIf(ref style, WS.SYSMENU, args.NewValue & WindowButton.System); SetBitIf(ref style, WS.MINIMIZEBOX, args.NewValue & WindowButton.Minimize); SetBitIf(ref style, WS.MAXIMIZEBOX, args.NewValue & WindowButton.Maximize); SetBitIf(ref styleEx, WS_EX.CONTEXTHELP, args.NewValue & WindowButton.Help); SetBitIf(ref styleEx, WS_EX.DLGMODALFRAME, ~(args.NewValue & WindowButton.Icon)); window.SetWindowStyle(style); window.SetWindowStyleEx(styleEx); if ((args.NewValue & WindowButton.Icon) == 0) { window.ClearWindowIcons(); } window.SetWindowPos(flags: SWP.FRAMECHANGED); }); }
public static bool ChangeWindowStyles(IntPtr handle, WS stylesToAdd, WS stylesToRemove, WS_EX extStylesToAdd, WS_EX extStyleToRemove) { try { var styles = Win32.GetWindowLong(handle, GWL.STYLE).ToWS(); var extStyles = Win32.GetWindowLong(handle, GWL.EXSTYLE).ToWS_EX(); styles |= stylesToAdd; styles &= ~stylesToRemove; extStyles |= extStylesToAdd; extStyles &= ~extStyleToRemove; Win32.SetWindowLong(handle, GWL.STYLE, new IntPtr((uint)styles)); Win32.SetWindowLong(handle, GWL.EXSTYLE, new IntPtr((uint)extStyles)); return(true); } catch { return(false); } }
public static void RemoveIcon(this Window window) { // Get this window's handle IntPtr hwnd = GetWindowHandle(window); WS_EX extendedStyle = GetWindowStyleEx(hwnd); Debug.Assert(0 != extendedStyle, "Could not get extended window style"); if (0 != extendedStyle) { // Change the extended window style to not show a window icon SetWindowStyleEx(hwnd, extendedStyle | WS_EX.DLGMODALFRAME); // Reset the large and small icon setting SetIcon(hwnd, ICON.SMALL); SetIcon(hwnd, ICON.BIG); // Update the window's non-client area to reflect the changes RefreshNonClientArea(hwnd); } }
public static IntPtr CreateWindowEx( WS_EX dwExStyle, string lpClassName, string lpWindowName, WS dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam) { var ret = _CreateWindowEx(dwExStyle, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam); if (ret == IntPtr.Zero) { HRESULT.ThrowLastError(); } return(ret); }
public static StrongHWND CreateWindowEx(WS_EX dwExStyle, string lpClassName, string lpWindowName, WS dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam) { HWND hwnd = NativeMethods.CreateWindowEx(dwExStyle, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam); return new StrongHWND(hwnd.DangerousGetHandle()); }
public static extern int SetWindowLong(IntPtr hWnd, GWL nIndex, WS_EX dsNewLong);
public static WS_EX SetWindowStyleEx(this Window window, WS_EX style) { return((WS_EX)SetWindowLong(GetHandle(window), GWL.EXSTYLE, (uint)style)); }
internal static WS_EX SetWindowStyleEx(IntPtr hWnd, WS_EX dwNewLong) { return((WS_EX)SetWindowLongPtr(hWnd, GWL.EXSTYLE, (IntPtr)(int)dwNewLong)); }
private static extern IntPtr CreateWindowExW(WS_EX dwExStyle, string lpClassName, string lpWindowName, WS dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam);
public static WS_EX SetWindowStyleEx (this Window window, WS_EX style) { return (WS_EX)SetWindowLong(GetHandle(window), GWL.EXSTYLE, (uint)style); }
private static extern bool _AdjustWindowRectEx(ref RECT lpRect, WS dwStyle, [MarshalAs(UnmanagedType.Bool)] bool bMenu, WS_EX dwExStyle);
/// <summary> /// /// </summary> /// <param name="hwnd"></param> /// <param name="value"></param> public static void SetWindowExtendedStyle(IntPtr hwnd, WS_EX value) { NativeMethods.SetWindowLong(hwnd, GWL.EXSTYLE, (int)value); }
public static StrongHWND CreateWindowEx(WS_EX dwExStyle, string lpClassName, string lpWindowName, WS dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam) { HWND hwnd = NativeMethods.CreateWindowEx(dwExStyle, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam); return(new StrongHWND(hwnd.DangerousGetHandle())); }
private static void SetWindowStyleEx(IntPtr hwnd, WS_EX style) => SetWindowLong(hwnd, GWL.EXSTYLE, (int)style);
private static extern IntPtr CreateWindowEx(WS_EX dwExStyle, string lpszClassName, string lpszWindowName, WS style, int x, int y, int width, int height, IntPtr hWndParent, IntPtr hMenu, IntPtr hInst, [MarshalAs(UnmanagedType.AsAny)] object pvParam);
private static extern bool AdjustWindowRectEx_1(ref RECT lpRect, WS dwStyle, bool bMenu, WS_EX dwExStyle);
public static extern HWND CreateWindowEx(WS_EX dwExStyle, string lpClassName, string lpWindowName, WS dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam);
public static extern bool AdjustWindowRectEx(ref RECT lpRect, WS style, bool bMenu, WS_EX exStyle);
public static RECT AdjustWindowRectEx(RECT lpRect, WS dwStyle, bool bMenu, WS_EX dwExStyle) { // Native version modifies the parameter in place. if (!_AdjustWindowRectEx(ref lpRect, dwStyle, bMenu, dwExStyle)) { HRESULT.ThrowLastError(); } return lpRect; }
private static extern IntPtr _CreateWindowEx(WS_EX dwExStyle, [MarshalAs(UnmanagedType.LPWStr)] string lpClassName, [MarshalAs(UnmanagedType.LPWStr)] string lpWindowName, WS dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam);
// ExStyle public static WS_EX SetWindowStyleEx(IntPtr hWnd, WS_EX value) { return((WS_EX)SetWindowLong(hWnd, (int)GWL.EXSTYLE, (int)value)); }
internal static bool SetWindowStyleEx(IntPtr hWnd, WS_EX ws_ex, bool enable) { return(SetWS(hWnd, (uint)ws_ex, (int)GWL.EXSTYLE, enable)); }
public static IntPtr CreateWindowEx( WS_EX dwExStyle, string lpClassName, string lpWindowName, WS dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam) { IntPtr ret = _CreateWindowEx(dwExStyle, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam); if (IntPtr.Zero == ret) { HRESULT.ThrowLastError(); } return ret; }
private static extern IntPtr _CreateWindowEx( WS_EX dwExStyle, [MarshalAs(UnmanagedType.LPWStr)] string lpClassName, [MarshalAs(UnmanagedType.LPWStr)] string lpWindowName, WS dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam);
public static extern bool AdjustWindowRectExForDpi(ref tagRECT lpRect, WS dwStyle, bool bMenu, WS_EX dwExStyle, int dpi);