Exemple #1
0
        //private readonly WindowStyles _windowFullscreenStyle = WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_GROUP | WindowStyles.WS_TABSTOP;

        public unsafe Window(string title, int width, int height, WindowFlags flags = WindowFlags.None)
        {
            Title = title;

            int  x         = CW_USEDEFAULT;
            int  y         = CW_USEDEFAULT;
            bool resizable = (flags & WindowFlags.Resizable) != WindowFlags.None;

            _windowWindowedStyle = WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU | WindowStyles.WS_MINIMIZEBOX | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_BORDER | WindowStyles.WS_DLGFRAME | WindowStyles.WS_THICKFRAME | WindowStyles.WS_GROUP | WindowStyles.WS_TABSTOP;

            if (resizable)
            {
                _windowWindowedStyle |= WindowStyles.WS_SIZEBOX | WindowStyles.WS_MAXIMIZEBOX;
            }

            _windowStyle = _windowWindowedStyle;

            RawRect windowRect = new RawRect(0, 0, width, height);

            // Adjust according to window styles
            AdjustWindowRectEx(ref windowRect, _windowStyle, false, WindowExStyles.WS_EX_OVERLAPPEDWINDOW);

            int windowWidth  = windowRect.Right - windowRect.Left;
            int windowHeight = windowRect.Bottom - windowRect.Top;

            bool centerWindow = true;

            if (centerWindow)
            {
                if (windowWidth > 0 && windowHeight > 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 - windowWidth) / 2;
                    y = (screenHeight - windowHeight) / 2;
                }
            }

            IntPtr hwnd;

            fixed(char *lpWndClassName = WndClassName)
            {
                fixed(char *lpWindowName = Title)
                {
                    hwnd = CreateWindowExW(
                        (uint)WindowExStyles.WS_EX_OVERLAPPEDWINDOW,
                        (ushort *)lpWndClassName,
                        (ushort *)lpWindowName,
                        (uint)_windowStyle,
                        x,
                        y,
                        windowWidth,
                        windowHeight,
                        IntPtr.Zero,
                        IntPtr.Zero,
                        IntPtr.Zero,
                        null);
                }
            }

            if (hwnd == IntPtr.Zero)
            {
                return;
            }

            ShowWindow(hwnd, ShowWindowCommand.Normal);
            Handle = hwnd;

            GetClientRect(hwnd, out windowRect);
            Extent = new VkExtent2D(windowRect.Right - windowRect.Left, windowRect.Bottom - windowRect.Top);
        }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VkRect2D"/> structure.
 /// </summary>
 /// <param name="width">The width component of the extent.</param>
 /// <param name="height">The height component of the extent.</param>
 public VkRect2D(int width, int height)
 {
     offset = default;
     extent = new VkExtent2D(width, height);
 }
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VkRect2D"/> structure.
 /// </summary>
 /// <param name="x">The X component of the offset.</param>
 /// <param name="y">The Y component of the offset.</param>
 /// <param name="width">The width component of the extent.</param>
 /// <param name="height">The height component of the extent.</param>
 public VkRect2D(int x, int y, int width, int height)
 {
     offset = new VkOffset2D(x, y);
     extent = new VkExtent2D(width, height);
 }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VkRect2D"/> structure.
 /// </summary>
 /// <param name="extent">The extent component of the rectangle.</param>
 public VkRect2D(VkExtent2D extent)
 {
     offset      = default;
     this.extent = extent;
 }
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VkRect2D"/> structure.
 /// </summary>
 /// <param name="offset">The offset component of the rectangle.</param>
 /// <param name="extent">The extent component of the rectangle.</param>
 public VkRect2D(VkOffset2D offset, VkExtent2D extent)
 {
     this.offset = offset;
     this.extent = extent;
 }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of <see cref="VkExtent3D"/> structure.
 /// </summary>
 /// <param name="extent2D">The <see cref="VkExtent2D"/> containing width and height.</param>
 /// <param name="depth">The depth component of the extent.</param>
 public VkExtent3D(VkExtent2D extent2D, uint depth)
 {
     width      = extent2D.width;
     height     = extent2D.height;
     this.depth = depth;
 }