如何隐藏任务栏时,autohiddetaskbar选项和脚本(ahk脚本)试图隐藏任务栏太
本文关键字:任务栏 脚本 隐藏 ahk 何隐藏 autohiddetaskbar 选项 | 更新日期: 2023-09-27 18:14:13
我的应用程序被设计为全屏启动,无论如何任务栏都不应该对用户可见。对于隐藏在ahk下面的任务栏,脚本将在后台运行以执行所需的操作。
关于AHK脚本,请选择下面的链接进行说明。
http://ahkscript.org/如果选择了windows 7的"自动隐藏任务栏"功能,脚本将不起作用。
因此,我采用了下面的c#代码来从应用程序端解决问题。
但是在某些情况下,比如当应用程序在窗口重启后第一次启动时,显示窗口功能不能正常工作,特别是当选择自动隐藏任务栏选项时。
样例代码 [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);
}
上面的代码改变了功能。
请建议处理这种情况的方法。
这是一个自动热键检查操作系统版本和更改隐藏任务栏设置的解决方案:
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
人们仍然可以通过按键盘上的Windows键或其他快捷键来访问任务栏。你所做的就是侵入计算机的注册表项,扰乱用户自定义的快捷方式。
你真正想做的是创建一个全屏最大化的窗口(类似于你在最大化youtube视频时看到的)。
设置窗口的属性如下:1. FormBorderStyle = None;2. 在表单加载时,获取屏幕矩形并将窗口大小调整为该大小