Page 1 of 1

Force TaskBar AutoHide

Posted: 05 Nov 2018, 06:42
by stealzy
Sometimes windows taskbar auto-hide option stop working, this is a known bug:
Image
Image
The reason of bug connected with tray (notification area), manually click on tray arrow usually could help to hide taskbar for once.

Script below reimplements auto-hide functionality, works with taskbar in any position (bottom, left, top, right):

Code: Select all

; _______Settings________
hideDelay := 300 ; ms
;========================
; #NoTrayIcon
#SingleInstance force
#Persistent
SetBatchLines -1
SetMouseDelay -1
SetWinDelay -1
CoordMode Mouse, Screen
OnExit Exit

global taskBarVis, xTaskBar, yTaskBar, wTaskBar, hTaskBar, taskBarOnTop, hideDelay
WinGetPos xTaskBar, yTaskBar, wTaskBar, hTaskBar, ahk_class Shell_TrayWnd ahk_exe explorer.exe
taskBarOnTop := yTaskBar < 0

DetectHiddenWindows On
hwndTaskBar := WinExist("ahk_class Shell_TrayWnd ahk_exe explorer.exe")
taskBarVis := DllCall("IsWindowVisible", Ptr, hwndTaskBar) ; originally invisible only on top
; MsgBox % xTaskBar " | " yTaskBar " | " wTaskBar " | " hTaskBar " | " taskBarVis := DllCall("IsWindowVisible", Ptr, hwndTaskBar)

; maybe hook is not cool for perfomance (possible freeze) and simple timer would be better
hHookMouse := DllCall("SetWindowsHookEx" . (A_IsUnicode ? "W" : "A")
   , Int, WH_MOUSE_LL := 14
   , Ptr, RegisterCallback("LowLevelMouseProc", "Fast")
   , Ptr, DllCall("GetModuleHandle", UInt, 0, Ptr)
   , UInt, 0, Ptr)
Return

; F1::showTaskBar()
; F2::hideTaskBar()
; Esc::ExitApp

Exit:
	DllCall("UnhookWindowsHookEx", Ptr, hHookMouse)
	showTaskBar()
	ExitApp

LowLevelMouseProc(nCode, wParam, lParam) {
	static WM_MOUSEMOVE := 0x200 ;, i := 0, j := 0

	if (nCode < 0 || wParam != WM_MOUSEMOVE)   ; 
	  Return DllCall("CallNextHookEx", Ptr, 0, Int, nCode, UInt, wParam, UInt, lParam)

	x := NumGet(lParam+0, "Int"), y := NumGet(lParam+0, 4, "Int")

		; ToolTip % x ":" y "`n" yTaskBar " " yTaskBar+hTaskBar,,, 1
	If ((!taskBarVis or taskBarOnTop) and (x >= xTaskBar and x <= xTaskBar+wTaskBar && y >= yTaskBar-1 and y <= yTaskBar+hTaskBar)) {
		taskBarVis := 1
		; ToolTip % ++i, 100, 100, 2
		SetTimer showTaskBar, -1
	}
	Else if (taskBarVis and !(x > xTaskBar-wTaskBar and x < xTaskBar+2*wTaskBar && y > yTaskBar-hTaskBar and y < yTaskBar+ 2*hTaskBar)) {
		taskBarVis := 0
		; ToolTip % ++j, 200, 100, 3
		SetTimer hideTaskBar, % -hideDelay
	}
	Return
}


hideTaskBar() {
	; static hMenuStart := WinExist("ahk_class DV2ControlHost")
	MouseGetPos x, y ;, hWin, ControlClNN, 1
	If !(x > xTaskBar-30 and x < xTaskBar+wTaskBar+30 && y > yTaskBar-30 and y < yTaskBar+hTaskBar+30) {
		WinHide ahk_class Shell_TrayWnd ahk_exe explorer.exe
		WinHide Start ahk_class Button ahk_exe explorer.exe
	} else {
		taskBarVis := 1
	}
}
showTaskBar() {
	WinShow ahk_class Shell_TrayWnd ahk_exe explorer.exe
	; WinActivate ahk_class Shell_TrayWnd ahk_exe explorer.exe ; Show without activation for fullscreen apps
	WinShow Start ahk_class Button ahk_exe explorer.exe
}
Scheme:
Image

Next feature I try to implement is not show taskbar immediately when cursor reache the desktop edge, only if cursor move some pixels along the edge. It must to prevent accidental taskbar appearence.
Next code is prototype, work only for bottom taskbar position:
Spoiler
Another possible feature is show taskbar even for fullscreen programs. In combination with prevent accidental taskbar appearence it must work well, but I'm too lazy.

Re: Force TaskBar AutoHide

Posted: 07 Nov 2018, 11:04
by Drugwash
Funny thing is a couple days ago this happened to me for the first time on this machine. Some memory corruption/overlap/whatever caused a running application to simply dissapear and afterwards the taskbar wouldn't autohide anymore. Manually toggling Autohide and AlwaysOnTop didn't cut it so I just killed explorer.exe and restarted it. I used Codestuff Starter in XP but it probably won't work in Win8/10, definitely not in x64 systems; Task Manager should suffice though.
Maybe you could do something like that (kill explorer / run explorer), might fix it instead of a workaround. ;)