Exemplo n.º 1
0
        public static WindowHandle CreateWindow(
            Atom className,
            string windowName,
            WindowStyles style,
            ExtendedWindowStyles extendedStyle,
            int x,
            int y,
            int width,
            int height,
            WindowHandle parentWindow,
            IntPtr menuHandle,
            ModuleInstance instance,
            IntPtr parameters)
        {
            WindowHandle window = Imports.CreateWindowExW(
                extendedStyle,
                className,
                windowName,
                style,
                x,
                y,
                width,
                height,
                parentWindow,
                menuHandle,
                instance ?? ModuleInstance.Null,
                parameters);

            if (window == WindowHandle.Null)
            {
                throw Errors.GetIoExceptionForLastError();
            }

            return(window);
        }
Exemplo n.º 2
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);
        }
Exemplo 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);
        }
Exemplo n.º 4
0
        public static void SetWindowStyles(Window window, ExtendedWindowStyles styles)
        {
            var hwnd          = new WindowInteropHelper(window).Handle;
            var extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE);

            extendedStyle |= (int)styles;
            SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle);
        }
Exemplo n.º 5
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);
 }
Exemplo n.º 6
0
 //Documentation: https://msdn.microsoft.com/en-us/library/windows/desktop/ms632680(v=vs.85).aspx
 private static extern IntPtr CreateWindowEx(
     ExtendedWindowStyles extendedStyle,
     IntPtr windowClassAtom,
     string windowName,
     WindowStyles style,
     int x, int y, int width, int height,
     IntPtr parent,
     IntPtr menu,
     IntPtr instance,
     IntPtr param);
Exemplo n.º 7
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));
 }
Exemplo n.º 8
0
 public static WindowHandle CreateWindow(
     ModuleInstance instance,
     string className,
     string windowName,
     WindowStyles style,
     ExtendedWindowStyles extendedStyle = ExtendedWindowStyles.None,
     int x      = WindowDefines.CW_USEDEFAULT,
     int y      = WindowDefines.CW_USEDEFAULT,
     int width  = WindowDefines.CW_USEDEFAULT,
     int height = WindowDefines.CW_USEDEFAULT)
 => WindowMethods.CreateWindow(className, windowName, style, extendedStyle, x, y, width, height, instance);
Exemplo n.º 9
0
 public static WindowHandle CreateWindow(
     Atom className,
     string windowName,
     WindowStyles style,
     ExtendedWindowStyles extendedStyle = ExtendedWindowStyles.None,
     int x      = WindowDefines.CW_USEDEFAULT,
     int y      = WindowDefines.CW_USEDEFAULT,
     int width  = WindowDefines.CW_USEDEFAULT,
     int height = WindowDefines.CW_USEDEFAULT,
     ModuleInstance instance = null)
 {
     return(CreateWindow(className, windowName, style, extendedStyle, x, y, width, height, WindowHandle.Null, IntPtr.Zero, instance, IntPtr.Zero));
 }
Exemplo n.º 10
0
 public static extern WindowHandle CreateWindowExW(
     ExtendedWindowStyles dwExStyle,
     IntPtr lpClassName,
     string lpWindowName,
     WindowStyles dwStyle,
     int x,
     int y,
     int nWidth,
     int nHeight,
     WindowHandle hWndParent,
     IntPtr hMenu,
     ModuleInstance hInstance,
     IntPtr lpParam);
Exemplo n.º 11
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));
 }
Exemplo n.º 12
0
 public static WindowHandle CreateWindow(
     string className,
     string windowName,
     WindowStyles style,
     ExtendedWindowStyles extendedStyle,
     int x,
     int y,
     int width,
     int height,
     WindowHandle parentWindow,
     IntPtr menuHandle,
     ModuleInstance instance,
     IntPtr parameters) => WindowMethods.CreateWindow(
     className, windowName, style, extendedStyle, x, y, width, height, parentWindow, menuHandle, instance, parameters);
Exemplo n.º 13
0
        public static string ToStringFlags(this ExtendedWindowStyles extendedWindowStyles)
        {
            var names  = new HashSet <string>();
            var type   = typeof(ExtendedWindowStyles);
            var values = (ExtendedWindowStyles[])Enum.GetValues(type);

            foreach (var val in values)
            {
                if ((extendedWindowStyles & val) == val)
                {
                    var name = Enum.GetName(type, val);
                    Debug.Assert(name != null, "name != null");
                    names.Add(name);
                }
            }
            return(string.Join(" | ", names));
        }
Exemplo n.º 14
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;
            }
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
 public static UInt32 ToUInt32(this ExtendedWindowStyles extendedWindowStyles)
 {
     return((UInt32)extendedWindowStyles);
 }
Exemplo n.º 18
0
 public static void SetExtendedWindowStyle(IntPtr hWnd, ExtendedWindowStyles exStyle)
 {
     PInvoke.SetWindowLong(hWnd, (int)GWL.GWL_EXSTYLE, (int)exStyle);
 }
Exemplo n.º 19
0
 //Documentation: https://msdn.microsoft.com/en-us/library/windows/desktop/ms632667(v=vs.85).aspx
 private static extern bool AdjustWindowRect(
     ref IntRect rect,
     WindowStyles style,
     bool menu,
     ExtendedWindowStyles extendedStyle);
Exemplo n.º 20
0
#pragma warning restore CS0612 // 类型或成员已过时
        public static ExtendedWindowStyles SetExtendedWindowStyles(IntPtr hWnd, ExtendedWindowStyles styles)
        => (ExtendedWindowStyles)SetWindowStyles(hWnd, WindowStylesKind.ExStyles, (int)styles);
Exemplo n.º 21
0
 public static extern bool AdjustWindowRectEx(
     ref RECT lpRect,
     WindowStyles dwStyle,
     bool bMenu,
     ExtendedWindowStyles dwExStyle);
Exemplo n.º 22
0
 public static extern bool AdjustWindowRectExForDpi([In][Out] ref Rectangle lpRect,
                                                    bool bMenu, ExtendedWindowStyles dwExStyle, uint dpi);