DIMMER BOX

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

DIMMER BOX

14 Jul 2020, 18:33

I know there are lots of screen dimmers and probably much better than this one but I found the idea of targeting only certain windows quite interesting. (Especially Notepad :mrgreen: 8-) )

usage:
Press Alt + F1 to dim selected windows
Press Alt + F2 to destroy all overlay boxes

Code: Select all

; =================================================================================================================================
; Name:           Dimmer box
; Description:    Dim selected windows with an overlay box
; credits:        Speedmaster, Skwire
; Topic:          https://www.autohotkey.com/boards/viewtopic.php?f=6&t=78587
; Sript version:  1.0
; AHK Version:    1.1.24.03 (A32/U32/U64)
; Tested on:      Win 7 
; shortcuts::     !F1 update all boxes or add a new one
;                 !F2 destroy all boxes

#SingleInstance force

!F1::

winid:=""
    WinGetPos, X, Y, W, H, A
WinGet, winid,, A

if instr(idlist, winid) {
    for k, v in strsplit(idlist, "_") {
        if (v) {
          WinGetPos, X, Y, W, H, % "ahk_id " . v
           if w
          Gui, dim_%k% : Show, % "x" . x . "y" . y . "w" . w . "h" . h, Overlay
          else
          Gui, dim_%k% : Destroy
       }
    }
return
}

if instr(excludelist, winid)
return


if !winid
return

dimcount++

if winid
   idlist .= winid "_"

; thx Skwire
Gui, dim_%dimcount% : +Toolwindow -Caption +Lastfound +AlwaysOnTop
Gui, dim_%dimcount% : Color, black ; Change overlay colour here.
Gui, dim_%dimcount% : Show, % "x" . x . "y" . y . "w" . w . "h" . h, Overlay
GUI_ID := WinExist()

excludelist .= gui_id

WinSet, Transparent, 100       , % "ahk_id " . GUI_ID ; Change the numerical value for opaqueness amount.
WinSet, ExStyle    , +0x00000020, % "ahk_id " . GUI_ID ; Leave this value alone
Return

!f2::
loop, % dimcount 
Gui, dim_%a_index% : Destroy

idlist:=excludelist:=dimcount:=winid:=""

return

esc::exitapp

Attachments
dimmer_box.png
dimmer_box.png (45.4 KiB) Viewed 3607 times
lblb
Posts: 190
Joined: 30 Sep 2013, 11:31

Re: DIMMER BOX

14 Jul 2020, 19:02

Nice script! Couple of suggestions that I think would make it more useful:
- anchor the overlay to the dimmed window so that they move and resize together
- destroy the overlay if the dimmed window is closed
User avatar
SpeedMaster
Posts: 494
Joined: 12 Nov 2016, 16:09

Re: DIMMER BOX

15 Jul 2020, 01:36

lblb wrote:
14 Jul 2020, 19:02
- anchor the overlay to the dimmed window so that they move and resize together
- destroy the overlay if the dimmed window is closed
if you press Alt + F1 again after resizing or closing a window the script will do that. :thumbup:
Doing this automatically would be better but I have no idea how to do it properly. :think:

Regards
lblb
Posts: 190
Joined: 30 Sep 2013, 11:31

Re: DIMMER BOX

17 Jul 2020, 04:46

Thanks for the quick reply!
keanhong2
Posts: 1
Joined: 03 Apr 2020, 18:07

Re: DIMMER BOX

19 Jul 2020, 22:01

thanks for sharing ,
dostroll
Posts: 40
Joined: 03 Nov 2021, 08:56

Re: DIMMER BOX

25 Apr 2022, 09:44

I was able to implement a checking mechanism for the active window using DllCall.
I found a very useful function. I hope it will become an official feature of AHK.

My usage is for software that doesn't support dark mode.

Code: Select all

myFunc := RegisterCallback("WinActivateHandler")
myHook := DllCall("SetWinEventHook"
, "UInt", 0x00000003 ; eventMin      : EVENT_SYSTEM_FOREGROUND
, "UInt", 0x00000003 ; eventMax      : EVENT_SYSTEM_FOREGROUND
, "UInt", 0          ; hModule       : self
, "UInt", myFunc     ; hWinEventProc :
, "UInt", 0          ; idProcess     : All process
, "UInt", 0          ; idThread      : All threads
, "UInt", 0x0003     ; dwFlags       : WINEVENT_SKIPOWNTHREAD | WINEVENT_SKIPOWNPROCESS
, "UInt")

WinActivateHandler(hWinEventHook, event, hwnd, idObject, idChild, thread, time) {
	WinGetTitle, title, ahk_id %hwnd%
	WinGetClass, class, ahk_id %hwnd%

	StringGetPos pos, title, notepad
	If (pos >= 0)
  {
    GoSub, Dimmer_box_Off
  } else {
    GoSub, Dimmer_box_On
  }
}

; =================================================================================================================================
; Name:           Dimmer box
; Description:    Dim selected windows with an overlay box
; credits:        Speedmaster, Skwire
; Topic:          https://www.autohotkey.com/boards/viewtopic.php?f=6&t=78587
; Sript version:  1.0
; AHK Version:    1.1.24.03 (A32/U32/U64)
; Tested on:      Win 7 
; shortcuts::     !F1 update all boxes or add a new one
;                 !F2 destroy all boxes

#SingleInstance force

!F1::
Dimmer_box_On:
winid:=""
    WinGetPos, X, Y, W, H, A
WinGet, winid,, A

if instr(idlist, winid) {
    for k, v in strsplit(idlist, "_") {
        if (v) {
          WinGetPos, X, Y, W, H, % "ahk_id " . v
           if w
          Gui, dim_%k% : Show, % "x" . x . "y" . y . "w" . w . "h" . h, Overlay
          else
          Gui, dim_%k% : Destroy
       }
    }
return
}

if instr(excludelist, winid)
return


if !winid
return

dimcount++

if winid
   idlist .= winid "_"

; thx Skwire
Gui, dim_%dimcount% : +Toolwindow -Caption +Lastfound +AlwaysOnTop
Gui, dim_%dimcount% : Color, black ; Change overlay colour here.
Gui, dim_%dimcount% : Show, % "x" . x . "y" . y . "w" . w . "h" . h, Overlay
GUI_ID := WinExist()

excludelist .= gui_id

WinSet, Transparent, 100       , % "ahk_id " . GUI_ID ; Change the numerical value for opaqueness amount.
WinSet, ExStyle    , +0x00000020, % "ahk_id " . GUI_ID ; Leave this value alone
Return

!f2::
Dimmer_box_Off
loop, % dimcount 
Gui, dim_%a_index% : Destroy

idlist:=excludelist:=dimcount:=winid:=""

return

esc::exitapp


Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 101 guests