Ejemplo n.º 1
0
        public unsafe static WindowHandle CreateWindow(
            Atom classAtom,
            string?windowName  = null,
            WindowStyles style = WindowStyles.Overlapped,
            ExtendedWindowStyles extendedStyle = ExtendedWindowStyles.Default,
            Rectangle bounds          = default,
            WindowHandle parentWindow = default,
            MenuHandle menuHandle     = default,
            ModuleInstance?instance   = null,
            IntPtr parameters         = default)
        {
            WindowHandle window = Imports.CreateWindowExW(
                extendedStyle,
                (char *)classAtom.ATOM,
                windowName,
                style,
                bounds.X,
                bounds.Y,
                bounds.Width,
                bounds.Height,
                parentWindow,
                menuHandle,
                instance ?? ModuleInstance.Null,
                parameters);

            if (window.IsInvalid)
            {
                Error.ThrowLastError();
            }

            return(window);
        }
Ejemplo n.º 2
0
 public static MenuHandle CreateMenu()
 {
     MenuHandle menu = new MenuHandle(Imports.CreateMenu(), ownsHandle: true);
     if (menu.IsInvalid)
         Error.ThrowLastError();
     return menu;
 }
Ejemplo n.º 3
0
        public WindowHandle CreateWindow(
            Rectangle bounds,
            string windowName  = null,
            WindowStyles style = WindowStyles.Overlapped,
            ExtendedWindowStyles extendedStyle = ExtendedWindowStyles.Default,
            bool isMainWindow         = false,
            WindowHandle parentWindow = default,
            IntPtr parameters         = default,
            MenuHandle menuHandle     = default)
        {
            if (!IsRegistered)
            {
                throw new ArgumentException("Window class must be registered before using.");
            }

            WindowHandle window = Windows.CreateWindow(
                Atom,
                windowName,
                style,
                extendedStyle,
                bounds,
                parentWindow,
                menuHandle,
                parameters: parameters);

            if (isMainWindow)
            {
                MainWindow = window;
            }

            return(window);
        }
Ejemplo n.º 4
0
 public static void CreateMainWindowAndRun(
     WindowClass windowClass,
     string?windowTitle = null,
     WindowStyles style = WindowStyles.OverlappedWindow,
     ExtendedWindowStyles extendedStyle = ExtendedWindowStyles.Default,
     MenuHandle menuHandle = default)
 {
     CreateMainWindowAndRun(windowClass, DefaultBounds, windowTitle, style, extendedStyle, menuHandle);
 }
Ejemplo n.º 5
0
        public static MenuHandle CreateMenu()
        {
            MenuHandle menu = new MenuHandle(Imports.CreateMenu(), ownsHandle: true);

            if (menu.IsInvalid)
            {
                throw Error.GetExceptionForLastError();
            }
            return(menu);
        }
Ejemplo n.º 6
0
 public WindowHandle CreateWindow(
     string windowName  = null,
     WindowStyles style = WindowStyles.Overlapped,
     ExtendedWindowStyles extendedStyle = ExtendedWindowStyles.Default,
     bool isMainWindow         = false,
     WindowHandle parentWindow = default,
     IntPtr parameters         = default,
     MenuHandle menuHandle     = default)
 {
     return(CreateWindow(Windows.DefaultBounds, windowName, style, extendedStyle, isMainWindow, parentWindow, parameters, menuHandle));
 }
Ejemplo n.º 7
0
        public unsafe static void AppendMenu(MenuHandle menu, string text, int id, bool disabled = false, bool @checked = false)
        {
            MenuFlags flags = MenuFlags.String;
            if (disabled) flags |= MenuFlags.Grayed;
            if (@checked) flags |= MenuFlags.Checked;

            fixed (char* c = text)
            {
                Error.ThrowLastErrorIfFalse(
                    Imports.AppendMenuW(menu, flags, (IntPtr)id, (IntPtr)c));
            }
        }
Ejemplo n.º 8
0
 public override WindowHandle CreateWindow(
     Rectangle bounds,
     string?windowName  = null,
     WindowStyles style = WindowStyles.Overlapped,
     ExtendedWindowStyles extendedStyle = ExtendedWindowStyles.Default,
     bool isMainWindow         = false,
     WindowHandle parentWindow = default,
     IntPtr parameters         = default,
     MenuHandle menuHandle     = default)
 {
     style |= (WindowStyles)ButtonStyle;
     return(base.CreateWindow(bounds, windowName, style, extendedStyle, isMainWindow, parentWindow, parameters, menuHandle));
 }
