【问题标题】:How to hide a taskbar when AutoHideTaskbar option selected and a script (ahk script) trying to hide taskbar too?如何在选择 AutoHideTaskbar 选项以及尝试隐藏任务栏的脚本(ahk 脚本)时隐藏任务栏?
【发布时间】:2015-12-21 16:31:50
【问题描述】:

我的应用程序设计为全屏启动,无论如何用户都不应该看到任务栏。对于隐藏在 ahk 下方的任务栏,脚本将在后台运行以执行所需的操作。

关于 AHK 脚本,请选择以下链接进行描述。

http://ahkscript.org/

如果选择了 Windows 7 的“自动隐藏任务栏”功能,该脚本将不起作用。

因此,我采用以下 C# 代码从应用程序端解决问题。

但在某些情况下,例如在 Windows 重新启动后首次启动应用程序时,showwindow 功能无法正常工作,尤其是在选择自动隐藏任务栏选项时。

示例代码

    [DllImport("user32.dll")]
    public static extern int FindWindowEx(int parentHandle, int childAfter, string className, int windowTitle);

    [DllImport("user32.dll")]
    private static extern int GetDesktopWindow();

    [DllImport("user32.dll")]
    private static extern int ShowWindow(int hwnd, int command);

    protected static int Handle
    {
        get
        {
            return (int)FindWindow("Shell_TrayWnd", "");
        }
    }

    protected static int HandleOfStartButton
    {
        get
        {
            int handleOfDesktop = GetDesktopWindow();
            int handleOfStartButton = FindWindowEx(handleOfDesktop, 0, "button", 0);
            return handleOfStartButton;
        }
    }
    public static void HideTaskbar()
    {
        int Taskbar = ShowWindow(Handle, SW_HIDE);
        int StartButton = ShowWindow(HandleOfStartButton, SW_HIDE);

    }

    private void button1_Click(object sender, EventArgs e)
    {
        HideTaskbar();
    }

脚本 下面的脚本隐藏任务栏并禁用某些键的执行。(右窗口和左窗口按钮和ctrl+esc)

WinHide,ahk_class Shell_TrayWnd
LWin::Suspend
RWin::Suspend
^Esc::Suspend

我尝试过的其他选项

[DllImport("user32.dll")]
    public static extern bool SetWindowPos(
    int hWnd,                 //   handle to window    
    int hWndInsertAfter,  //   placement-order handle    
    short X,                  //   horizontal position    
    short Y,                  //   vertical position    
    short cx,                 //   width    
    short cy,                //    height    
    uint uFlags             //    window-positioning options    
    );

    private void button1_Click(object sender, EventArgs e)
    {

        int hwnd = FindWindow("Shell_TrayWnd", "");
        SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_HIDEWINDOW);
    }

上面的代码改变了功能。无法正常工作。

请提出任何处理这种情况的方法。

【问题讨论】:

  • 您应该为您的 C# 和 .ahk 代码提供完整的代码示例,否则不清楚您的两个代码之间交互的确切性质。也就是说,在我看来,您根本不应该尝试影响任务托盘。这种在您自己的进程之外摆弄用户界面的行为通常会让用户感到厌烦,并且在某些情况下实际上会严重干扰用户对计算机的合法使用。
  • 至少,您应该详细解释为什么您认为这种行为在您的场景中是合适的,以防有人可以提供更合适的替代方案来实现相同的目标。跨度>
  • @PeterDuniho 我已经修改了问题和 ahk 脚本。

标签: c# windows winforms autohotkey


【解决方案1】:

这是一个检查操作系统版本和更改隐藏任务栏设置的 AutoHotkey 解决方案:

If (A_OSVersion = WIN_7) {
    ; retrieve Registry Value of AutoHide Taskbar
    RegRead, OutputVar, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects2, Settings 

    ; If AutoHide Taskbar is On
    If (SubStr(OutputVar, 18, 1) == 3) {
        ChangeSetting := RegExReplace(OutputVar, (03), "02",, 1, 16) 
        ;ChangeSetting := StrReplace(OutputVar, "3", "2",,1)
        RegWrite, REG_BINARY, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects2, Settings, % ChangeSetting
        ; The Code below Automatically applies Registry settings (and on Win 8.1 Explorer.exe is also restarted immediatley
        ; Alternatively you could use Shutdown Command to Reboot the system but this is much faster...
        Process, Close, explorer.exe 

    }   
}

如果你只是想测试一下,这里有一些代码:

Gui, Add, Button, x1 y1 w110 h30 gButton1, Change AutoHide
Gui, Show,, New GUI Window
Return

Button1:
    RegRead, OutputVar, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects2, Settings 
    ChangeSetting := ((SubStr(OutputVar, 18, 1) == 3) 
                   ? RegExReplace(OutputVar, (03), "02",, 1, 16)
                   : RegExReplace(OutputVar, (02), "03",, 1, 16))
    RegWrite, REG_BINARY, HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\StuckRects2, Settings, % ChangeSetting
    Process, Close, explorer.exe 
Return

GuiClose:
ExitApp

【讨论】:

  • 那么您找到解决方案了吗?这有用吗?
  • 非常感谢。您的解决方案很有帮助。我们有一些限制根本不使用注册表,因为应用程序将以各种模式(管理员、用户等)启动。我正在寻找其他一些解决方案和选项。任何帮助都会很棒。
【解决方案2】:

人们仍然可以通过按键盘上的 Windows 键或其他快捷键来访问任务栏。您所做的只是破解计算机的注册表项来破坏用户自定义的快捷方式。

您真正想要做的是创建一个全屏最大化窗口(类似于您在最大化 youtube 视频时看到的)。

设置窗口的属性,以便: 1.FormBorderStyle = 无, 2. 在表单加载时,获取屏幕矩形并将您的窗口调整为该大小。

【讨论】:

    猜你喜欢
    • 2011-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多