Hide the dotted focus border

Put simple Tips and Tricks that are not entire Tutorials in this forum
just me
Posts: 5637
Joined: 02 Oct 2013, 08:51
Location: Germany

Hide the dotted focus border

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.

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%
}
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.
User avatar
joedf
Posts: 6679
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: Hide the dotted focus border

23 Oct 2015, 17:14

hmm... cool :+1:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500 @ 3.00 GHz, 16GB DDR4 3200 MHz, NVIDIA GTX 1060 6GB | [About Me] | [ASPDM - StdLib Distribution]
[Populate the AHK MiniCity!] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library] | [About the AHK Foundation]
Coco-guest

Re: Hide the dotted focus border

23 Oct 2015, 22:10

AutoIt solution I once found way back. It is somehow more complicated(involves subclassing, etc.) compared to your method.
User avatar
Exaskryz
Posts: 2876
Joined: 17 Oct 2015, 20:28

Re: Hide the dotted focus border

09 Dec 2015, 14:19

Just wanted to say that it works on 8.1 and I appreciate you sharing this code. Worked great to hide the border on a Slider control.

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 4 guests