Jump to content

How to hide focus rectangle for any control?


Recommended Posts

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
Link to comment
Share on other sites

So it is just for cosmetic reasons?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

  • Developers

Maybe I can recommend a mental coach to help you deal with a standard Windows feature? ;)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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.

Link to comment
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

 

 

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...