Hide the dotted focus border
Posted: 23 Oct 2015, 01:43
Because of this question I tried tmplinshi's function. But it didn't work as I want, so I changed it. This version seems to work and - according to the MSDN - should work for all Windows versions >= Win 2000. I tested on Win 10 only.
As a result of my test you have to call the function once for each GUI control / GUI after it has been shown.
tmplinshi had already noticed some issues caused by the Alt key. On my system WM_UPDATEUISTATE messages with wParam = 0x00030002 (UIS_INITIALIZE | UISF_HIDEACCEL) are sent/posted to the controls. Although wParam does not contain the UISF_HIDEFOCUS flag, it will be cleared when the message is processed. That's why the message handler for WM_UPDATEUISTATE messages is needed.
As a result of my test you have to call the function once for each GUI control / GUI after it has been shown.
Code: Select all
; ==================================================================================================================================
; Hides the focus border for the given GUI control or GUI and all of its children.
; Call the function passing only the HWND of the control / GUI in wParam as only parameter.
; WM_UPDATEUISTATE -> msdn.microsoft.com/en-us/library/ms646361(v=vs.85).aspx
; The Old New Thing -> blogs.msdn.com/b/oldnewthing/archive/2013/05/16/10419105.aspx
; ==================================================================================================================================
HideFocusBorder(wParam, lParam := "", uMsg := "", hWnd := "") {
; WM_UPDATEUISTATE = 0x0128
Static Affected := [] ; affected controls / GUIs
, HideFocus := 0x00010001 ; UIS_SET << 16 | UISF_HIDEFOCUS
, OnMsg := OnMessage(0x0128, Func("HideFocusBorder"))
If (uMsg = 0x0128) { ; called by OnMessage()
If (wParam = HideFocus)
Affected[hWnd] := True
Else If Affected[hWnd]
PostMessage, 0x0128, %HideFocus%, 0, , ahk_id %hWnd%
}
Else If DllCall("IsWindow", "Ptr", wParam, "UInt")
PostMessage, 0x0128, %HideFocus%, 0, , ahk_id %wParam%
}