Example #1
0
        IntPtr CreateWindow(int x, int y, int width, int height, string title, GameWindowFlags options, DisplayDevice device, IntPtr parentHandle)
        {
            // Use win32 to create the native window.
            // Keep in mind that some construction code runs in the WM_CREATE message handler.

            // The style of a parent window is different than that of a child window.
            // Note: the child window should always be visible, even if the parent isn't.
            WindowStyle         style    = 0;
            ExtendedWindowStyle ex_style = 0;

            if (parentHandle == IntPtr.Zero)
            {
                style   |= WindowStyle.OverlappedWindow | WindowStyle.ClipChildren;
                ex_style = ParentStyleEx;
            }
            else
            {
                style   |= WindowStyle.Visible | WindowStyle.Child | WindowStyle.ClipSiblings;
                ex_style = ChildStyleEx;
            }

            // Find out the final window rectangle, after the WM has added its chrome (titlebar, sidebars etc).
            Win32Rectangle rect = new Win32Rectangle();

            rect.left = x; rect.top = y; rect.right = x + width; rect.bottom = y + height;
            Functions.AdjustWindowRectEx(ref rect, style, false, ex_style);
            // Create the window class that we will use for this window.
            // The current approach is to register a new class for each top-level WinGLWindow we create.
            if (!class_registered)
            {
                ExtendedWindowClass wc = new ExtendedWindowClass();
                wc.Size      = ExtendedWindowClass.SizeInBytes;
                wc.Style     = DefaultClassStyle;
                wc.Instance  = Instance;
                wc.WndProc   = WindowProcedureDelegate;
                wc.ClassName = ClassName;
                wc.Icon      = Icon != null ? Icon.Handle : IntPtr.Zero;
#warning "This seems to resize one of the 'large' icons, rather than using a small icon directly (multi-icon files). Investigate!"
                wc.IconSm = Icon != null ? new Icon(Icon, 16, 16).Handle : IntPtr.Zero;
                wc.Cursor = Functions.LoadCursor(CursorName.Arrow);
                ushort atom = Functions.RegisterClassEx(ref wc);
                if (atom == 0)
                {
                    throw new PlatformException(String.Format("Failed to register window class. Error: {0}", Marshal.GetLastWin32Error()));
                }
                class_registered = true;
            }

            IntPtr window_name = Marshal.StringToHGlobalAuto(title);
            IntPtr handle      = Functions.CreateWindowEx(
                ex_style, ClassName, window_name, style,
                rect.left, rect.top, rect.Width, rect.Height,
                parentHandle, IntPtr.Zero, Instance, IntPtr.Zero);
            if (handle == IntPtr.Zero)
            {
                throw new PlatformException(String.Format("Failed to create window. Error: {0}", Marshal.GetLastWin32Error()));
            }
            return(handle);
        }
Example #2
0
 public WindowProfile(string title, WindowStyle style, ExtendedWindowStyle extStyle, int x, int y, int width, int height)
 {
     Title = title;
     WindowStyle = style;
     ExtendedWindowStyle = extStyle;
     X = x;
     Y = y;
     Width = width;
     Height = height;
 }
Example #3
0
 internal static extern IntPtr CreateWindowEx(
     ExtendedWindowStyle ExStyle,
     [MarshalAs(UnmanagedType.LPTStr)] string className,
     [MarshalAs(UnmanagedType.LPTStr)] string windowName,
     WindowStyle Style,
     int X, int Y,
     int Width, int Height,
     IntPtr HandleToParentWindow,
     IntPtr Menu,
     IntPtr Instance,
     IntPtr Param);
 public static extern IntPtr CreateWindowEx(
     ExtendedWindowStyle ExStyle,
     IntPtr ClassAtom,
     IntPtr WindowName,
     WindowStyle Style,
     int X, int Y,
     int Width, int Height,
     IntPtr HandleToParentWindow,
     IntPtr Menu,
     IntPtr Instance,
     IntPtr Param);
 internal static extern IntPtr CreateWindowEx(
     ExtendedWindowStyle exStyle,
     IntPtr classAtom,
     IntPtr windowName,
     WindowStyle style,
     int x, int y,
     int width, int height,
     IntPtr handleToParentWindow,
     IntPtr menu,
     IntPtr instance,
     IntPtr param
     );
 public void RemoveExtendedStyle(ExtendedWindowStyle style)
 {
     var oldStyle = GetExtendedStyle();
     var newStyle = (oldStyle & (~style));
     SetExtendedStyle(newStyle);
 }
Example #7
0
 internal static extern IntPtr CreateWindowEx(
     ExtendedWindowStyle ExStyle,
     IntPtr ClassAtom,
     IntPtr WindowName,
     WindowStyle Style,
     int X, int Y,
     int Width, int Height,
     IntPtr HandleToParentWindow,
     IntPtr Menu,
     IntPtr Instance,
     IntPtr Param);
Example #8
0
 internal static extern bool AdjustWindowRectEx(
     ref Win32Rectangle lpRect,
     WindowStyle dwStyle,
     [MarshalAs(UnmanagedType.Bool)] bool bMenu,
     ExtendedWindowStyle dwExStyle);
