Monitoring a part of the screen

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: Monitoring a part of the screen

Post by boiler » 16 Sep 2021, 09:02

I recommend that if you haven't read the Structure of a Script section of the documentation, read it and make simple scripts with auto-execute sections and hotkeys until you understand how it works. If you have read it, then review it and practice it with simple test scripts. Also review the #Include page of the documentation and understand exactly what it does.

Fulminare
Posts: 369
Joined: 26 Jun 2021, 20:15

Re: Monitoring a part of the screen

Post by Fulminare » 16 Sep 2021, 09:22

Thank you boiler :)

It may take me some time to understand all that.

I will post any updates here

antonio57
Posts: 4
Joined: 27 Apr 2022, 01:50

Re: Monitoring a part of the screen

Post by antonio57 » 03 Mar 2023, 16:56

Thanks for the example, I was just looking for this for my script.

But unfortunately your code does not work for me - it shows an error on this line

Code: Select all

throw "DwmRegisterThumbnail failed"
I don't know what to do to make it work on my windows 7.

The original idea was to take a video from the Sega Zero Tolerance game from emulator window and, after replanning the location of the visible area and the map, bring them to a new window - make the visible part on the whole window, and display the map semi-transparently in the upper right corner. )))

So still don't know how to do it.

teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Monitoring a part of the screen

Post by teadrinker » 03 Mar 2023, 18:12

On Windows 7 this script will only work if the Aero theme is enabled.

antonio57
Posts: 4
Joined: 27 Apr 2022, 01:50

Re: Monitoring a part of the screen

Post by antonio57 » 04 Mar 2023, 03:31

Understandable, thanks. Can you suggest something as simple as this?

teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Monitoring a part of the screen

Post by teadrinker » 04 Mar 2023, 06:04

For Windows 7 no idea.


antonio57
Posts: 4
Joined: 27 Apr 2022, 01:50

Re: Monitoring a part of the screen

Post by antonio57 » 04 Mar 2023, 06:27

malcev wrote:
04 Mar 2023, 06:14
On forum You can find some examples.
Hm, browse code samples - there is no match with with maginigication, magnifier, magapi...
How do you suggest I look for these examples?

malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Monitoring a part of the screen

Post by malcev » 04 Mar 2023, 09:42

You need to search for MagSetWindowTransform or MagSetColorEffect.
Some info can get here:
viewtopic.php?f=76&t=94011

teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Monitoring a part of the screen

Post by teadrinker » 04 Mar 2023, 10:17

@malcev
According to my tests it doesn't work on Windows 7 either without enabling Aero theme.
Tested like this:

Code: Select all

x := 500
y := 500
w := 320
h := 240

Gui, +HWNDhGui +AlwaysOnTop
Gui, Destroy
hGui := ""
#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("CreateWindowEx", "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, "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

malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Monitoring a part of the screen

Post by malcev » 04 Mar 2023, 10:52

I dont have win7 now.
But it should work, cause there are no info that You should have aero enabled.
You can try to run and convert this autoit examples:
https://www.autoitscript.com/forum/topic/161193-magnifier-functions-windows-vista-magnifier-manipulation/
; Setting DWM off has these effects:
; - Full-screen Magnifier Color Effects AND Magnification do NOT work
; - Magnifier Control will not 'ignore' windows with _MagnifierSetWindowFilter()
; - Magnified images tend to look blurry - possibly software-mode magnification?

; Force DWM off so Full-screen Effect tests don't run
;_WinAPI_DwmEnableComposition(False)

teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Monitoring a part of the screen

Post by teadrinker » 04 Mar 2023, 11:29

malcev wrote: You can try to run and convert this autoit examples
I don't need it. At least as it is, the script doesn't work even if I comment out MagSetColorEffect.

malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Monitoring a part of the screen

Post by malcev » 04 Mar 2023, 13:06

I dont need it too.
I even think that support Win-7 is bad practice.
I thought that You are interested why code does not work on win7 with dwm off and therefore asked it.
I read autoit code and see that to work on win7 with dwm off before MagSetColorEffect We need to call MagSetWindowTransform.

teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Monitoring a part of the screen

Post by teadrinker » 04 Mar 2023, 14:14

Yep, this made it working:

Code: Select all

#SingleInstance Force
SetBatchLines -1
SetWinDelay -1

x := 400
y := 200
w := 400
h := 280
scaleFactor := 1

DllCall("LoadLibrary", "str", "magnification.dll")
DllCall("magnification\MagInitialize")
OnExit("Uninitialize")

Gui, % "+hwndhGui -DPIScale +AlwaysOnTop +E" . (WS_EX_COMPOSITED := 0x02000000) | (WS_EX_LAYERED := 0x00080000)
Gui, Add, Custom, ClassMagnifier hwndhMagnifier x0 y0 w%w% h%h%
Gui, Show, x0 y0 w%w% h%h%

VarSetCapacity(MAGTRANSFORM, 36, 0)
for k, v in [scaleFactor, scaleFactor, 1]
   NumPut(v, MAGTRANSFORM, (A_Index - 1) * 16, "Float")
DllCall("magnification\MagSetWindowTransform", "Ptr", hMagnifier, "Ptr", &MAGTRANSFORM)

if (A_PtrSize = 4)
   params := ["Int", x, "Int", y, "Int", w, "Int", h]
else {
   VarSetCapacity(RECT, 16, 0)
   for k, v in [x, y, w, h]
      NumPut(v, RECT, (A_Index - 1) * 4, "Int")
   params := ["Ptr", &RECT]
}
Loop
   DllCall("magnification\MagSetWindowSource", "Ptr", hMagnifier, params*)
Return

GuiClose() {
   ExitApp
}

Uninitialize() {
   DllCall("magnification\MagUninitialize")  
}
malcev wrote: I even think that support Win-7 is bad practice.
But you can set the scale factor by this way on modern OS.

Post Reply

Return to “Ask for Help (v1)”