示例#1
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);
 }
示例#2
0
        public static unsafe Atom RegisterClass(ref WindowClass windowClass)
        {
            Atom atom;

            using (var marshaller = new WindowClass.Marshaller())
            {
                marshaller.FillNative(out WNDCLASSEX native, ref windowClass);
                atom = Imports.RegisterClassExW(ref native);
                if (!atom.IsValid)
                {
                    throw Errors.GetIoExceptionForLastError();
                }
            }

            return(atom);
        }
示例#3
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;
            }
        }
示例#4
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);
        }
示例#5
0
 public static Atom RegisterClass(ref WindowClass windowClass) => WindowMethods.RegisterClass(ref windowClass);