Example #9
0
 internal static extern bool AdjustWindowRectEx(
     ref Win32Rectangle lpRect,
     WindowStyle dwStyle,
     [MarshalAs(UnmanagedType.Bool)] bool bMenu,
     ExtendedWindowStyle dwExStyle);
Example #10
0
 internal static extern IntPtr CreateWindowEx(
     ExtendedWindowStyle ExStyle,
     [MarshalAs(UnmanagedType.LPTStr)] string className,
     [MarshalAs(UnmanagedType.LPTStr)] string windowName,
     WindowStyle Style,
     int X, int Y,
     int Width, int Height,
     IntPtr HandleToParentWindow,
     IntPtr Menu,
     IntPtr Instance,
     IntPtr Param);
        private void CreateWindow()
        {
            _style = WindowStyle.ClipSiblings | WindowStyle.ClipChildren;
            _extendedStyle = ExtendedWindowStyle.ApplicationWindow;

            var fullscreen = true;

            int fullWidth, fullHeight;
            if (fullscreen)
            {
                _style |= WindowStyle.Popup;
                fullWidth = Width;
                fullHeight = Height;

            }
            else
            {
                _style |= WindowStyle.Caption | WindowStyle.SystemMenu | WindowStyle.MinimizeBox;

                var rect = User32.AdjustWindowRectEx(Width, Height, _style, false, _extendedStyle);
                fullWidth = rect.Right - rect.Left;
                fullHeight = rect.Bottom - rect.Top;

            }

            _handle = User32.CreateWindowEx(_extendedStyle, _className, _title, _style, _monitor.Position.X, _monitor.Position.Y, fullWidth,
                                                    fullHeight, IntPtr.Zero, IntPtr.Zero, _instance, IntPtr.Zero);
            if (_handle == IntPtr.Zero)
                throw new Exception(String.Format("Failed to create window. Error: {0}",
                                                  Marshal.GetLastWin32Error()));
        }
Example #12
0
 internal static extern bool AdjustWindowRectEx(ref Rectangle lpRect, WindowStyle dwStyle, bool bMenu, ExtendedWindowStyle dwExStyle);
Example #13
0
 public static extern IntPtr CreateWindowEx(ExtendedWindowStyle style, IntPtr className, string windowName, WindowStyle Style, int x, int y, int width, int height, IntPtr parent, IntPtr menu, IntPtr instance, IntPtr param);
Example #14
0
 private static extern bool AdjustWindowRectEx(ref Win32Rectangle lpRect, WindowStyle dwStyle, bool bMenu, ExtendedWindowStyle dwExStyle);
 public void SetExtendedStyle(ExtendedWindowStyle style)
 {
     var result = SetWindowLong(GetWindowLongOffset.GWL_EXSTYLE, (long)style);
     if (result == 0)
     {
         throw new PInvokeException("Unable to set window extended style");
     }
 }
 public bool HasExtendedStyle(ExtendedWindowStyle style)
 {
     return (GetExtendedStyle() & style) != 0;
 }
Example #17
0
 public static void RemoveExtendedStyle(IntPtr handle, ExtendedWindowStyle style)
 {
     SetExtendedStyle(handle, ExtendedStyle(handle) & ~style);
 }
Example #18
0
 public static void AddExtendedStyle(IntPtr handle, ExtendedWindowStyle style)
 {
     SetExtendedStyle(handle, ExtendedStyle(handle) | style);
 }
Example #19
0
 public static void SetExtendedStyle(IntPtr handle, ExtendedWindowStyle style)
 {
     User32.SetWindowLong(handle, (int)WindowLong.ExtendedStyle, new IntPtr((int)style));
 }
Example #20
0
 public WindowProfile(string title, WindowStyle style, ExtendedWindowStyle extStyle)
     : this(title, style, extStyle, 0, 0, 0, 0)
 {
 }
Example #21
0
        public static void SetExtended(Window window, ExtendedWindowStyle style)
        {
            IntPtr hWnd = new WindowInteropHelper(window).EnsureHandle();

            SetWindowLong(hWnd, (int)GetWindowLongField.GWL_EXSTYLE, (IntPtr)style);
        }
 public void AddExtendedStyle(IntPtr window, ExtendedWindowStyle style)
 {
     var oldStyle = GetExtendedStyle();
     var newStyle = (oldStyle | style);
     SetExtendedStyle(newStyle);
 }
Example #23
0
 public static extern IntPtr CreateWindowExW(ExtendedWindowStyle dwExStyle, string lpClassName,
                                             string lpWindowName,
                                             WindowStyle dwStyle, int x, int y,
                                             int nWidth, int nHeight,
                                             IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance,
                                             IntPtr lpParam);
Example #24
0
 internal static extern bool AdjustWindowRectEx(ref Win32Rectangle lpRect, WindowStyle dwStyle, bool bMenu, ExtendedWindowStyle dwExStyle);
Example #25
0
 public static Rectangle AdjustWindowRectEx(int width, int height, WindowStyle style, bool menu, ExtendedWindowStyle extendedStyle)
 {
     var rect = new Win32Rectangle
         {
             Right = width,
             Bottom = height
         };
     AdjustWindowRectEx(ref rect, style, menu, extendedStyle);
     return rect.ToRectangle();
 }