Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application stuck in full screen?

Tags:

c#

winforms

To reproduce my problem please do the following:

  1. Create a new Windows Form Application in C#.
  2. In the Properties window of Form1 set FormBorderStyle to None.
  3. Launch program and press Windows+Up.
  4. Now you are stuck in full screen.

In the default FormBorderStyle setting the MaximizeBox property to false will disable the Windows+Up fullscreen shortcut.

If the FormBorderStyle is set to None Microsoft decided it would be a good idea to disable all the Windows+Arrow key shortcuts except for the up arrow and then disable the disabling of the MaximizeBox property.

Is this a glitch? Any simple way to disable this shortcut function the selfsame way it is disabled on all the other FormBorderStyles?

like image 451
CodeCamper Avatar asked Jun 05 '13 05:06

CodeCamper


People also ask

How do you get a program out of full screen mode?

The most common way to get out of full screen mode on Windows 10 is to use the 11th function key. To leave full screen mode on Windows 10, press F11 located near the top-right of your keyboard. You can press F11 again to return.

Why am I stuck on full screen?

The usual way to get into and out of full screen mode is by using the F11 key. If this does not work for you, try to hit Alt + Space to open the application menu and click (or use the keyboard) to choose Restore or Minimize. Another way is to hit Ctrl + Shift + Esc to open the Task Manager.


1 Answers

Windows does this by calling SetWindowPos() to change the position and size of the window. A window can be notified about this by listening for the WM_WINDOWPOSCHANGING message and override the settings. Lots of things you can do, like still giving the operation a meaning by adjusting the size and position to your liking. You completely prevent it by turning on the NOSIZE and NOMOVE flags.

Paste this code into your form:

    private bool AllowWindowChange;

    private struct WINDOWPOS {
        public IntPtr hwnd, hwndInsertAfter;
        public int x, y, cx, cy;
        public int flags;
    }

    protected override void WndProc(ref Message m) {
        // Trap WM_WINDOWPOSCHANGING
        if (m.Msg == 0x46 && !AllowWindowChange) {
            var wpos = (WINDOWPOS)System.Runtime.InteropServices.Marshal.PtrToStructure(m.LParam, typeof(WINDOWPOS));
            wpos.flags |= 0x03; // Turn on SWP_NOSIZE | SWP_NOMOVE
            System.Runtime.InteropServices.Marshal.StructureToPtr(wpos, m.LParam, false);
        }
        base.WndProc(ref m);
    }

When you want to change the window yourself, simply set the AllowWindowChange field temporarily to true.

like image 103
Hans Passant Avatar answered Sep 28 '22 03:09

Hans Passant