Magnification API and AutoHotkey - Ask for Help - AutoHotkey Community
http://www.autohotkey.com/board/topic/64060-magnification-api-and-autohotkey/
I have the following issues:
- is it possible to save the current image as a file? [my main concern, I would like to be able to navigate back to an old image if a GUI item disappears]
- does it work on Windows 8, Windows 10?
- why doesn't 100% zoom look exactly the same as the screen
- to make it work in 64-bit (I tried to do this, not sure what the problem is, it shows (0,0) instead of the correct coordinate)
- are there better alternatives, is using Gdip.ahk to printscreen and enlarge and a Static control with an image the best way, or some other way?
- is it possible to acquire the height of a tool window title bar, it doesn't appear to be available via SysGet
Thanks.
Code: Select all
;Magnification API and AutoHotkey - Ask for Help - AutoHotkey Community
;http://www.autohotkey.com/board/topic/64060-magnification-api-and-autohotkey/
OnExit, Uninitialize
vCtlW := 320, vCtlH := 240
vMagFactor := 2
vDoWinWithinScreen := 1
vOffset := 0 ;window within screen offset
;vOffset := 50
Gui, +E0x80000 +AlwaysOnTop +ToolWindow hWndhGui
Gui, Show, % "w" vCtlW " h" vCtlH " x450 y200", MagnifierWindowAHK
WinSet, Transparent, 255, % "ahk_id " hGui
vSfx := (A_PtrSize=8) ? "Ptr" : ""
hInstance := DllCall("GetWindowLong" vSfx, "Ptr",hGui, "Int",-6, "Ptr") ;GWL_HINSTANCE := -6
DllCall("kernel32\LoadLibrary", "Str","magnification.dll", "Ptr")
DllCall("magnification\MagInitialize")
GroupAdd, WinGroupMag, % "ahk_id " hGui
WS_CHILD := 0x40000000
WS_VISIBLE := 0x10000000
MS_SHOWMAGNIFIEDCURSOR := 0x1
vWinStyle := WS_CHILD | MS_SHOWMAGNIFIEDCURSOR | WS_VISIBLE
hCtl := DllCall("user32\CreateWindowEx", "UInt",0, "Str","Magnifier", "Str","MagnifierWindow", "UInt",vWinStyle, "Int",0, "Int",0, "Int",vCtlW, "Int",vCtlH, "Ptr",hGui, "Ptr",0, "Ptr",hInstance, "Ptr",0, "Ptr")
;The transformation matrix is
; (n, 0.0, 0.0)
; (0.0, n, 0.0)
; (0.0, 0.0, 1.0)
;where n is the magnification factor.
VarSetCapacity(MAGTRANSFORM, 36, 0)
NumPut(vMagFactor, MAGTRANSFORM, (1-1)*4, "Float")
NumPut(vMagFactor, MAGTRANSFORM, (5-1)*4, "Float")
NumPut(1, MAGTRANSFORM, (9-1)*4, "Float")
CoordMode, Mouse, Screen
Loop
{
if !WinActive("ahk_id " hGui)
{
Gosub Uninitialize
return
}
MouseGetPos, vMouseX, vMouseY
if !vGuiW
WinGetPos,,, vGuiW, vGuiH, % "ahk_id " hGui
vRectX := vMouseX-(vGuiW/(2*vMagFactor)), vRectY := vMouseY-(vGuiH/(2*vMagFactor))
vGuiX := vMouseX-(vGuiW/2), vGuiY := vMouseY-(vGuiH/2)
;account for window title bar
vRectY += 10/vMagFactor
DllCall("magnification\MagSetWindowTransform", "Ptr",hCtl, "Ptr",&MAGTRANSFORM)
;VarSetCapacity(RECT, 16, 0)
;NumPut(vRectX, RECT, 0, "Int") ;left
;NumPut(vRectY, RECT, 4, "Int") ;top
;NumPut(vCtlW, RECT, 8, "Int") ;right ;in this case the width is wanted
;NumPut(vCtlH, RECT, 12, "Int") ;bottom ;in this case the height is wanted
DllCall("magnification\MagSetWindowSource", "Ptr",hCtl, "Int",vRectX, "Int",vRectY, "Int",vCtlW, "Int",vCtlH)
;keep window within screen / certain coordinates
if vDoWinWithinScreen
{
if (vGuiX < vOffset)
vGuiX := vOffset
if (vGuiX+vGuiW > A_ScreenWidth-vOffset)
vGuiX := A_ScreenWidth-vOffset-vGuiW
if (vGuiY < vOffset)
vGuiY := vOffset
if (vGuiY+vGuiH > A_ScreenHeight-vOffset)
vGuiY := A_ScreenHeight-vOffset-vGuiH
}
if (vGuiX2 = vGuiX) && (vGuiY2 = vGuiY)
Sleep, 700
else
WinMove, % "ahk_id " hGui,, % vGuiX, % vGuiY
Sleep, 300
vGuiX2 := vGuiX
vGuiY2 := vGuiY
}
return
#IfWinActive MagnifierWindowAHK ahk_class AutoHotkeyGUI
Esc::
Uninitialize:
Gui, Destroy
DllCall("magnification\MagUninitialize")
ExitApp
#IfWinActive