kosamja

How to hide focus rectangle for any control?

11 posts in this topic

#1 ·  Posted (edited)

Is it possible to hide focus rectangle for any control in any window? I tried this, but focus rectangle appears on mouse hover or click:

; www.autoitscript.com/forum/topic/56536-easy-shell-hooking-example/?page=2
; autohotkey.com/board/topic/82458-how-to-disable-the-standard-focus-rectangle/

#NoTrayIcon
#include<WinAPI.au3>
#include<WinAPISys.au3>
#include<WindowsConstants.au3>

Opt("WinWaitDelay", 0)
Opt("MouseClickDelay", 0)
Opt("MouseClickDownDelay", 0)
Opt("MouseClickDragDelay", 0)
Opt("SendKeyDelay", 0)
Opt("SendKeyDownDelay", 0)
Opt("WinTitleMatchMode", 3)

Global Const $UISF_HIDEFOCUS = 0x10001
$hHookFunc = DllCallbackRegister('_WinEventProc', 'none', 'ptr;uint;hwnd;int;int;uint;uint')
$hWinHook = _WinAPI_SetWinEventHook($EVENT_OBJECT_FOCUS, $EVENT_OBJECT_FOCUS, DllCallbackGetPtr($hHookFunc))

While 1
   _HighPrecisionSleep(0.1)
WEnd

Func _WinEventProc($hHook, $iEvent, $hWnd, $iObjectID, $iChildID, $iEventThread, $imsEventTime)
   If $iEvent = $EVENT_OBJECT_FOCUS Then
      _SendMessage($hWnd, $WM_CHANGEUISTATE, $UISF_HIDEFOCUS)
      _SendMessage($hWnd, $WM_UPDATEUISTATE, $UISF_HIDEFOCUS)
   EndIf
EndFunc

Func _HighPrecisionSleep($iMicroSeconds,$hDll=False)
   Local $hStruct, $bLoaded
   If Not $hDll Then
      $hDll=DllOpen("ntdll.dll")
      $bLoaded=True
   EndIf
   $hStruct=DllStructCreate("int64 time;")
   DllStructSetData($hStruct,"time",-1*($iMicroSeconds*10))
   DllCall($hDll,"dword","ZwDelayExecution","int",0,"ptr",DllStructGetPtr($hStruct))
   If $bLoaded Then DllClose($hDll)
EndFunc

 

Edited by kosamja

Share this post


Link to post
Share on other sites



bump... Just to check is this not possible without dll?

Share this post


Link to post
Share on other sites

Is this what you are looking for? -> 

 


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

yes, but for every window.  NoFocusLines works only for autoit gui.

Edited by kosamja

Share this post


Link to post
Share on other sites

Ok, what is the purpose to do so for external windows?


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

to remove that ugly dotted focus rectangle...

Share this post


Link to post
Share on other sites

So it is just for cosmetic reasons?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Yes, and because its annoying since it appears on every control that is clicked or has focus.

Edited by kosamja

Share this post


Link to post
Share on other sites

standard Windows feature I havent seen for years thanks to RemoveFocusRect.dll. Unfortunately that dll doesnt work if secure boot on UEFI is enabled since in that case AppInit_DLLs is disabled. I guess I can just disable secure boot, but I thought I can instead use autoit for removal of focus rectangle, but it looks I cant.

Share this post


Link to post
Share on other sites

Hello. First UISF_HIDEFOCUS constant has not that value :S It's defined as UISF_HIDEFOCUS=0x1

_HighPrecisionSleep Function is pretty wrong.

Check

; www.autoitscript.com/forum/topic/56536-easy-shell-hooking-example/?page=2
; autohotkey.com/board/topic/82458-how-to-disable-the-standard-focus-rectangle/

;~ #NoTrayIcon
#include <WinAPI.au3>
#include <WinAPISys.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Opt("WinWaitDelay", 0)
Opt("MouseClickDelay", 0)
Opt("MouseClickDownDelay", 0)
Opt("MouseClickDragDelay", 0)
Opt("SendKeyDelay", 0)
Opt("SendKeyDownDelay", 0)
Opt("WinTitleMatchMode", 3)

Global $hNTDll = DllOpen("ntdll.dll") ;just load once :P

Global Const $UIS_SET = 1
Global Const $UIS_CLEAR = 2
Global Const $UISF_HIDEFOCUS = 0x1

OnAutoItExitRegister("_Free")


Global $hHookFunc = DllCallbackRegister('_WinEventProc', 'none', 'ptr;uint;hwnd;int;int;uint;uint')
Global $hWinHook = _WinAPI_SetWinEventHook($EVENT_OBJECT_CREATE, $EVENT_OBJECT_CREATE, DllCallbackGetPtr($hHookFunc))


While 1
    _HighPrecisionSleep(0.1)
WEnd

Func _Free()
    If $hWinHook Then _WinAPI_UnhookWinEvent($hWinHook)
    If $hHookFunc Then DllCallbackFree($hHookFunc)
    If $hNTDll Then DllClose($hNTDll)
EndFunc   ;==>_Free


Func _WinEventProc($hHook, $iEvent, $hWnd, $iObjectID, $iChildID, $iEventThread, $imsEventTime)
    _SendMessage($hWnd, $WM_CHANGEUISTATE, _WinAPI_MakeLong($UIS_CLEAR, $UISF_HIDEFOCUS))
    _SendMessage($hWnd, $WM_UPDATEUISTATE, _WinAPI_MakeLong($UIS_SET, $UISF_HIDEFOCUS))
EndFunc   ;==>_WinEventProc



Func _HighPrecisionSleep($iMicroSeconds)
    Local $hStruct = DllStructCreate("int64 time;")
    DllStructSetData($hStruct, "time", -1 * ($iMicroSeconds * 10))
    DllCall($hNTDll, "dword", "NtDelayExecution", "int", 0, "ptr", DllStructGetPtr($hStruct))
EndFunc   ;==>_HighPrecisionSleep

 

 

Saludos

 

 

 

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now