public static WINDOWPLACEMENT GetPlacement(IntPtr hwnd)
 {
     WINDOWPLACEMENT placement = new WINDOWPLACEMENT();
     placement.length = Marshal.SizeOf(placement);
     GetWindowPlacement(hwnd, ref placement);
     return placement;
 }
Пример #2
0
        private void SyncWindowState(string newWindowState)
        {
            _logger.Info("Setting window state to {0}", newWindowState);
            
            try
            {
                FormWindowState newState;
                bool fullscreen = false;
                if (string.Equals(newWindowState, "fullscreen", StringComparison.OrdinalIgnoreCase))
                {
                    newState = FormWindowState.Maximized;
                    fullscreen = true;
                }
                else if (string.Equals(newWindowState, "maximized", StringComparison.OrdinalIgnoreCase))
                {
                    newState = FormWindowState.Maximized;
                    fullscreen = true;
                }
                else if (string.Equals(newWindowState, "minimized", StringComparison.OrdinalIgnoreCase))
                {
                    newState = FormWindowState.Minimized;
                }
                else
                {
                    newState = FormWindowState.Normal;
                }

                _form.InvokeIfRequired(() =>
                {
                    _form.WindowState = newState;
                });

                if (fullscreen)
                {
                    NativeWindowMethods.SetWindowPos(_windowHandle, -1, _form.Left, _form.Top, _form.Width, _form.Height, 0);
                    //var placement = new WINDOWPLACEMENT();
                    //placement.showCmd = ShowWindowCommands.Maximized;
                    //placement.length = Marshal.SizeOf(typeof(WINDOWPLACEMENT));
                    //NativeWindowMethods.SetWindowPlacement(_windowHandle, ref placement);
                }
                else if (newState == FormWindowState.Maximized)
                {
                    //NativeWindowMethods.SetWindowPos(_windowHandle, -1, _form.Left, _form.Top, _form.Width, _form.Height, 0);
                    var placement = new WINDOWPLACEMENT();
                    placement.showCmd = ShowWindowCommands.Maximized;
                    placement.length = Marshal.SizeOf(typeof(WINDOWPLACEMENT));
                    NativeWindowMethods.SetWindowPlacement(_windowHandle, ref placement);
                }
                else if (newState == FormWindowState.Normal)
                {
                    var placement = new WINDOWPLACEMENT();
                    placement.showCmd = ShowWindowCommands.Normal;
                    NativeWindowMethods.SetWindowPos(_windowHandle, -2, _form.Left, _form.Top, _form.Width, _form.Height, 0);
                    //NativeWindowMethods.SetWindowPlacement(_windowHandle, ref placement);
                }

                if (newState != FormWindowState.Minimized)
                {
                    NativeWindowMethods.SetForegroundWindow(_windowHandle);
                }
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error syncing window positions", ex);
            }
        }
Пример #3
0
        private void SyncWindowState(string newWindowState)
        {
            _logger.Info("Setting window state to {0}", newWindowState);

            try
            {
                FormWindowState newState;
                bool            fullscreen = false;
                if (string.Equals(newWindowState, "fullscreen", StringComparison.OrdinalIgnoreCase))
                {
                    newState   = FormWindowState.Maximized;
                    fullscreen = true;
                }
                else if (string.Equals(newWindowState, "maximized", StringComparison.OrdinalIgnoreCase))
                {
                    newState   = FormWindowState.Maximized;
                    fullscreen = true;
                }
                else if (string.Equals(newWindowState, "minimized", StringComparison.OrdinalIgnoreCase))
                {
                    newState = FormWindowState.Minimized;
                }
                else
                {
                    newState = FormWindowState.Normal;
                }

                _form.InvokeIfRequired(() =>
                {
                    _form.WindowState = newState;
                });

                if (fullscreen)
                {
                    NativeWindowMethods.SetWindowPos(_windowHandle, -1, _form.Left, _form.Top, _form.Width, _form.Height, 0);
                    //var placement = new WINDOWPLACEMENT();
                    //placement.showCmd = ShowWindowCommands.Maximized;
                    //placement.length = Marshal.SizeOf(typeof(WINDOWPLACEMENT));
                    //NativeWindowMethods.SetWindowPlacement(_windowHandle, ref placement);
                }
                else if (newState == FormWindowState.Maximized)
                {
                    //NativeWindowMethods.SetWindowPos(_windowHandle, -1, _form.Left, _form.Top, _form.Width, _form.Height, 0);
                    var placement = new WINDOWPLACEMENT();
                    placement.showCmd = ShowWindowCommands.Maximized;
                    placement.length  = Marshal.SizeOf(typeof(WINDOWPLACEMENT));
                    NativeWindowMethods.SetWindowPlacement(_windowHandle, ref placement);
                }
                else if (newState == FormWindowState.Normal)
                {
                    var placement = new WINDOWPLACEMENT();
                    placement.showCmd = ShowWindowCommands.Normal;
                    NativeWindowMethods.SetWindowPos(_windowHandle, -2, _form.Left, _form.Top, _form.Width, _form.Height, 0);
                    //NativeWindowMethods.SetWindowPlacement(_windowHandle, ref placement);
                }

                if (newState != FormWindowState.Minimized)
                {
                    NativeWindowMethods.SetForegroundWindow(_windowHandle);
                }
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error syncing window positions", ex);
            }
        }
 public static extern bool SetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
 private static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);