示例#1
0
        protected override WindowStylePlacement GetWindowStylePlacement(WindowState state)
        {
            WindowStylePlacement windowStyle = new WindowStylePlacement(_options);

            if (_options.UseCustomStyle && _options != null && _options.CustomStyle.IsValid())
            {
                return(GetWindowStyles(_options.CustomStyle, state));
            }

            var styles   = WS.OVERLAPPEDWINDOW | WS.CLIPCHILDREN | WS.CLIPSIBLINGS;
            var exStyles = WS_EX.APPWINDOW | WS_EX.WINDOWEDGE | WS_EX.TRANSPARENT;

            windowStyle.Styles   = styles;
            windowStyle.ExStyles = exStyles;
            windowStyle.RECT     = GetWindowBounds();

            switch (state)
            {
            case WindowState.Normal:
                windowStyle.ShowCommand = SW.SHOWNORMAL;
                break;

            case WindowState.Maximize:
                windowStyle.Styles     |= WS.MAXIMIZE;
                windowStyle.ShowCommand = SW.SHOWMAXIMIZED;
                break;

            default:
                windowStyle.ShowCommand = SW.SHOWNORMAL;
                break;
            }

            return(windowStyle);
        }
        protected WindowStylePlacement GetWindowStyles(WindowCustomStyle customCreationStyle, WindowState state)
        {
            WindowStylePlacement windowStyle = new WindowStylePlacement(_options);
            var styles   = (WS)customCreationStyle.WindowStyles;
            var exStyles = (WS_EX)customCreationStyle.WindowExStyles;

            windowStyle.Styles   = styles;
            windowStyle.ExStyles = exStyles;
            windowStyle.RECT     = GetWindowBounds();

            switch (state)
            {
            case WindowState.Normal:
                windowStyle.ShowCommand = SW.SHOWNORMAL;
                break;

            case WindowState.Maximize:
                windowStyle.Styles     |= WS.MAXIMIZE;
                windowStyle.ShowCommand = SW.SHOWMAXIMIZED;
                break;

            case WindowState.Fullscreen:
                windowStyle.ShowCommand = SW.SHOWMAXIMIZED;
                break;

            default:
                break;
            }

            return(windowStyle);
        }
        protected override WindowStylePlacement GetWindowStylePlacement(WindowState state)
        {
            WindowStylePlacement windowStylePlacement = base.GetWindowStylePlacement(state);

            if (!_windowFrameless)
            {
                return(windowStylePlacement);
            }

            windowStylePlacement.Styles = WS.POPUPWINDOW | WS.CLIPCHILDREN | WS.CLIPSIBLINGS
                                          | WS.SIZEBOX | WS.MINIMIZEBOX | WS.MAXIMIZEBOX;


            return(windowStylePlacement);
        }
        protected virtual void PlaceWindow(IntPtr hWnd, WindowStylePlacement stylePlacement)
        {
            if (_options.Fullscreen || _options.KioskMode)
            {
                SetFullscreenScreen(hWnd, (int)stylePlacement.Styles, (int)stylePlacement.ExStyles);
            }
            else
            {
                // Center window if State is Normal
                if (_options.WindowState == WindowState.Normal && _options.StartCentered)
                {
                    WindowHelper.CenterWindowToScreen(hWnd);
                }
            }

            WINDOWPLACEMENT wpPrev;
            var             placement = GetWindowPlacement(hWnd, out wpPrev);

            if (placement == BOOL.TRUE)
            {
                _windoStylePlacement.WindowPlacement = wpPrev;
            }
        }
        public unsafe virtual void CreateWindow(IWindowOptions options, bool debugging)
        {
            _keyboadHandler?.SetNativeHost(this);
            _options         = options;
            _windowFrameless = _options.WindowFrameless;

            _wndProc = WndProc;
            _consoleParentInstance = GetConsoleWindow();
            _options.WindowState   = (_options.Fullscreen || _options.KioskMode) ?  WindowState.Fullscreen : _options.WindowState;
            _windoStylePlacement   = new WindowStylePlacement(_options);

            User32.WNDCLASS wcex = new User32.WNDCLASS();
            wcex.style         = User32.CS.HREDRAW | User32.CS.VREDRAW;
            wcex.lpfnWndProc   = Marshal.GetFunctionPointerForDelegate(_wndProc);
            wcex.cbClsExtra    = 0;
            wcex.cbWndExtra    = 0;
            wcex.hIcon         = GetIconHandle();
            wcex.hCursor       = User32.LoadCursorW(IntPtr.Zero, (IntPtr)CursorResourceId.IDC_ARROW);
            wcex.hbrBackground = Gdi32.GetStockObject(Gdi32.StockObject.WHITE_BRUSH);
            wcex.lpszMenuName  = null;
            wcex.hInstance     = _consoleParentInstance;

            fixed(char *c = Chromely_WINDOW_CLASS)
            {
                wcex.lpszClassName = c;
            }

            if (User32.RegisterClassW(ref wcex) == 0)
            {
                Logger.Instance.Log.LogError("Chromelywindow registration failed");
                return;
            }

            var stylePlacement = GetWindowStylePlacement(_options.WindowState);

            var hWnd = User32.CreateWindowExW(
                stylePlacement.ExStyles,
                Chromely_WINDOW_CLASS,
                _options.Title,
                stylePlacement.Styles,
                stylePlacement.RECT.left,
                stylePlacement.RECT.top,
                stylePlacement.RECT.Width,
                stylePlacement.RECT.Height,
                IntPtr.Zero,
                IntPtr.Zero,
                _consoleParentInstance,
                null);

            if (hWnd == IntPtr.Zero)
            {
                Logger.Instance.Log.LogError("Chromelywindow creation failed");
                return;
            }

            PlaceWindow(hWnd, stylePlacement);
            InstallHooks(hWnd);
            ShowWindow(hWnd, stylePlacement.ShowCommand);
            UpdateWindow(hWnd);
            RegisterHotKeys(hWnd);
        }
        protected virtual WindowStylePlacement GetWindowStylePlacement(WindowState state)
        {
            WindowStylePlacement windowStyle = new WindowStylePlacement(_options);

            if (_options.UseCustomStyle && _options != null && _options.CustomStyle.IsValid())
            {
                return(GetWindowStyles(_options.CustomStyle, state));
            }

            var styles   = WindowStylePlacement.NormalStyles;
            var exStyles = WindowStylePlacement.NormalExStyles;

            if (_options.DisableResizing)
            {
                styles  = WS.OVERLAPPEDWINDOW & ~WS.THICKFRAME | WS.CLIPCHILDREN | WS.CLIPSIBLINGS;
                styles &= ~WS.MAXIMIZEBOX;
            }

            if (_options.DisableMinMaximizeControls)
            {
                styles &= ~WS.MINIMIZEBOX;
                styles &= ~WS.MAXIMIZEBOX;
            }

            if (_options.WindowFrameless)
            {
                styles  = WS.POPUPWINDOW | WS.CLIPCHILDREN | WS.CLIPSIBLINGS;
                styles |= WS.SIZEBOX;
            }

            if (_options.KioskMode || _options.Fullscreen)
            {
                styles   &= ~(WS.CAPTION);
                exStyles &= ~(WS_EX.DLGMODALFRAME | WS_EX.WINDOWEDGE | WS_EX.CLIENTEDGE | WS_EX.STATICEDGE);
                state     = WindowState.Fullscreen;
                _options.DisableResizing = _options.KioskMode ? true : _options.DisableResizing;
            }

            windowStyle.Styles   = styles;
            windowStyle.ExStyles = exStyles;
            windowStyle.RECT     = GetWindowBounds();

            switch (state)
            {
            case WindowState.Normal:
                windowStyle.ShowCommand = SW.SHOWNORMAL;
                break;

            case WindowState.Maximize:
                windowStyle.Styles     |= WS.MAXIMIZE;
                windowStyle.ShowCommand = SW.SHOWMAXIMIZED;
                break;

            case WindowState.Fullscreen:
                windowStyle.ShowCommand = SW.SHOWMAXIMIZED;
                break;

            default:
                break;
            }

            return(windowStyle);
        }