internal void StylesToProperty() { StyleToProperty(); foreach (StyleInfo si in styles) { if (si.Extended) { WindowExStyles e; if (!Enum.TryParse <WindowExStyles>(si.Name, out e)) { Diagnostic.WriteLine("WARNING! Unknown style name: " + si.Name); continue; } ExStyle |= e; } else { WindowStyles e; if (!Enum.TryParse <WindowStyles>(si.Name, out e)) { Diagnostic.WriteLine("WARNING! Unknown style name: " + si.Name); continue; } Style |= e; } #if DEBUG Diagnostic.WriteLine(string.Concat("WARNING: residual style ", si.Name, " for control ", Id)); #endif } }
protected override bool InspectWindow(WindowHandle handle) { //Reject empty titles if (string.IsNullOrEmpty(handle.Title)) { return(true); } //Accept windows that // - are visible // - do not have a parent // - have no owner and are not Tool windows OR // - have an owner and are App windows if ((long)Win32.GetParent(handle.Handle) == 0) { bool hasOwner = (long)Win32.GetWindow(handle.Handle, GetWindowMode.GW_OWNER) != 0; WindowExStyles exStyle = (WindowExStyles)Win32.GetWindowLong(handle.Handle, WindowLong.ExStyle); if (((exStyle & WindowExStyles.ToolWindow) == 0 && !hasOwner) || //unowned non-tool window ((exStyle & WindowExStyles.AppWindow) == WindowExStyles.AppWindow && hasOwner)) { //owned application window _list.Add(handle); } } return(true); }
/// <summary> /// The get window styles. /// </summary> /// <param name="state"> /// The state. /// </param> /// <returns> /// The <see cref="Tuple"/>. /// </returns> private Tuple <WindowStyles, WindowExStyles, ShowWindowCommands> GetWindowStyles(WindowState state) { WindowStyles styles = WindowStyles.WS_OVERLAPPEDWINDOW | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS; WindowExStyles exStyles = WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_WINDOWEDGE; switch (state) { case WindowState.Normal: return(new Tuple <WindowStyles, WindowExStyles, ShowWindowCommands>(styles, exStyles, ShowWindowCommands.SW_SHOWNORMAL)); case WindowState.Maximize: { styles = WindowStyles.WS_OVERLAPPEDWINDOW | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_MAXIMIZE; exStyles = WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_WINDOWEDGE; return(new Tuple <WindowStyles, WindowExStyles, ShowWindowCommands>(styles, exStyles, ShowWindowCommands.SW_SHOWMAXIMIZED)); } case WindowState.Fullscreen: { styles = WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_MAXIMIZE; exStyles = WindowExStyles.WS_EX_TOOLWINDOW; return(new Tuple <WindowStyles, WindowExStyles, ShowWindowCommands>(styles, exStyles, ShowWindowCommands.SW_SHOWMAXIMIZED)); } } return(new Tuple <WindowStyles, WindowExStyles, ShowWindowCommands>(styles, exStyles, ShowWindowCommands.SW_SHOWNORMAL)); }
private TWindow CreateWindowCoreFromInstance <TWindow>(TWindow win, string text, WindowStyles styles, WindowExStyles exStyles, int x, int y, int width, int height, IntPtr hParent, IntPtr hMenu, uint controlStyles) where TWindow : WindowCore { VerifyWindowInstanceNotInitialized(win); ((INativeConnectable)win).SetFactory(this); var winGcHandle = GCHandle.Alloc(win); var extraParam = GCHandle.ToIntPtr(winGcHandle); var hwnd = IntPtr.Zero; try { hwnd = User32Methods.CreateWindowEx(exStyles, this.ClassName, text, styles | (WindowStyles)controlStyles, x, y, width, height, hParent, hMenu, this.InstanceHandle, extraParam); } finally { winGcHandle.Free(); if (hwnd == IntPtr.Zero) { win.Dispose(); ThrowWindowCreationFailed(); } } return(win); }
public MonoView(XplatUICocoa driver, CGRect frameRect, WindowStyles style, WindowExStyles exStyle) : base(frameRect) { this.driver = driver; this.Style = style; this.ExStyle = exStyle; this.eventResponder = new WindowsEventResponder(driver, this); base.NextResponder = eventResponder; }
public TWindow CreateWindowCore <TWindow>(Func <TWindow> instanceCreator, string text, WindowStyles styles, WindowExStyles exStyles, int x, int y, int width, int height, IntPtr hParent, IntPtr hMenu, uint controlStyles) where TWindow : WindowCore { return(this.CreateWindowCoreFromInstance(instanceCreator(), text, styles, exStyles, x, y, width, height, hParent, hMenu, controlStyles)); }
public static bool InverseAdjustWindowRectEx( ref Rectangle lpRect, WindowStyles dwStyle, bool hasMenu, WindowExStyles dwExStyle) { var rc = new Rectangle(); var res = User32Methods.AdjustWindowRectEx(ref rc, dwStyle, hasMenu, dwExStyle); if (res) Subtract(ref lpRect, ref rc); }
public static void GetFullWindowRect(WindowStyles style, WindowExStyles styleEx, uint dpi, ref Rect rect) { if (IsWindows10AnniversaryUpdateOrGreaterWin32) { User32.AdjustWindowRectExForDpi(ref rect, style, false, styleEx, dpi); } else { User32.AdjustWindowRectEx(ref rect, style, false, styleEx); } }
protected TWindow CreateWindow <TWindow>(Func <TWindow> func, string title) where TWindow : WindowCore { var constructionParams = new FrameWindowConstructionParams(); WindowExStyles exStyles = WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_NOREDIRECTIONBITMAP; TWindow window = windowFactory.CreateWindow(func, title, constructionParams: constructionParams, exStyles: exStyles); windows.Add(window); return(window); }
public static extern IntPtr CreateWindowEx( WindowExStyles dwExStyle, string lpClassName, string lpWindowName, WindowStyles dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hwndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam);
public void PrintStyle(Control control, WindowExStyles s) { CreateParams cp = (CreateParams)control.GetType().GetProperty("CreateParams", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(control, null); if ((cp.Style & (int)s) == (int)s) { Console.WriteLine("=>Style: {0}:{1}", PlanStyle(s), (int)s); } if ((cp.ExStyle & (int)s) == (int)s) { Console.WriteLine("=>ExStyle: {0}:{1}", PlanStyle(s), (int)s); } }
public static NativeWindow CreateExternalWindowCore(string className, string text, WindowStyles styles, WindowExStyles exStyles, int x, int y, int width, int height, IntPtr hParent, IntPtr hMenu, IntPtr hInstance, IntPtr extraParams, uint controlStyles) { var hwnd = User32Methods.CreateWindowEx(exStyles, className, text, styles | (WindowStyles)controlStyles, x, y, width, height, hParent, hMenu, hInstance, extraParams); if (hwnd == IntPtr.Zero) { ThrowWindowCreationFailed(); } return(CreateWindowFromHandle(hwnd)); }
private void AdjustWindowStyle(IntPtr handle) { uint lStyle = Methods.GetWindowLong(handle, (int)WindowLongParam.GWL_STYLE); WindowStyles flagsToDisable = ~(WindowStyles.WS_CAPTION | WindowStyles.WS_THICKFRAME | WindowStyles.WS_MINIMIZE | WindowStyles.WS_MAXIMIZE | WindowStyles.WS_SYSMENU); lStyle &= (uint)flagsToDisable; Methods.SetWindowLong(handle, (int)WindowLongParam.GWL_STYLE, lStyle); uint lExStyle = Methods.GetWindowLong(handle, (int)WindowLongParam.GWL_EXSTYLE); WindowExStyles flagsToDisableEx = ~(WindowExStyles.WS_EX_DLGMODALFRAME | WindowExStyles.WS_EX_CLIENTEDGE | WindowExStyles.WS_EX_STATICEDGE); lExStyle &= (uint)flagsToDisableEx; Methods.SetWindowLong(handle, (int)WindowLongParam.GWL_EXSTYLE, lExStyle); }
public static void ToTransparentWindow(this Window x) { x.SourceInitialized += delegate { // Get this window's handle IntPtr hwnd = new WindowInteropHelper(x).Handle; // Change the extended window style to include WS_EX_TRANSPARENT WindowExStyles extendedStyle = (WindowExStyles)GetWindowLong(hwnd, GWL_EXSTYLE); SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WindowExStyles.WS_EX_TRANSPARENT | WindowExStyles.WS_EX_NOACTIVATE); }; }
public static void MakeInteractive(this System.Windows.Window w, bool value = true) { IntPtr hwnd = new WindowInteropHelper(w).Handle; // Change the extended window style to include WS_EX_TRANSPARENT WindowExStyles extendedStyle = (WindowExStyles)GetWindowLong(hwnd, DesktopWindowManager.GWL_EXSTYLE); if (value) { extendedStyle &= ~(WindowExStyles.WS_EX_TRANSPARENT | WindowExStyles.WS_EX_NOACTIVATE); } else { extendedStyle |= WindowExStyles.WS_EX_TRANSPARENT | WindowExStyles.WS_EX_NOACTIVATE; } SetWindowLong(hwnd, DesktopWindowManager.GWL_EXSTYLE, extendedStyle); }
public static TWindow CreateExternalWindowCore <TWindow>(Func <TWindow> instanceCreator, bool takeOwnership, string className, string text, WindowStyles styles, WindowExStyles exStyles, int x, int y, int width, int height, IntPtr hParent, IntPtr hMenu, IntPtr hInstance, IntPtr extraParams, uint controlStyles) where TWindow : WindowCore { var hwnd = User32Methods.CreateWindowEx(exStyles, className, text, styles | (WindowStyles)controlStyles, x, y, width, height, hParent, hMenu, hInstance, extraParams); if (hwnd == IntPtr.Zero) { ThrowWindowCreationFailed(); } return(CreateWindowFromHandle(instanceCreator, hwnd, takeOwnership)); }
private void ToggleFullScreen() { if (!isFullScreen) { isMaximized = User32Methods.IsZoomed(Handle); //if (isMaximized) // SetState(ShowWindowCommands.SW_RESTORE); windowStyles = GetStyles(); windowExStyles = GetExStyles(); GetWindowRect(out windowRect); SetStyle(windowStyles & ~(WindowStyles.WS_CAPTION | WindowStyles.WS_THICKFRAME)); SetExStyles(windowExStyles & ~(WindowExStyles.WS_EX_DLGMODALFRAME | WindowExStyles.WS_EX_WINDOWEDGE | WindowExStyles.WS_EX_CLIENTEDGE | WindowExStyles.WS_EX_STATICEDGE)); IntPtr monitor = User32Methods.MonitorFromWindow(Handle, MonitorFlag.MONITOR_DEFAULTTONEAREST); User32Helpers.GetMonitorInfo(monitor, out MonitorInfo monitorInfo); SetPosition(monitorInfo.MonitorRect, WindowPositionFlags.SWP_NOZORDER | WindowPositionFlags.SWP_NOACTIVATE | WindowPositionFlags.SWP_FRAMECHANGED); } else { SetStyle(windowStyles); SetExStyles(windowExStyles); SetPosition(windowRect, WindowPositionFlags.SWP_NOZORDER | WindowPositionFlags.SWP_NOACTIVATE | WindowPositionFlags.SWP_FRAMECHANGED); if (isMaximized) { SetState(ShowWindowCommands.SW_MAXIMIZE); } } isFullScreen = !isFullScreen; ResetTransformation(); }
public static int DecodeExStyle(this string strings) { string[] tokens = strings.Split('|'); WindowExStyles ws = 0; foreach (string s in tokens) { bool not; string val; if (!AdjustValue(s, out not, out val)) { continue; } if (not) { ws &= ~(WindowExStyles)Enum.Parse(typeof(WindowExStyles), val); } else { ws |= (WindowExStyles)Enum.Parse(typeof(WindowExStyles), val); } } return((int)ws); }
public static extern bool AdjustWindowRectEx(ref RECT lpRect, WindowStyles dwStyle, bool bMenu, WindowExStyles dwExStyle);
internal static bool IsSet (WindowExStyles ExStyle, WindowExStyles Option) { return (Option & ExStyle) == Option; }
internal bool IsSet (WindowExStyles ExStyle) { return (this.ex_style & (int) ExStyle) == (int) ExStyle; }
public static WindowExStyles SetWindowLongEx(IntPtr hWnd, WindowExStyles dwNewLong) { return (WindowExStyles)SetWindowLong(hWnd, (int)WindowLongFlags.GWL_EXSTYLE, (int)dwNewLong); }
public static extern int SetWindowLongA(IntPtr hWnd, SetWindowLongType nIndex, WindowExStyles dwNewLong);
internal extern static IntPtr Win32CreateWindow(WindowExStyles dwExStyle, string lpClassName, string lpWindowName, WindowStyles dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lParam);
public static extern int SetWindowLong(IntPtr hwnd, int index, WindowExStyles newStyle);
public static extern bool AdjustWindowRectEx([In][Out] ref Rect lpRect, WindowStyles dwStyle, bool bMenu, WindowExStyles exStyle);
private void CreateWindowInternal() { var x = 0; var y = 0; WindowStyles style = 0; WindowExStyles styleEx = 0; const bool resizable = true; // Setup the screen settings depending on whether it is running in full screen or in windowed mode. //if (fullscreen) //{ //style = User32.WindowStyles.WS_POPUP | User32.WindowStyles.WS_VISIBLE; //styleEx = User32.WindowStyles.WS_EX_APPWINDOW; //width = screenWidth; //height = screenHeight; //} //else { if (Width > 0 && Height > 0) { var screenWidth = User32.GetSystemMetrics(SystemMetrics.SM_CXSCREEN); var screenHeight = User32.GetSystemMetrics(SystemMetrics.SM_CYSCREEN); // Place the window in the middle of the screen.WS_EX_APPWINDOW x = (screenWidth - Width) / 2; y = (screenHeight - Height) / 2; } if (resizable) { style = WindowStyles.WS_OVERLAPPEDWINDOW; } else { style = WindowStyles.WS_POPUP | WindowStyles.WS_BORDER | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU; } styleEx = WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_WINDOWEDGE; } style |= WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS; int windowWidth; int windowHeight; if (Width > 0 && Height > 0) { var rect = new Rect(0, 0, Width, Height); // Adjust according to window styles User32.AdjustWindowRectEx( ref rect, style, false, styleEx); windowWidth = rect.Right - rect.Left; windowHeight = rect.Bottom - rect.Top; } else { x = y = windowWidth = windowHeight = CW_USEDEFAULT; } var hwnd = User32.CreateWindowEx( (int)styleEx, Application.WndClassName, Title, (int)style, x, y, windowWidth, windowHeight, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); if (hwnd == IntPtr.Zero) { return; } User32.ShowWindow(hwnd, ShowWindowCommand.Normal); Handle = hwnd; Width = windowWidth; Height = windowHeight; }
public Win32Window(WindowsApplicationHost host, string title, int width, int height) : base(title) { _title = title; _host = host; //const bool fullscreen = false; var resizable = true; var x = 0; var y = 0; WindowStyles style = 0; WindowExStyles styleEx = 0; // Setup the screen settings depending on whether it is running in full screen or in windowed mode. //if (fullscreen) //{ //style = User32.WindowStyles.WS_POPUP | User32.WindowStyles.WS_VISIBLE; //styleEx = User32.WindowStyles.WS_EX_APPWINDOW; //width = screenWidth; //height = screenHeight; //} //else { if (width > 0 && height > 0) { var screenWidth = GetSystemMetrics(SystemMetrics.SM_CXSCREEN); var screenHeight = GetSystemMetrics(SystemMetrics.SM_CYSCREEN); // Place the window in the middle of the screen.WS_EX_APPWINDOW x = (screenWidth - width) / 2; y = (screenHeight - height) / 2; } if (resizable) { style = WindowStyles.WS_OVERLAPPEDWINDOW; } else { style = WindowStyles.WS_POPUP | WindowStyles.WS_BORDER | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU; } styleEx = WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_WINDOWEDGE; } style |= WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS; int windowWidth; int windowHeight; if (width > 0 && height > 0) { var rect = new Rect(0, 0, (int)(width * ContentScale), (int)(height * ContentScale)); // Adjust according to window styles AdjustWindowRectEx( ref rect, style, false, styleEx); windowWidth = rect.Right - rect.Left; windowHeight = rect.Bottom - rect.Top; } else { x = y = windowWidth = windowHeight = CW_USEDEFAULT; } _hwnd = CreateWindowEx( (int)styleEx, WindowsApplicationHost.WndClassName, title, (int)style, x, y, windowWidth, windowHeight, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); if (_hwnd == IntPtr.Zero) { //Log.Error("[Win32] - Failed to create window"); return; } _host.RegisterWindow(this); ShowWindow(_hwnd, ShowWindowCommand.Normal); // Rase and set handle. OnHandleCreated(SwapChainHandle.CreateWin32(host.HInstance, _hwnd)); }
private unsafe void PlatformConstruct() { int x = 0; int y = 0; WindowStyles style = 0; WindowExStyles styleEx = 0; const bool resizable = true; // Setup the screen settings depending on whether it is running in full screen or in windowed mode. //if (fullscreen) //{ //style = User32.WindowStyles.WS_POPUP | User32.WindowStyles.WS_VISIBLE; //styleEx = User32.WindowStyles.WS_EX_APPWINDOW; //width = screenWidth; //height = screenHeight; //} //else { if (ClientSize.Width > 0 && ClientSize.Height > 0) { int screenWidth = GetSystemMetrics(SystemMetrics.SM_CXSCREEN); int screenHeight = GetSystemMetrics(SystemMetrics.SM_CYSCREEN); // Place the window in the middle of the screen.WS_EX_APPWINDOW x = (screenWidth - ClientSize.Width) / 2; y = (screenHeight - ClientSize.Height) / 2; } if (resizable) { style = WindowStyles.WS_OVERLAPPEDWINDOW; } else { style = WindowStyles.WS_POPUP | WindowStyles.WS_BORDER | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU; } styleEx = WindowExStyles.WS_EX_APPWINDOW | WindowExStyles.WS_EX_WINDOWEDGE; } style |= WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS; int windowWidth; int windowHeight; if (ClientSize.Width > 0 && ClientSize.Height > 0) { var rect = new RawRect(0, 0, ClientSize.Width, ClientSize.Height); // Adjust according to window styles AdjustWindowRectEx(&rect, (uint)style, 0, (uint)styleEx); windowWidth = rect.Right - rect.Left; windowHeight = rect.Bottom - rect.Top; } else { x = y = windowWidth = windowHeight = CW_USEDEFAULT; } fixed(char *lpszClassName = Application.WindowClassName) { fixed(char *lpWindowName = Title) { Handle = CreateWindowExW( (uint)styleEx, (ushort *)lpszClassName, (ushort *)lpWindowName, (uint)style, x, y, windowWidth, windowHeight, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, null ); if (Handle == IntPtr.Zero) { return; } } } ShowWindow(Handle, (int)ShowWindowCommand.Normal); ClientSize = new Size(windowWidth, windowHeight); }
bool ExStyleSet (int ex, WindowExStyles exws) { return (ex & (int)exws) == (int)exws; }
internal bool IsSet(WindowExStyles ExStyle) { return((this.ex_style & (int)ExStyle) == (int)ExStyle); }
public static extern bool AdjustWindowRectEx([In][Out] ref Rectangle lpRect, WindowStyles dwStyle, bool hasMenu, WindowExStyles dwExStyle);
internal static bool IsSet(WindowExStyles ExStyle, WindowExStyles Option) { return((Option & ExStyle) == Option); }
private string PlanStyle (WindowExStyles style) { return style.ToString ().Replace ("WS_EX_LEFT, WS_EX_RIGHTSCROLLBAR, ", ""); }
public static bool IsExStyleSet (Control control, WindowExStyles style) { CreateParams cp = GetCreateParams (control); return ((cp.ExStyle & (int) style) == (int) style); }
public void PrintStyle (Control control, WindowExStyles s) { CreateParams cp = (CreateParams) control.GetType().GetProperty("CreateParams", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(control, null); if ((cp.Style & (int) s) == (int) s) { Console.WriteLine ("=>Style: {0}:{1}", PlanStyle(s), (int)s); } if ((cp.ExStyle & (int) s) == (int) s) { Console.WriteLine ("=>ExStyle: {0}:{1}", PlanStyle(s), (int)s); } }
public static bool IsExStyleSet(Control control, WindowExStyles style) { CreateParams cp = GetCreateParams(control); return((cp.ExStyle & (int)style) == (int)style); }
private bool ExStyleSet(int ex, WindowExStyles exws) { return((ex & (int)exws) == (int)exws); }