Ejemplo n.º 9
0
        public unsafe static void AppendMenu(MenuHandle menu, string text, int id, bool disabled = false, bool @checked = false)
        {
            MenuFlags flags = MenuFlags.String;

            if (disabled)
            {
                flags |= MenuFlags.Grayed;
            }
            if (@checked)
                flags |= MenuFlags.Checked;

            fixed(char *c = text)
            {
                if (!Imports.AppendMenuW(menu, flags, (IntPtr)id, (IntPtr)c))
                {
                    throw Error.GetExceptionForLastError();
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates a window of the specified class and processes the message loop.
        /// Does not return until the message loop exits.
        /// </summary>
        public static void CreateMainWindowAndRun(
            WindowClass windowClass,
            Rectangle bounds,
            string?windowTitle = null,
            WindowStyles style = WindowStyles.OverlappedWindow,
            ExtendedWindowStyles extendedStyle = ExtendedWindowStyles.Default,
            MenuHandle menuHandle = default)
        {
            if (!windowClass.IsRegistered)
            {
                windowClass.Register();
            }

            WindowHandle mainWindow = windowClass.CreateWindow(
                bounds,
                windowTitle,
                style,
                extendedStyle,
                isMainWindow: true,
                menuHandle: menuHandle);

            try
            {
                mainWindow.ShowWindow(ShowWindowCommand.Normal);
                mainWindow.UpdateWindow();

                while (GetMessage(out WindowMessage message))
                {
                    TranslateMessage(ref message);
                    DispatchMessage(ref message);
                }

                // Make sure our window class doesn't get collected while we're pumping messages
                GC.KeepAlive(windowClass);
            }
            catch
            {
                // Hit the P/Invoke directly as we want to throw the original error.
                Imports.DestroyWindow(mainWindow);
                throw;
            }
        }
Ejemplo n.º 11
0
        public unsafe static WindowHandle CreateWindow(
            string className,
            string windowName  = null,
            WindowStyles style = WindowStyles.Overlapped,
            ExtendedWindowStyles extendedStyle = ExtendedWindowStyles.Default,
            Rectangle bounds          = default,
            WindowHandle parentWindow = default,
            MenuHandle menuHandle     = default,
            ModuleInstance instance   = default,
            IntPtr parameters         = default)
        {
            WindowHandle window;

            fixed(char *name = className)
            {
                window = Imports.CreateWindowExW(
                    extendedStyle,
                    name,
                    windowName,
                    style,
                    bounds.X,
                    bounds.Y,
                    bounds.Width,
                    bounds.Height,
                    parentWindow,
                    menuHandle,
                    instance ?? ModuleInstance.Null,
                    parameters);
            }

            if (window.IsInvalid)
            {
                throw Error.GetExceptionForLastError();
            }

            return(window);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates a window of the specified class and processes the message loop.
        /// Does not return until the message loop exits.
        /// </summary>
        public static void CreateMainWindowAndRun(
            WindowClass windowClass,
            Rectangle bounds,
            string windowTitle = null,
            WindowStyles style = WindowStyles.OverlappedWindow,
            ExtendedWindowStyles extendedStyle = ExtendedWindowStyles.Default,
            MenuHandle menuHandle = default)
        {
            // Hack for launching as a .NET Core Windows Application
            Console.Console.TryFreeConsole();

            if (!windowClass.IsRegistered)
            {
                windowClass.Register();
            }

            WindowHandle mainWindow = windowClass.CreateWindow(
                bounds,
                windowTitle,
                style,
                extendedStyle,
                isMainWindow: true,
                menuHandle: menuHandle);

            mainWindow.ShowWindow(ShowWindowCommand.Normal);
            mainWindow.UpdateWindow();

            while (GetMessage(out WindowMessage message))
            {
                TranslateMessage(ref message);
                DispatchMessage(ref message);
            }

            // Make sure our window class doesn't get collected while were pumping
            GC.KeepAlive(windowClass);
        }