停留在全屏应用程序? [英] Application stuck in full screen?

查看:176
本文介绍了停留在全屏应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要重现我的问题,请执行以下操作:

To reproduce my problem please do the following:


  1. 在C#中创建一个新的Windows窗体应用程序

  2. 在Form1的属性窗口中设置 FormBorderStyle

  3. <李>启动程序,然后按<大骨节病>窗口 + <大骨节病>最多
  4. 现在,你被卡住全屏。

  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.

在默认的 FormBorderStyle 设置 MaximizeBox 属性为false将禁用<大骨节病>窗口 + <大骨节病>最多全屏快捷方式。

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

如果在 FormBorderStyle 设置为微软决定这将是禁用所有的Windows +箭头键的快捷方式除了箭头,然后禁用禁用一个好主意的 MaximizeBox 属性。

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.

这是一个小故障?所有的简单的方式为禁用此快捷键功能,它是在所有其他FormBorderStyles

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

推荐答案

勾选此解决方案 - 它删除最大化/最小化/标题栏/边框通过API调用

Check this solution - it removes Maximize/Minimize/Titlebar/Border by API calls.

public partial class Form1 : Form
{
    // import necessary API functions to get and set Windows styles for P/Invoke
    [DllImport("user32.dll")]
    internal extern static int SetWindowLong(IntPtr hwnd, int index, int value);

    [DllImport("user32.dll")]
    internal extern static int GetWindowLong(IntPtr hwnd, int index);

    // define constants like they are named in SDK in order to make source more readable
    const int GWL_STYLE = -16;
    const int GWL_EXSTYLE = -20;
    const int WS_MINIMIZEBOX = 0x00020000;
    const int WS_MAXIMIZEBOX = 0x00010000;
    const int WS_CAPTION = 0x00C00000;
    const int WS_THICKFRAME = 0x00040000;
    const int WS_EX_DLGMODALFRAME = 0x00000001;
    const int WS_EX_CLIENTEDGE = 0x00000200;
    const int WS_EX_STATICEDGE = 0x00020000;

    // this replaces MinimizeBox=false and MaximizeBox=false
    void HideMinimizeAndMaximizeButtons()
    {
        // read current style
        int style = GetWindowLong(Handle, GWL_STYLE);
        Debug.WriteLine("0x{0:X}", style);
        // update style - remove flags for MinimizeBox and MaximizeBox
        style = style & ~WS_MINIMIZEBOX & ~WS_MAXIMIZEBOX;
        Debug.WriteLine("0x{0:X}", style);
        SetWindowLong(Handle, GWL_STYLE, style);
    }

    // part of removing the whole border
    void HideTitleBar()
    {
        // read current style
        int style = GetWindowLong(Handle, GWL_STYLE);
        Debug.WriteLine("0x{0:X}", style);
        // update style - remove flag for caption
        style = style & ~WS_CAPTION;
        Debug.WriteLine("0x{0:X}", style);
        SetWindowLong(Handle, GWL_STYLE, style);
    }

    // hide the border
    void HideBorder()
    {
        // read current style
        int style = GetWindowLong(Handle, GWL_STYLE);
        Debug.WriteLine("0x{0:X}", style);
        // update style - remove flag for border (could use WS_SIZEBOX which is the very same flag (see MSDN)
        style = style & ~WS_THICKFRAME;
        Debug.WriteLine("0x{0:X}", style);
        SetWindowLong(Handle, GWL_STYLE, style);

        // read current extended style
        style = GetWindowLong(Handle, GWL_EXSTYLE);
        Debug.WriteLine("0x{0:X}", style);
        // update style by removing some additional border styles -
        // may not be necessary, when current border style is not something exotic,
        // i.e. as long as it "normal"
        style = style & ~WS_EX_DLGMODALFRAME & ~WS_EX_CLIENTEDGE & ~WS_EX_STATICEDGE;
        Debug.WriteLine("0x{0:X}", style);
        SetWindowLong(Handle, GWL_EXSTYLE, style);
    }

    public Form1()
    {
        InitializeComponent();

        // hide those unwanted properties - you can try to leave out one or another to see what it does
        HideMinimizeAndMaximizeButtons();
        HideTitleBar();
        HideBorder();
    }
}

这按预期工作。最大化/设置的WindowState工程,以及减少。

This works as intended. Maximizing/minimizing by setting WindowState works as well.

人们可以在源分析框架做什么和它做什么错误(或不完全正确)。

One could analyze in sources what the framework does and what it does "wrong" (or not quite correct).

编辑:我添加的样式值的调试输出。请尝试的命令在Form1构造序列:

I added debug output of the style values. Please try this sequence of commands in Form1 constructor:

MaximizeBox = false;
FormBorderStyle = FormBorderStyle.Sizable;
HideMinimizeAndMaximizeButtons();
FormBorderStyle = FormBorderStyle.None;
MaximizeBox = true;
MaximizeBox = false;
HideMinimizeAndMaximizeButtons();
FormBorderStyle = FormBorderStyle.None;
HideMinimizeAndMaximizeButtons();

您将看到,该设置FormBorderStyle.None使WS_MAXIMIZEBOX风格。另一这不能纠正MaximizeBox = FALSE 。看来有必要调用API函数。

You'll see, that setting FormBorderStyle.None enables the WS_MAXIMIZEBOX style. This cannot be "corrected" by another MaximizeBox = false. It seems it's necessary to call API functions.

这篇关于停留在全屏应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