Example #1
0
        public Window(
            WindowClass windowClass,
            Rectangle bounds,
            string windowName          = default,
            User32.WS style            = User32.WS.OVERLAPPED,
            User32.WS_EX extendedStyle = User32.WS_EX.DEFAULT,
            bool isMainWindow          = false,
            Window parentWindow        = default,
            IntPtr parameters          = default,
            IntPtr menuHandle          = default)
        {
            _windowClass = windowClass;
            if (!_windowClass.IsRegistered)
            {
                _windowClass.Register();
            }

            Handle = _windowClass.CreateWindow(
                bounds,
                windowName,
                style,
                extendedStyle,
                isMainWindow,
                parentWindow?.Handle ?? default,
                parameters,
                menuHandle);
        }
Example #2
0
 public IntPtr CreateWindow(
     string windowName          = null,
     User32.WS style            = User32.WS.OVERLAPPED,
     User32.WS_EX extendedStyle = default,
     bool isMainWindow          = false,
     IntPtr parentWindow        = default,
     IntPtr parameters          = default,
     IntPtr menuHandle          = default)
 {
     return(CreateWindow(
                DefaultBounds,
                windowName,
                style,
                extendedStyle,
                isMainWindow,
                parentWindow,
                parameters,
                menuHandle));
 }
Example #3
0
        public unsafe IntPtr CreateWindow(
            RECT bounds,
            string windowName          = null,
            User32.WS style            = User32.WS.OVERLAPPED,
            User32.WS_EX extendedStyle = default,
            bool isMainWindow          = false,
            IntPtr parentWindow        = default,
            IntPtr parameters          = default,
            IntPtr menuHandle          = default)
        {
            if (!IsRegistered)
            {
                throw new ArgumentException("Window class must be registered before using.");
            }

            IntPtr window = User32.CreateWindowExW(
                dwExStyle: extendedStyle,
                lpClassName: (char *)Atom,
                lpWindowName: windowName,
                dwStyle: style,
                X: bounds.X,
                Y: bounds.Y,
                nWidth: bounds.Width,
                nHeight: bounds.Height,
                hWndParent: parentWindow,
                hMenu: menuHandle,
                hInst: IntPtr.Zero,
                lpParam: parameters);

            if (isMainWindow)
            {
                MainWindow = window;
            }

            return(window);
        }
        public unsafe IntPtr CreateWindow(
            RECT bounds,
            string windowName          = null,
            User32.WS style            = User32.WS.OVERLAPPED,
            User32.WS_EX extendedStyle = default,
            bool isMainWindow          = false,
            IntPtr parentWindow        = default,
            IntPtr parameters          = default,
            IntPtr menuHandle          = default)
        {
            if (!IsRegistered)
            {
                throw new ArgumentException("Window class must be registered before using.");
            }

            IntPtr window;

            if (Atom.IsValid)
            {
                window = User32.CreateWindowExW(
                    dwExStyle: extendedStyle,
                    lpClassName: (char *)Atom.ATOM,
                    lpWindowName: windowName,
                    dwStyle: style,
                    X: bounds.X,
                    Y: bounds.Y,
                    nWidth: bounds.Width,
                    nHeight: bounds.Height,
                    hWndParent: parentWindow,
                    hMenu: menuHandle,
                    hInst: IntPtr.Zero,
                    lpParam: parameters);
            }
            else
            {
                fixed(char *atom = _className)
                {
                    window = User32.CreateWindowExW(
                        dwExStyle: extendedStyle,
                        lpClassName: atom,
                        lpWindowName: windowName,
                        dwStyle: style,
                        X: bounds.X,
                        Y: bounds.Y,
                        nWidth: bounds.Width,
                        nHeight: bounds.Height,
                        hWndParent: parentWindow,
                        hMenu: menuHandle,
                        hInst: IntPtr.Zero,
                        lpParam: parameters);
                }
            }

            if (window == IntPtr.Zero)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            if (!Atom.IsValid)
            {
                Atom = User32.GetClassLong(window, User32.GCL.ATOM);
            }

            if (isMainWindow)
            {
                MainWindow = window;
            }

            return(window);
        }