Hi, I use AutoHotKey to change dark/light modes for many programs I use, but for some that don't support it I'd like to reverse the colors for the specific window, or alternatively for some screen coordinates. It is not an aesthetically perfect solution, but sufficient for the purpose in the absence of alternatives. Is there a script for this?
Thank you.
Invert window colors Topic is solved
Invert window colors
Last edited by d_romeo on 22 Aug 2021, 16:51, edited 2 times in total.
-
- Posts: 4360
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Reverse window colors
I'm not sure, what do you mean by «reverse», perhaps you mean «invert».
SRCINVERT
SRCINVERT
Re: Invert window colors
Yes, I'm sorry. Invert the colors. With Magnify and ^!i you invert the colors of the whole screen, but I'd like to do it for just a few windows.
-
- Posts: 4360
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Invert window colors
I was wrong, NOTSRCCOPY is more suitable. A simple examle:
Code: Select all
NOTSRCCOPY := 0x330008
X := 100, Y := 100, W := 600, H := 400
hDC := DllCall("GetDC", "Ptr", 0, "Ptr")
hBM := DllCall("CreateCompatibleBitmap", "Ptr", hDC, "Int", W, "Int", H, "Ptr")
hMDC := DllCall("CreateCompatibleDC", "Ptr", hDC, "Ptr")
hObj := DllCall("SelectObject", "Ptr", hMDC, "Ptr", hBM)
DllCall("BitBlt", "Ptr", hMDC, "Int", 0, "Int", 0, "Int", W, "Int", H
, "Ptr", hDC, "Int", X, "Int", Y, "UInt", NOTSRCCOPY)
DllCall("SelectObject", "Ptr", hMDC, "Ptr", hObj)
DllCall("DeleteDC", "Ptr", hMDC)
DllCall("ReleaseDC", "Ptr", 0, "Ptr", hDC)
Gui, New, -Caption +AlwaysOnTop +Owner -DPIScale
Gui, Margin, 0, 0
Gui, Add, Pic,, HBITMAP:%hBM%
Gui, Show, x%X% y%Y% NA
Re: Invert window colors Topic is solved
Example with magnification api and CreateWindowInBand.
Code: Select all
x := 500
y := 500
w := 320
h := 240
Gui, +HWNDhGui +AlwaysOnTop
DllCall("GetWindowBand", "ptr", hGui, "uint*", band)
Gui, Destroy
hGui := ""
if (band = 1)
{
If (A_PtrSize = 8)
RunWait "C:\Program Files\AutoHotkey\AutoHotkeyU64_UIA.exe" "%A_ScriptFullPath%"
Else If A_IsUnicode
RunWait "C:\Program Files\AutoHotkey\AutoHotkeyU32_UIA.exe" "%A_ScriptFullPath%"
Else
RunWait "C:\Program Files\AutoHotkey\AutoHotkeyA32_UIA.exe" "%A_ScriptFullPath%"
}
#SingleInstance Force
SetBatchLines -1
SetWinDelay -1
OnExit, Uninitialize
Gui, +HWNDhGui -DPIScale -Caption +AlwaysOnTop +E0x02000000 +E0x00080000 +E0x20 ; WS_EX_COMPOSITED := E0x02000000 WS_EX_LAYERED := E0x00080000
Gui, Margin, 0,0
Gui, Show, x%x% y%y% w%w% h%h% NA
DllCall("LoadLibrary", "str", "magnification.dll")
DllCall("magnification.dll\MagInitialize")
hChildMagnifier := DllCall("CreateWindowInBand", "UInt", 0, "Str", "Magnifier", "Str", "MagnifierWindow", "UInt", WS_CHILD := 0x40000000, "Int", 0, "Int", 0, "Int", w, "Int", h, "Ptr", hGui, "UInt", 0, "Ptr", DllCall("GetWindowLong" (A_PtrSize=8 ? "Ptr" : ""), "Ptr", hGui, "Int", GWL_HINSTANCE := -6 , "ptr"), "UInt", 0, "uint", ZBID_UIACCESS := 2, "ptr")
Matrix := "-1|0|0|0|0|"
. "0|-1|0|0|0|"
. "0|0|-1|0|0|"
. "0|0|0|1|0|"
. "1|1|1|0|1"
VarSetCapacity(MAGCOLOREFFECT, 100, 0)
Loop, Parse, Matrix, |
NumPut(A_LoopField, MAGCOLOREFFECT, (A_Index - 1) * 4, "Float")
DllCall("magnification.dll\MagSetColorEffect", "Ptr", hChildMagnifier, "Ptr", &MAGCOLOREFFECT)
WinShow, ahk_id %hChildMagnifier%
Loop
{
if (A_PtrSize = 8)
{
VarSetCapacity(RECT, 16, 0)
NumPut(x, RECT, 0, "Int")
NumPut(y, RECT, 4, "Int")
NumPut(w, RECT, 8, "Int")
NumPut(h, RECT, 12, "Int")
DllCall("magnification.dll\MagSetWindowSource", "Ptr", hChildMagnifier, "Ptr", &RECT)
}
else
DllCall("magnification.dll\MagSetWindowSource", "Ptr", hChildMagnifier, "Int", x, "Int", y, "Int", w, "Int", h)
}
Return
Uninitialize:
DllCall("magnification.dll\MagUninitialize")
ExitApp
Last edited by malcev on 25 Sep 2021, 13:04, edited 5 times in total.
Re: Invert window colors
teadrinker your code works fine thanks.
malcev I had problems with your version, I don't have AutoHotkeyU64_UIA.exe installed, I tried replacing with AutoHotkeyU64.exe and the code works, but it draws a completely white rettag. I have the 64bit Unicode version installed.
malcev I had problems with your version, I don't have AutoHotkeyU64_UIA.exe installed, I tried replacing with AutoHotkeyU64.exe and the code works, but it draws a completely white rettag. I have the 64bit Unicode version installed.
Re: Invert window colors
You need AutoHotkeyU64_UIA.exe
https://www.autohotkey.com/docs/Program.htm#Installer_uiAccess
https://www.autohotkey.com/docs/Program.htm#Installer_uiAccess
Re: Invert window colors
Ok, now it works, and I haven't noticed any display lag either, which is very important. There is a problem with the 2 sides as shown in the screenshot, do you have this bug too?
However, I have UAC disabled, so I don't know if that would affect it.
However, I have UAC disabled, so I don't know if that would affect it.
Re: Invert window colors
It is because of dpi scaling.
I have modified code.
I have modified code.
Re: Invert window colors
It works perfectly. I will work on it now to fit the windows, thank you very much.
Re: Invert window colors
I have modified post with code - remove callback to prevent cpu usage.
viewtopic.php?p=416776#p416776
Also have created script that tracks window.
viewtopic.php?f=6&t=94264
viewtopic.php?p=416776#p416776
Also have created script that tracks window.
viewtopic.php?f=6&t=94264
Re: Invert window colors
@malcev:
Very interesting stuff. Thx for sharing it.
@d_romeo:
Here's a full-screen color inverter, maybe you want to use it.
Very interesting stuff. Thx for sharing it.
@d_romeo:
Here's a full-screen color inverter, maybe you want to use it.
Code: Select all
#NoEnv
#SingleInstance Force
SetBatchLines -1
DllCall("LoadLibrary", "Str", "Magnification.dll")
Initialized := False
OnExit, Uninitialize
InvertMatrix := [-1, 0, 0, 0, 0
, 0, -1, 0, 0, 0
, 0, 0, -1, 0, 0
, 0, 0, 0, 1, 0
, 1, 1, 1, 0, 1]
VarSetCapacity(MagEffectInvert, 100, 0)
Addr := &MagEffectInvert
For I, V In InvertMatrix
Addr := NumPut(V, Addr + 0, "Float")
Return
; ----------------------------------------------------------------------------------------------------------------------
Uninitialize:
If (Initialized)
DllCall("Magnification.dll\MagUninitialize")
ExitApp
; ----------------------------------------------------------------------------------------------------------------------
^+I::
If (Initialized)
Initialized := DllCall("Magnification.dll\MagUninitialize", "UInt") & 0
Else If (Initialized := DllCall("Magnification.dll\MagInitialize", "UInt"))
DllCall("Magnification.dll\MagSetFullscreenColorEffect", "Ptr", &MagEffectInvert)
Return
Re: Invert window colors
teadrinker detected that when We run script with UIACCESS, then if We set +AlwaysOnTop on Gui then it automatically runs with ZBID_UIACCESS band.
Also to invert colors in magnifier control We can do without matrix like this:
https://docs.microsoft.com/en-us/previous-versions/windows/desktop/magapi/magapi-magnifier-styles
Code: Select all
If !RegExMatch(DllCall("GetCommandLine", "Str"), " /restart(?!\S)") {
If (A_PtrSize = 8)
RunWait "C:\Program Files\AutoHotkey\AutoHotkeyU64_UIA.exe" /restart "%A_ScriptFullPath%"
Else If A_IsUnicode
RunWait "C:\Program Files\AutoHotkey\AutoHotkeyU32_UIA.exe" /restart "%A_ScriptFullPath%"
Else
RunWait "C:\Program Files\AutoHotkey\AutoHotkeyA32_UIA.exe" /restart "%A_ScriptFullPath%"
}
Gui, +HWNDhGui
Gui, Add, Text,, Please enter your name:
Gui, Add, Edit, vName hwndhEdit
Gui, Show, x0 y0
DllCall("GetWindowBand", "ptr", hGui, "uint*", band)
msgbox % band
Gui, +AlwaysOnTop
DllCall("GetWindowBand", "ptr", hGui, "uint*", band)
msgbox % band
Code: Select all
x := 500
y := 500
w := 320
h := 240
Gui, +HWNDhGui +AlwaysOnTop
DllCall("GetWindowBand", "ptr", hGui, "uint*", band)
Gui, Destroy
hGui := ""
if (band = 1)
{
If (A_PtrSize = 8)
RunWait "C:\Program Files\AutoHotkey\AutoHotkeyU64_UIA.exe" "%A_ScriptFullPath%"
Else If A_IsUnicode
RunWait "C:\Program Files\AutoHotkey\AutoHotkeyU32_UIA.exe" "%A_ScriptFullPath%"
Else
RunWait "C:\Program Files\AutoHotkey\AutoHotkeyA32_UIA.exe" "%A_ScriptFullPath%"
}
#SingleInstance Force
SetBatchLines -1
SetWinDelay -1
OnExit, Uninitialize
Gui, +HWNDhGui -DPIScale -Caption +AlwaysOnTop +E0x02000000 +E0x00080000 +E0x20 ; WS_EX_COMPOSITED := E0x02000000 WS_EX_LAYERED := E0x00080000
Gui, Show, x%x% y%y% w%w% h%h% NA
DllCall("LoadLibrary", "str", "magnification.dll")
DllCall("magnification.dll\MagInitialize")
hChildMagnifier := DllCall("CreateWindowEx", "UInt", 0, "Str", "Magnifier", "Str", "MagnifierWindow", "UInt", (WS_CHILD := 0x40000000)|(MS_INVERTCOLORS := 0x0004), "Int", 0, "Int", 0, "Int", w, "Int", h, "Ptr", hGui, "UInt", 0, "Ptr", DllCall("GetWindowLong" (A_PtrSize=8 ? "Ptr" : ""), "Ptr", hGui, "Int", GWL_HINSTANCE := -6 , "ptr"), "UInt", 0, "ptr")
WinShow, ahk_id %hChildMagnifier%
Loop
{
if (A_PtrSize = 8)
{
VarSetCapacity(RECT, 16, 0)
NumPut(x, RECT, 0, "Int")
NumPut(y, RECT, 4, "Int")
NumPut(w, RECT, 8, "Int")
NumPut(h, RECT, 12, "Int")
DllCall("magnification.dll\MagSetWindowSource", "Ptr", hChildMagnifier, "Ptr", &RECT)
}
else
DllCall("magnification.dll\MagSetWindowSource", "Ptr", hChildMagnifier, "Int", x, "Int", y, "Int", w, "Int", h)
}
Return
Uninitialize:
DllCall("magnification.dll\MagUninitialize")
ExitApp
Last edited by malcev on 25 Sep 2021, 13:05, edited 2 times in total.
Re: Invert window colors
@malcev:
Shouldn't it befor AHK 1.1?
Shouldn't it be
Code: Select all
If !RegExMatch(DllCall("GetCommandLine", "Str"), " /restart(?!\S)") {
If (A_PtrSize = 8)
RunWait "C:\Program Files\AutoHotkey\AutoHotkeyU64_UIA.exe" /restart "%A_ScriptFullPath%"
Else If A_IsUnicode
RunWait "C:\Program Files\AutoHotkey\AutoHotkeyU32_UIA.exe" /restart "%A_ScriptFullPath%"
Else
RunWait "C:\Program Files\AutoHotkey\AutoHotkeyA32_UIA.exe" /restart "%A_ScriptFullPath%"
}
Re: Invert window colors
I chose this algorithm because of speed, but Your algorithm I think is more correct.
I have corrected codes.
I have corrected codes.
Re: Invert window colors
Hi malcev, lately I can't get the script to invert the colors of a single window to work anymore, which I use quite often. Now I just get a black window, everything else works fine, like size, window tracking etc. but the colors are not reversed. Could the latest updates in Windows 11 have changed something? I currently use version 22000.527.
Re: Invert window colors
I do not have win11, but if You run script with ahk32 bit, then try to run it with ahk64 bit.
Re: Invert window colors
I fixed the problem, apparently AutoHotKey doesn't like Nvidia graphics cards. In case anyone has the same issue as me: I have configured Nvidia AutoHotkeyU64_UIA.exe in the control panel to use the integrated graphics card by default, in this way everything works correctly.
-
- Posts: 1
- Joined: 25 Feb 2022, 07:02
Re: Invert window colors
I'm a complete newbie. i want to invert colors of the specific window of one note whenever it opens. can someone help?
Re: Invert window colors
You mean you want to automatically invert a window, so it's always in dark mode?
I've included in my scripts a code that automatically inverts a window when it opens during night hours, even when closing and reopening, but it's a bit complicated. If that's what you're asking, I can help you.
I've included in my scripts a code that automatically inverts a window when it opens during night hours, even when closing and reopening, but it's a bit complicated. If that's what you're asking, I can help you.
Who is online
Users browsing this forum: Bing [Bot], Descolada, DracoCapt, norot41087, science2002 and 77 guests