How to hide a taskbar when AutoHideTaskbar option selected and a script (ahk script) trying to hide taskbar too?

早过忘川 提交于 2019-12-12 05:43:07

问题


My application is designed to launch in full screen, at any cost taskbar should not be visible to the user. For taskbar hiding below ahk scripts will be running in the background to perform the needed operations.

Regarding AHK scripting please select the below link for its description.

http://ahkscript.org/

The script doesn`t work if "Auto Hide taskbar" functionality of windows 7 is selected.

Hence I have taken the below C# code to solve the issue from the application side.

But in certain conditions like when the application launches for the first time after windows restart, showwindow function is not working properly especially when Auto Hide taskbar option selected.

Sample Code

    [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();
    }

Script Below script hides the taskbar and disables the execution of some keys.(right window and left window button and ctrl+esc)

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

other options I have tried out

[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);
    }

Above code alters the functionality. Not working properly.

Please suggest any ways to handle this scenario.


回答1:


Here's an AutoHotkey solution to check OS Version and change the Hide Taskbar Setting:

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 

    }   
}

Here's some code if you just want to test it out:

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:


People will still be able to access the taskbar by pressing the Windows key on the keyboard or some other shortcut. All you're doing is hacking the computer's registry keys to mess with the user's customized shortcuts.

What you really want to do is create a fullscreen maximized window (similar to what you see when you maximize a youtube video).

Set the properties of your window such that: 1. FormBorderStyle = None, 2. On form load, get screen rects and resize your window to be of that size.



来源:https://stackoverflow.com/questions/32755118/how-to-hide-a-taskbar-when-autohidetaskbar-option-selected-and-a-script-ahk-scr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!