public DefaultForm( WindowClassStyle classStyle, WindowsExtendedStyle dwStyleEx, string title, WindowStyles windowStyle, int left, int top, int winWidth, int winHeight, Control parentHWnd ) { _classStyle = classStyle; _dwStyleEx = dwStyleEx; _windowStyle = windowStyle; SuspendLayout(); AutoScaleBaseSize = new System.Drawing.Size(5, 13); BackColor = System.Drawing.Color.Black; ClientSize = new System.Drawing.Size(640, 480); Name = title; Left = left; Top = top; Width = winWidth; Height = winHeight; if (parentHWnd != null) Parent = parentHWnd; Load += DefaultFormLoad; Deactivate += DefaultFormDeactivate; Activated += DefaultFormActivated; Closing += DefaultFormClose; Resize += DefaultFormResize; ResumeLayout(false); }
private static void AddWindowStyle(Window window, WindowStyles styleToAdd) { WindowInteropHelper wih = new WindowInteropHelper(window); WindowStyles style = (WindowStyles)GetWindowLongPtr(wih.EnsureHandle(), GWL_STYLE); style |= styleToAdd; SetWindowLongPtr(wih.Handle, GWL_STYLE, (IntPtr)style); SetWindowPos(wih.Handle, IntPtr.Zero, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER); }
private static extern IntPtr CreateWindowEx( UInt32 dwExStyle, String lpClassName, String lpWindowName, WindowStyles dwStyle, Int32 x, Int32 y, Int32 nWidth, Int32 nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam);
internal static extern IntPtr CreateWindowEx( WindowStylesEx dwExStyle, string lpClassName, string lpWindowName, WindowStyles dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam);
public static extern bool AdjustWindowRect(ref Rectangle rect, WindowStyles style, [MarshalAs(UnmanagedType.Bool)] bool menu);
public static extern bool AdjustWindowRectEx(ref Rect lpRect, WindowStyles dwStyle, bool bMenu, WindowStylesEx dwExStyle);
private static extern IntPtr CreateWindowEx(UInt32 dwExStyle, uint lpClassNameByAtomFromRegisterWindow, [MarshalAs(UnmanagedType.LPWStr)] string lpWindowName, WindowStyles dwStyle, Int32 x, Int32 y, Int32 nWidth, Int32 nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam );
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 override void Create( string name, int width, int height, bool fullScreen, NamedParameterList miscParams ) { SWF.Control parentHWnd = null; SWF.Control externalHWnd = null; this._fsaaType = D3D9.MultisampleType.None; this._fsaaQuality = 0; fsaa = 0; this._vSync = false; this._vSyncInterval = 1; var title = name; var colorDepth = 32; var left = int.MaxValue; // Defaults to screen center var top = int.MaxValue; // Defaults to screen center var depthBuffer = true; var border = ""; var outerSize = false; var enableDoubleClick = false; this._useNVPerfHUD = false; //var fsaaSamples = 0; //Not used, even in Ogre var fsaaHint = string.Empty; var monitorIndex = -1; if ( miscParams != null ) { object opt; // left (x) if ( miscParams.TryGetValue( "left", out opt ) ) { left = Int32.Parse( opt.ToString() ); } // top (y) if ( miscParams.TryGetValue( "top", out opt ) ) { top = Int32.Parse( opt.ToString() ); } // Window title if ( miscParams.TryGetValue( "title", out opt ) ) { title = (string)opt; } // parentWindowHandle -> parentHWnd if ( miscParams.TryGetValue( "parentWindowHandle", out opt ) ) { parentHWnd = GetControlFromParameter( opt ); } // externalWindowHandle -> externalHWnd if ( miscParams.TryGetValue( "externalWindowHandle", out opt ) ) { externalHWnd = GetControlFromParameter(opt); } // vsync [parseBool] if ( miscParams.TryGetValue( "vsync", out opt ) ) { this._vSync = bool.Parse( opt.ToString() ); } // vsyncInterval [parseUnsignedInt] if ( miscParams.TryGetValue( "vsyncInterval", out opt ) ) { this._vSyncInterval = Int32.Parse( opt.ToString() ); } // displayFrequency if ( miscParams.TryGetValue( "displayFrequency", out opt ) ) { this._displayFrequency = Int32.Parse( opt.ToString() ); } // colorDepth if ( miscParams.TryGetValue( "colorDepth", out opt ) ) { colorDepth = Int32.Parse( opt.ToString() ); } // depthBuffer [parseBool] if ( miscParams.TryGetValue( "depthBuffer", out opt ) ) { depthBuffer = bool.Parse( opt.ToString() ); } //FSAA settings // FSAA type if ( miscParams.TryGetValue( "FSAA", out opt ) ) { this._fsaaType = (D3D9.MultisampleType)opt; } if ( miscParams.TryGetValue( "FSAAHint", out opt ) ) { fsaaHint = (string)opt; } // window border style if ( miscParams.TryGetValue( "border", out opt ) ) { border = ( (string)opt ).ToLower(); } // set outer dimensions? if ( miscParams.TryGetValue( "outerDimensions", out opt ) ) { outerSize = bool.Parse( opt.ToString() ); } // NV perf HUD? if ( miscParams.TryGetValue( "useNVPerfHUD", out opt ) ) { this._useNVPerfHUD = bool.Parse( opt.ToString() ); } // sRGB? if ( miscParams.TryGetValue( "gamma", out opt ) ) { hwGamma = bool.Parse( opt.ToString() ); } // monitor index if ( miscParams.TryGetValue( "monitorIndex", out opt ) ) { monitorIndex = Int32.Parse( opt.ToString() ); } // enable double click messages if ( miscParams.TryGetValue( "enableDoubleClick", out opt ) ) { enableDoubleClick = bool.Parse( opt.ToString() ); } } // Destroy current window if any if ( this._windowHandle != null ) { Destroy(); } if ( externalHWnd == null ) { var dwStyle = WindowStyles.Visible | WindowStyles.ClipChildren; var dwStyleEx = (WindowsExtendedStyle)0; var monitorHandle = IntPtr.Zero; // If we specified which adapter we want to use - find it's monitor. if ( monitorIndex != -1 ) { var direct3D9 = D3D9RenderSystem.Direct3D9; for ( var i = 0; i < direct3D9.AdapterCount; ++i ) { if ( i != monitorIndex ) { continue; } monitorHandle = direct3D9.GetAdapterMonitor( i ); break; } } // If we didn't specified the adapter index, or if it didn't find it if ( monitorHandle == IntPtr.Zero ) { // Fill in anchor point. var windowAnchorPoint = new Point( left, top ); // Get the nearest monitor to this window. monitorHandle = ScreenHelper.GetHandle( windowAnchorPoint ); } // Get the target monitor info var monitorInfo = ScreenHelper.FromHandle( monitorHandle ); var winWidth = width; var winHeight = height; // No specified top left -> Center the window in the middle of the monitor if ( left == int.MaxValue || top == int.MaxValue ) { var screenw = monitorInfo.WorkingArea.Right - monitorInfo.WorkingArea.Left; var screenh = monitorInfo.WorkingArea.Bottom - monitorInfo.WorkingArea.Top; // clamp window dimensions to screen size var outerw = ( winWidth < screenw ) ? winWidth : screenw; var outerh = ( winHeight < screenh ) ? winHeight : screenh; if ( left == int.MaxValue ) { left = monitorInfo.WorkingArea.Left + ( screenw - outerw )/2; } else if ( monitorIndex != -1 ) { left += monitorInfo.WorkingArea.Left; } if ( top == int.MaxValue ) { top = monitorInfo.WorkingArea.Top + ( screenh - outerh )/2; } else if ( monitorIndex != -1 ) { top += monitorInfo.WorkingArea.Top; } } else if ( monitorIndex != -1 ) { left += monitorInfo.WorkingArea.Left; top += monitorInfo.WorkingArea.Top; } this.width = this._desiredWidth = width; this.height = this._desiredHeight = height; this.top = top; this.left = left; if ( fullScreen ) { dwStyleEx |= WindowsExtendedStyle.TopMost; dwStyle |= WindowStyles.Popup; this.top = monitorInfo.Bounds.Top; this.left = monitorInfo.Bounds.Left; } else { if ( parentHWnd != null ) { dwStyle |= WindowStyles.Child; } else { if ( border == "none" ) { dwStyle |= WindowStyles.Popup; } else if ( border == "fixed" ) { dwStyle |= WindowStyles.Overlapped | WindowStyles.Border | WindowStyles.Caption | WindowStyles.SystemMenu | WindowStyles.MinimizeBox; } else { dwStyle |= WindowStyles.OverlappedWindow; } } AdjustWindow( width, height, dwStyle, out winWidth, out winHeight ); if ( !outerSize ) { // Calculate window dimensions required // to get the requested client area var rc = new RECT( 0, 0, this.width, this.height ); AdjustWindowRect( ref rc, dwStyle, false ); this.width = rc.Right - rc.Left; this.height = rc.Bottom - rc.Top; // Clamp window rect to the nearest display monitor. if ( this.left < monitorInfo.WorkingArea.Left ) { this.left = monitorInfo.WorkingArea.Left; } if ( this.top < monitorInfo.WorkingArea.Top ) { this.top = monitorInfo.WorkingArea.Top; } if ( winWidth > monitorInfo.WorkingArea.Right - this.left ) { winWidth = monitorInfo.WorkingArea.Right - this.left; } if ( winHeight > monitorInfo.WorkingArea.Bottom - this.top ) { winHeight = monitorInfo.WorkingArea.Bottom - this.top; } } } WindowClassStyle classStyle = 0; if ( enableDoubleClick ) { classStyle |= WindowClassStyle.DoubleClicks; } // Create our main window this._isExternal = false; this._windowHandle = new DefaultForm( classStyle, dwStyleEx, title, dwStyle, this.left, this.top, winWidth, winHeight, parentHWnd ) { RenderWindow = this }; this._style = dwStyle; WindowEventMonitor.Instance.RegisterWindow( this ); } else { this._windowHandle = externalHWnd; this._isExternal = true; } // top and left represent outer window coordinates var rc2 = new System.Drawing.Rectangle( this._windowHandle.Location, this._windowHandle.Size ); this.top = rc2.Top; this.left = rc2.Left; // width and height represent interior drawable area rc2 = this._windowHandle.ClientRectangle; this.width = rc2.Right; this.height = rc2.Bottom; this.name = name; isDepthBuffered = depthBuffer; isFullScreen = fullScreen; this.colorDepth = colorDepth; LogManager.Instance.Write( "D3D9 : Created D3D9 Rendering Window '{0}' : {1}x{2}, {3}bpp", this.name, this.width, this.height, ColorDepth ); active = true; this._isClosed = false; }
public DefaultForm( WindowClassStyle classStyle, WindowsExtendedStyle dwStyleEx, string title, WindowStyles windowStyle, int left, int top, int winWidth, int winHeight, Control parentHWnd ) { this._classStyle = classStyle; this._dwStyleEx = dwStyleEx; this._windowStyle = windowStyle; SuspendLayout(); BackColor = Color.Black; Name = title; Left = left; Top = top; Width = winWidth; Height = winHeight; if ( parentHWnd != null ) { Parent = parentHWnd; } Load += _defaultFormLoad; Deactivate += _defaultFormDeactivate; Activated += _defaultFormActivated; Closing += _defaultFormClose; Resize += _defaultFormResize; Cursor.Hide(); ResumeLayout( false ); }
/// <summary> /// Infinitely locks the cursor to the selected window if it has focus. /// Only returns once the window handle is destroyed. /// </summary> /// <param name="windowHandle">The handle of the window to which the cursor will be locked.</param> public static void LockCursor(IntPtr windowHandle) { Rectangle windowArea = new Rectangle(); bool selectedWindowHadFocus = false; int validateHandleCount = 0; WindowStyles previousStyles = 0; Rectangle windowBorderSize = new Rectangle(); string selectedWindowTitle = GetWindowText(windowHandle, WindowTitleMaxLength); while (true) { // Check if window styles changed so the program doesn't break if the window's borders style is changed if (previousStyles != GetWindowLong(windowHandle, GetWindowLongIndex.GWL_STYLE)) { // Determine border sizes for the selected window windowBorderSize = GetWindowBorderSizes(windowHandle); previousStyles = GetWindowLong(windowHandle, GetWindowLongIndex.GWL_STYLE); } if (GetForegroundWindow() == windowHandle) { if (GetWindowRect(windowHandle, ref windowArea) == 0) { throw new Win32Exception( Marshal.GetLastWin32Error(), string.Format("Get window rectangle win32 error. selectedWindowHandle {0:d}", windowHandle)); } windowArea.Left += windowBorderSize.Left; windowArea.Top += windowBorderSize.Top; windowArea.Bottom -= windowBorderSize.Bottom; windowArea.Right -= windowBorderSize.Right; if (ClipCursor(ref windowArea) == 0) { throw new Win32Exception( Marshal.GetLastWin32Error(), string.Format("Clip cursor win32 error. windowArea {0:s}", windowArea.ToString())); } selectedWindowHadFocus = true; Thread.Sleep(500); } else if (selectedWindowHadFocus) { // If the window lost focus remove the clipping area. // Usually the clipping gets removed by default if the window loses focus. ClipCursor(IntPtr.Zero); selectedWindowHadFocus = false; } // Validate the window every x amount of loops validateHandleCount++; if (validateHandleCount > ValidateHandleThreshold) { validateHandleCount = 0; string tempWindowTitle = GetWindowText(windowHandle, WindowTitleMaxLength); if (tempWindowTitle == null || tempWindowTitle != selectedWindowTitle) { Console.WriteLine("The selected Window doesn't exists anymore!"); ClipCursor(IntPtr.Zero); break; } } Thread.Sleep(ClippingRefreshInterval); } }
public static extern bool AdjustWindowRect([In][Out] ref Rect lpRect, WindowStyles dwStyle, bool hasMenu);
private static void ResetWindowStyle(Window window, WindowStyles styles, bool set) { const int Flags = SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREPOSITION | SWP_NOSIZE | SWP_NOZORDER; var wih = new WindowInteropHelper(window); var style = (WindowStyles)GetWindowLongPtr(wih.EnsureHandle(), GWL_STYLE); if (set) { style |= styles; } else { style &= ~styles; } SetWindowLongPtr(wih.Handle, GWL_STYLE, (IntPtr)style); SetWindowPos(wih.Handle, IntPtr.Zero, 0, 0, 0, 0, Flags); }
public static extern IntPtr CreateWindow(WindowStylesEx 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 WindowStyles SetWindowLong(IntPtr hWnd, WindowStyles dwNewLong) { return((WindowStyles)SetWindowLong(hWnd, (int)WindowLongFlags.GWL_STYLE, (int)dwNewLong)); }
public static extern IntPtr CreateWindowExW(WindowStylesEx dwExStyle, ushort lpszClassName, [MarshalAs(UnmanagedType.LPTStr)] string lpszWindowName, WindowStyles style, int x, int y, int width, int height, IntPtr hWndParent, IntPtr hMenu, IntPtr hInst, IntPtr lpParam);
static sz_Or_Ord ControlTypeToClass(Tokens type, string typeName, ref WindowStyles style) { switch (type) { case Tokens.DefPushButton: case Tokens.PushButton: return(g_Button); case Tokens.EditText: return(g_Edit); //case Tokens.Static: // return g_Static; case Tokens.ListBox: return(g_Listbox); //case Tokens.ScrollBar: // return g_ScrollBar; case Tokens.ComboBox: return(g_ComboBox); case Tokens.Control: return(new sz_Or_Ord(typeName)); case Tokens.LText: case Tokens.RText: case Tokens.CText: style |= WindowStyles.WS_GROUP; if (type == Tokens.LText) { style |= WindowStyles.SS_LEFT; } else if (type == Tokens.RText) { style |= WindowStyles.SS_RIGHT; } else if (type == Tokens.CText) { style |= WindowStyles.SS_CENTER; } return(g_Static); case Tokens.Icon: style |= WindowStyles.SS_ICON; return(g_Static); case Tokens.GroupBox: style |= WindowStyles.BS_GROUPBOX; return(g_Static); case Tokens.CheckBox: style |= WindowStyles.WS_TABSTOP | WindowStyles.BS_CHECKBOX; return(g_Button); case Tokens.AutoCheckBox: style |= WindowStyles.WS_TABSTOP | WindowStyles.BS_AUTOCHECKBOX; return(g_Button); case Tokens.RadioButton: style |= WindowStyles.WS_TABSTOP | WindowStyles.BS_RADIOBUTTON; return(g_Button); case Tokens.AutoRadioButton: style |= WindowStyles.WS_TABSTOP | WindowStyles.BS_AUTORADIOBUTTON; return(g_Button); default: Debugger.Break(); return(null); } }
/// <summary>Set new window style</summary> public static void SetStyle(IntPtr window, WindowStyles newStyle) { SetWindowLongStyle(window, -16, newStyle); }
public static extern bool AdjustWindowRectEx([In][Out] ref Rect lpRect, WindowStyles dwStyle, bool bMenu, WindowExStyles exStyle);
public static bool IsStyleSet (Control control, WindowStyles style) { CreateParams cp = GetCreateParams (control); return ((cp.Style & (int) style) == (int) style); }
public WindowStyles SetStyle(WindowStyles styles) { return((WindowStyles)this.SetParam(WindowLongFlags.GWL_STYLE, new IntPtr((int)styles))); }
public void AdjustWindow( int clientWidth, int clientHeight, WindowStyles style, out int winWidth, out int winHeight ) { // NB only call this for non full screen var rc = new RECT( 0, 0, clientWidth, clientHeight ); AdjustWindowRect( ref rc, style, false ); winWidth = rc.Right - rc.Left; winHeight = rc.Bottom - rc.Top; // adjust to monitor var handle = this._windowHandle != null ? this._windowHandle.Handle : IntPtr.Zero; // Get monitor info var monitorInfo = ScreenHelper.FromHandle( handle ); var maxW = monitorInfo.WorkingArea.Right - monitorInfo.WorkingArea.Left; var maxH = monitorInfo.WorkingArea.Bottom - monitorInfo.WorkingArea.Top; if ( winWidth > maxW ) { winWidth = maxW; } if ( winHeight > maxH ) { winHeight = maxH; } }
public static extern bool AdjustWindowRect( [In] ref RECT lpRect, [In] WindowStyles dwStyle, [In, MarshalAs(UnmanagedType.Bool)] bool bMenu );
public void PrintStyle (Control control, WindowStyles 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 extern bool AdjustWindowRectEx(ref Rect lpRect, [In] WindowStyles dwStyle, [In] bool bMenu, [In] WindowStylesEx dwExStyle);
internal static bool IsSet (WindowStyles Style, WindowStyles Option) { return (Option & Style) == Option; }
public static extern IntPtr CreateWindowEx([In] WindowStylesEx dwExStyle, [In][MarshalAs(UnmanagedType.LPStr)] string lpClassName, [In][MarshalAs(UnmanagedType.LPStr)] string lpWindowName, [In] WindowStyles dwStyle, [In] int x, [In] int y, [In] int nWidth, [In] int nHeight, [In] IntPtr hWndParent, [In] IntPtr hMenu, [In] IntPtr hInstance, [In] IntPtr lpParam);
public static bool IsStyleSet(Control control, WindowStyles style) { CreateParams cp = GetCreateParams(control); return((cp.Style & (int)style) == (int)style); }
public static extern IntPtr CreateWindowEx(uint dwExStyle, [MarshalAs(UnmanagedType.LPTStr)] string lpClassName, [MarshalAs(UnmanagedType.LPTStr)] string lpWindowName, WindowStyles dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam);
//取消标志位 public static IntPtr UnsetWindowStyles(IntPtr hWnd, WindowStyles ws) { var style = GetWindowLongPtr(hWnd, WindowLongFlags.GWL_STYLE); return SetWindowLongPtr(hWnd, WindowLongFlags.GWL_STYLE, IntPtrEnumHelper.UnsetFlag(style, ws)); }
public static IntPtr CreateWindow(string lpClassName, string lpWindowName, WindowStyles dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam) { return(CreateWindowEx(0, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)); }
private static extern IntPtr SetWindowLongStyle(IntPtr hWnd, int index, WindowStyles style);
public static extern bool AdjustWindowRectEx(ref RECT lpRect, WindowStyles dwStyle, bool bMenu, uint dwExStyle);
public static extern IntPtr CreateWindow(int exStyle, [MarshalAs(UnmanagedType.LPTStr)] string className, [MarshalAs(UnmanagedType.LPTStr)] string windowName, WindowStyles style, int x, int y, int width, int height, IntPtr parent, IntPtr menuHandle, IntPtr instanceHandle, IntPtr zero);
internal bool IsSet(WindowStyles Style) { return((this.style & (int)Style) == (int)Style); }
public MonoContentView(XplatUICocoa driver, NSRect frameRect, WindowStyles style, WindowExStyles exStyle) : base(driver, frameRect, style, exStyle) { }
internal static bool IsSet(WindowStyles Style, WindowStyles Option) { return((Option & Style) == Option); }
private static extern bool AdjustWindowRect( ref RECT lpRect, WindowStyles dwStyle, [MarshalAs( UnmanagedType.Bool )] bool bMenu );
public static extern uint SetWindowLong(IntPtr hWnd, WindowsIndexStyle nIndex, WindowStyles dwNewLong);
public override void SetFullScreen( bool fullScreen, int width, int height ) { if ( fullScreen != isFullScreen || width != this.width || height != this.height ) { if ( fullScreen != isFullScreen ) { this._switchingFullScreen = true; } this._style = WindowStyles.Visible | WindowStyles.ClipChildren; var oldFullScreen = isFullScreen; isFullScreen = fullScreen; this.width = this._desiredWidth = width; this.height = this._desiredHeight = height; if ( fullScreen ) { this._style |= WindowStyles.Popup; // Get the nearest monitor to this window. var windowAnchorPoint = new Point( left, top ); // Get the target monitor info var monitorInfo = SWF.Screen.FromPoint( windowAnchorPoint ); top = monitorInfo.Bounds.Top; left = monitorInfo.Bounds.Left; // need different ordering here ( (DefaultForm)this._windowHandle ).TopMost = true; ( (DefaultForm)this._windowHandle ).SetBounds( left, top, width, height ); if ( !oldFullScreen ) { ( (DefaultForm)this._windowHandle ).WindowStyles = this._style; //TODO //SetWindowPos(mHWnd, 0, 0,0, 0,0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); } } else { this._style |= WindowStyles.OverlappedWindow; // Calculate window dimensions required // to get the requested client area int winWidth, winHeight; AdjustWindow( this.width, this.height, this._style, out winWidth, out winHeight ); ( (DefaultForm)this._windowHandle ).WindowStyles = this._style; ( (DefaultForm)this._windowHandle ).TopMost = false; ( (DefaultForm)this._windowHandle ).SetBounds( 0, 0, winWidth, winHeight ); //TODO //SetWindowPos(mHWnd, HWND_NOTOPMOST, 0, 0, winWidth, winHeight, SWP_DRAWFRAME | SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOACTIVATE); // Note that we also set the position in the restoreLostDevice method // via FinishSwitchingFullScreen } // Have to release & trigger device reset // NB don't use windowMovedOrResized since Win32 doesn't know // about the size change yet this._device.Invalidate( this ); // Notify viewports of resize foreach ( var it in ViewportList.Values ) { it.UpdateDimensions(); } } }
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 static extern IntPtr CreateWindowEx( WindowStylesEx dwExStyle, [MarshalAs(UnmanagedType.LPWStr)] string lpClassName, [MarshalAs(UnmanagedType.LPWStr)] string lpWindowName, WindowStyles dwStyle, Int32 x, Int32 y, Int32 nWidth, Int32 nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam);
public static extern bool AdjustWindowRectEx([In][Out] ref Rectangle lpRect, WindowStyles dwStyle, bool hasMenu, WindowExStyles dwExStyle);
public ControlStylesTester (WindowStyles Style, WindowStyles ExStyle, bool OrStyles) { style = Style; ex_style = ExStyle; or_styles = OrStyles; }
/// <summary> /// The CreateWindow is identical to the CreateWindowEx function, actually it is a macro on C/C++ /// </summary> /// <param name="lpClassName"> /// Pointer to a null-terminated string or a class atom created by a previous call to the /// RegisterClass or RegisterClassEx function. The atom must be in the low-order word of /// lpClassName; the high-order word must be zero. If lpClassName is a string, it specifies /// the window class name. The class name can be any name registered with RegisterClass or /// RegisterClassEx, provided that the module that registers the class is also the module /// that creates the window. The class name can also be any of the predefined system class names. /// </param> /// <param name="lpWindowName"> /// Pointer to a null-terminated string that specifies the window name. If the window style /// specifies a title bar, the window title pointed to by lpWindowName is displayed in the /// title bar. When using CreateWindow to create controls, such as buttons, check boxes, and /// static controls, use lpWindowName to specify the text of the control. When creating a /// static control with the SS_ICON style, use lpWindowName to specify the icon name or /// identifier. To specify an identifier, use the syntax "#num". /// </param> /// <param name="dwStyle"> /// Specifies the style of the window being created. This parameter can be a combination of /// window styles, plus the control styles indicated in the Remarks section. /// </param> /// <param name="x"> /// Specifies the initial horizontal position of the window. For an overlapped or pop-up /// window, the x parameter is the initial x-coordinate of the window's upper-left corner, in /// screen coordinates. For a child window, x is the x-coordinate of the upper-left corner of /// the window relative to the upper-left corner of the parent window's client area. If x is /// set to CW_USEDEFAULT, the system selects the default position for the window's upper-left /// corner and ignores the y parameter. CW_USEDEFAULT is valid only for overlapped windows; /// if it is specified for a pop-up or child window, the x and y parameters are set to zero. /// </param> /// <param name="y"> /// Specifies the initial vertical position of the window. For an overlapped or pop-up /// window, the y parameter is the initial y-coordinate of the window's upper-left corner, in /// screen coordinates. For a child window, y is the initial y-coordinate of the upper-left /// corner of the child window relative to the upper-left corner of the parent window's /// client area. For a list box y is the initial y-coordinate of the upper-left corner of the /// list box's client area relative to the upper-left corner of the parent window's client area. /// <para> /// If an overlapped window is created with the WS_VISIBLE style bit set and the x parameter /// is set to CW_USEDEFAULT, then the y parameter determines how the window is shown. If the /// y parameter is CW_USEDEFAULT, then the window manager calls ShowWindow with the SW_SHOW /// flag after the window has been created. If the y parameter is some other value, then the /// window manager calls ShowWindow with that value as the nCmdShow parameter. /// </para> /// </param> /// <param name="nWidth"> /// Specifies the width, in device units, of the window. For overlapped windows, nWidth is /// the window's width, in screen coordinates, or CW_USEDEFAULT. If nWidth is CW_USEDEFAULT, /// the system selects a default width and height for the window; the default width extends /// from the initial x-coordinates to the right edge of the screen; the default height /// extends from the initial y-coordinate to the top of the icon area. CW_USEDEFAULT is valid /// only for overlapped windows; if CW_USEDEFAULT is specified for a pop-up or child window, /// the nWidth and nHeight parameter are set to zero. /// </param> /// <param name="nHeight"> /// Specifies the height, in device units, of the window. For overlapped windows, nHeight is /// the window's height, in screen coordinates. If the nWidth parameter is set to /// CW_USEDEFAULT, the system ignores nHeight. /// </param> /// <param name="hWndParent"> /// Handle to the parent or owner window of the window being created. To create a child /// window or an owned window, supply a valid window handle. This parameter is optional for /// pop-up windows. /// <para> /// Windows 2000/XP: To create a message-only window, supply HWND_MESSAGE or a handle to an /// existing message-only window. /// </para> /// </param> /// <param name="hMenu"> /// Handle to a menu, or specifies a child-window identifier, depending on the window style. /// For an overlapped or pop-up window, hMenu identifies the menu to be used with the window; /// it can be NULL if the class menu is to be used. For a child window, hMenu specifies the /// child-window identifier, an integer value used by a dialog box control to notify its /// parent about events. The application determines the child-window identifier; it must be /// unique for all child windows with the same parent window. /// </param> /// <param name="hInstance"> /// Handle to the instance of the module to be associated with the window. /// </param> /// <param name="lpParam"> /// Pointer to a value to be passed to the window through the CREATESTRUCT structure /// (lpCreateParams member) pointed to by the lParam param of the WM_CREATE message. This /// message is sent to the created window by this function before it returns. /// <para> /// If an application calls CreateWindow to create a MDI client window, lpParam should point /// to a CLIENTCREATESTRUCT structure. If an MDI client window calls CreateWindow to create /// an MDI child window, lpParam should point to a MDICREATESTRUCT structure. lpParam may be /// NULL if no additional data is needed. /// </para> /// </param> /// <returns> /// If the function succeeds, the return value is a handle to the new window. /// <para> /// If the function fails, the return value is NULL. To get extended error information, call GetLastError. /// </para> /// <para>This function typically fails for one of the following reasons:</para> /// <list type=""> /// <item>an invalid parameter value</item> /// <item>the system class was registered by a different module</item> /// <item>The WH_CBT hook is installed and returns a failure code</item> /// <item> /// if one of the controls in the dialog template is not registered, or its window window /// procedure fails WM_CREATE or WM_NCCREATE /// </item> /// </list> /// </returns> public static unsafe IntPtr CreateWindow( string lpClassName, string lpWindowName, WindowStyles dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, void* lpParam) { return CreateWindowEx(0, lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam); }
private string PlanStyle (WindowStyles style) { return style.ToString ().Replace ("WS_EX_LEFT, WS_EX_RIGHTSCROLLBAR, ", ""); }
private string PlanStyle(WindowStyles style) { return(style.ToString().Replace("WS_EX_LEFT, WS_EX_RIGHTSCROLLBAR, ", "")); }
internal bool IsSet (WindowStyles Style) { return (this.style & (int) Style) == (int) Style; }
public static WindowStyles SetWindowLong(IntPtr hWnd, WindowStyles dwNewLong) { return (WindowStyles)SetWindowLong(hWnd, (int)WindowLongFlags.GWL_STYLE, (int)dwNewLong); }
bool StyleSet (int s, WindowStyles ws) { return (s & (int)ws) == (int)ws; }
public static extern bool AdjustWindowRect(ref Rect lpRect, WindowStyles dwStyle, bool bMenu);
private void AdjustWindowRect( ref System.Drawing.Rectangle rc, WindowStyles getWindowStyle, bool b ) { }
/// <inheritdoc /> protected override void SetupInternal(Configurator config) { IsWindows7OrGreater = IsWindowsVersionOrGreaterWin32( NativeHelpers.HiByte((ushort)NtDll.WinVer.Win32WinNTWin7), NativeHelpers.LoByte((ushort)NtDll.WinVer.Win32WinNTWin7), 0); IsWindows8OrGreater = IsWindowsVersionOrGreaterWin32( NativeHelpers.HiByte((ushort)NtDll.WinVer.Win32WinNTWin8), NativeHelpers.LoByte((ushort)NtDll.WinVer.Win32WinNTWin8), 0); IsWindows81OrGreater = IsWindowsVersionOrGreaterWin32( NativeHelpers.HiByte((ushort)NtDll.WinVer.Win32WinNTWinBlue), NativeHelpers.LoByte((ushort)NtDll.WinVer.Win32WinNTWinBlue), 0); IsWindows10AnniversaryUpdateOrGreaterWin32 = IsWindows10BuildOrGreaterWin32(14393); IsWindows10CreatorsUpdateOrGreaterWin32 = IsWindows10BuildOrGreaterWin32(15063); var windowsVersionFlags = new List <string>(); if (IsWindows7OrGreater) { windowsVersionFlags.Add(nameof(IsWindows7OrGreater)); } if (IsWindows8OrGreater) { windowsVersionFlags.Add(nameof(IsWindows8OrGreater)); } if (IsWindows81OrGreater) { windowsVersionFlags.Add(nameof(IsWindows81OrGreater)); } if (IsWindows10AnniversaryUpdateOrGreaterWin32) { windowsVersionFlags.Add(nameof(IsWindows10AnniversaryUpdateOrGreaterWin32)); } if (IsWindows10CreatorsUpdateOrGreaterWin32) { windowsVersionFlags.Add(nameof(IsWindows10CreatorsUpdateOrGreaterWin32)); } Engine.Log.Trace(string.Join(", ", windowsVersionFlags), MessageSource.Win32); if (IsWindows10CreatorsUpdateOrGreaterWin32) { User32.SetProcessDpiAwarenessContext(DpiAwarenessContext.DpiAwarenessContextPerMonitorAwareV2); } else if (IsWindows81OrGreater) { User32.SetProcessDpiAwareness(ProcessDpiAwareness.ProcessPerMonitorDpiAware); } else { User32.SetProcessDPIAware(); } // todo: load libraries - if any, probably XInput? // Initialize audio. AudioContext ctx = null; #if OpenAL ctx ??= OpenALAudioAdapter.TryCreate(this); #endif ctx ??= WasApiAudioContext.TryCreate(this); ctx ??= new NullAudioContext(); Audio = ctx; Engine.Log.Trace("Audio init complete.", MessageSource.Win32); PopulateKeyCodes(); RegisterWindowClass(); CreateHelperWindow(); PollMonitors(); Engine.Log.Trace("Platform helpers created.", MessageSource.Win32); var windowInitialSize = new Rect { Right = (int)config.HostSize.X, Bottom = (int)config.HostSize.Y }; GetFullWindowRect(DEFAULT_WINDOW_STYLE, DEFAULT_WINDOW_STYLE_EX, DEFAULT_DPI, ref windowInitialSize); int initialWidth = windowInitialSize.Right - windowInitialSize.Left; int initialHeight = windowInitialSize.Bottom - windowInitialSize.Top; WindowStyles windowStyle = DEFAULT_WINDOW_STYLE; if (config.HiddenWindow) { windowStyle &= ~WindowStyles.WS_VISIBLE; windowStyle &= ~WindowStyles.WS_MINIMIZE; // This will override the hide otherwise config.InitialDisplayMode = DisplayMode.Initial; } IntPtr windowHandle = User32.CreateWindowEx( DEFAULT_WINDOW_STYLE_EX, CLASS_NAME, config.HostTitle, windowStyle, (int)CreateWindowFlags.CW_USEDEFAULT, (int)CreateWindowFlags.CW_USEDEFAULT, // Position - default initialWidth, initialHeight, // Size - initial IntPtr.Zero, // No parent window IntPtr.Zero, // No window menu Kernel32.GetModuleHandle(null), IntPtr.Zero ); if (windowHandle == IntPtr.Zero) { CheckError("Couldn't create window.", true); return; } Engine.Log.Trace("Window created.", MessageSource.Win32); string[] args = Environment.GetCommandLineArgs(); bool forceAngle = CommandLineParser.FindArgument(args, "angle", out string _); bool forceMesa = CommandLineParser.FindArgument(args, "software", out string _); // Create graphics context. if (!forceAngle && !forceMesa) { try { var wgl = new WglGraphicsContext(); wgl.Init(User32.GetDC(_helperWindowHandle), windowHandle, this); if (wgl.Valid) { Context = wgl; } } catch (Exception ex) { Engine.Log.Warning($"Couldn't create WGL context, falling back if possible.\n{ex}", MessageSource.Win32); } } #if ANGLE if (Context == null && !forceMesa) { try { var egl = new EglGraphicsContext(); egl.Init(User32.GetDC(windowHandle), windowHandle, this); if (egl.Valid) { Context = egl; } } catch (Exception ex) { Engine.Log.Warning($"Couldn't create EGL context, falling back if possible.\n{ex}", MessageSource.Win32); } } #endif if (Context == null) { try { var gallium = new GalliumGraphicsContext(); gallium.Init(windowHandle, this); if (gallium.Valid) { Context = gallium; } } catch (Exception ex) { Engine.CriticalError(new Exception("Couldn't create MESA context.", ex)); } } if (Context == null) { Engine.CriticalError(new Exception("Couldn't create graphics context!")); return; } // Adjust window size to account for DPI scaling of the window frame and optionally DPI scaling of the content area. // This cannot be done until we know what monitor it was placed on - so it's done post creation. var rect = new Rect { Right = (int)config.HostSize.X, Bottom = (int)config.HostSize.Y }; rect.ClientToScreen(windowHandle); GetFullWindowRect(ref rect); User32.SetWindowPos(_windowHandle, IntPtr.Zero, rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top, WindowPositionFlags.SWP_NOACTIVATE | WindowPositionFlags.SWP_NOZORDER); _windowHandle = windowHandle; }