Jump to content

Yet another... screen magnifier and info tool


Siao
 Share

Recommended Posts

Probably reinventing the wheel in quite a few cases, but oh well... :P

Got the basic idea from some thread, figured I could use something like that on my crappy screen. Wasn't happy with a few bugs, CPU use and the looks though, so rewrote one myself.

Figured I could use some pixel color/position and basic window/control info tool, so added that too.

Feats:

Resizeable and draggable main window, magnifier x1-x10. Pixel precision 5x5, hex color and coords. Window/control title, class, handle. Configuration options.

None of those features are very sophisticated, but good enough for me.

To do - resampling for better quality magnify, using GDI+ or whateva.

Posted Image

Source:

;#####################################################
#cs
Screen Magnifier, Pixel pos and Window info tool
all-in-one, by Siao
Usage:
    Main window resizeable
    Left click drags window
    Right click brings up options
    etc.
#ce
;#####################################################

#include <GUIConstants.au3>

#NoTrayIcon
Opt("WinWaitDelay", 0)
Opt("GUICloseOnESC", 0)
Opt("GUIOnEventMode", 1)

Global Const $WM_MOVING = 0x0216
;~ Global Const $WM_SIZING = 0x0214
;cursors
Global Const $IDC_SIZEALL = 32646
Global Const $IDC_ARROW = 32512
;~ Global Const $WM_SETCURSOR  = 0x0020
;Drag constants
Global Const $HTCAPTION = 2
Global Const $WM_NCLBUTTONDOWN = 0xA1
;raster opcodes
;normal:
Global Const $SRCCOPY = 0xCC0020
Global Const $MERGECOPY = 0xC000CA
;inverted:
Global Const $NOTSRCCOPY = 0x330008
;text constants:
Global Const $DT_RIGHT = 0x2

Global $nZoomFactor = 2, $aMPosOld[2], $nTrans = 200
Global $iSleepTime = 90, $nTimer = 0, $bShowMini = 1, $bShowText = 1, $bAlwaysCenter = 0, $bInvert = 0, $bMouseUpdate = 1, $bSave = 0

;Main view GUI
$hGuiMain = GUICreate("Magnifier by Siao", 400, 300, -1, -1, _
                    BitOR($WS_POPUP,$WS_BORDER,$WS_SIZEBOX+$WS_CLIPCHILDREN), _
                    $WS_EX_TOPMOST _
                    );+$WS_EX_LAYERED+$WS_EX_TRANSPARENT

;Mini view GUI
$hGuiMini = GUICreate("Aimpoint 5x5", 128,128,400-130,0,$WS_CHILD+$WS_BORDER, -1, $hGuiMain)


;Options GUI
#Region ### START Koda GUI section ### Form=d:\miniprojects\autoit3\magnifier\guioptions.kxf
$hGuiOpt = GUICreate("Magnifier Options", 305, 230, -1, -1, BitOR($WS_SYSMENU,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS), -1, $hGuiMain)
$btnMin = GUICtrlCreateButton("Minimize", 5, 5, 145, 25, 0)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$btnQuit = GUICtrlCreateButton("Quit Program", 155, 5, 145, 25, 0)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$SliderTrans = GUICtrlCreateSlider(6, 54, 19, 165, BitOR($TBS_VERT,$TBS_AUTOTICKS))
GUICtrlSetCursor (-1, 11)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$grp1 = GUICtrlCreateGroup("View options", 60, 40, 235, 147)
$SliderZoom = GUICtrlCreateSlider(126, 60, 161, 19);, $TBS_AUTOTICKS)
GUICtrlSetLimit(-1, 100, 1)
GUICtrlSetData(-1, 2)
GUICtrlSetCursor (-1, 13)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$cbInvert = GUICtrlCreateCheckbox("Invert colors", 76, 90, 93, 21)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$cbCenter = GUICtrlCreateCheckbox("Always center", 76, 108, 93, 21)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$Label1 = GUICtrlCreateLabel("Zoom:", 74, 60, 50, 17)
$cbInfoPix = GUICtrlCreateCheckbox("Show pixel info", 182, 108, 93, 21)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$cbInfoWin = GUICtrlCreateCheckbox("Show win info", 182, 90, 93, 21)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$inTimer = GUICtrlCreateInput("", 192, 136, 37, 21, $ES_NUMBER)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$Label3 = GUICtrlCreateLabel("Update time (ms):", 106, 138, 86, 17)
$cbMouseUpdate = GUICtrlCreateCheckbox("Update only on mouse move", 104, 159, 161, 21)
GUICtrlSetOnEvent(-1, "OptionsEvents")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label2 = GUICtrlCreateLabel("Trans:", 6, 40, 34, 17)
$Label4 = GUICtrlCreateLabel("(c) Siao, 2007", 300, 226, 1, 1, BitOR($SS_CENTER,$SS_CENTERIMAGE,$WS_BORDER))
GUICtrlSetCursor (-1, 0)
$Label5 = GUICtrlCreateLabel("0", 30, 204, 10, 17)
$Label6 = GUICtrlCreateLabel("255", 30, 57, 22, 17)
$cbSave = GUICtrlCreateCheckbox("Remember options", 70, 194, 113, 30)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$btnOK = GUICtrlCreateButton("OK", 198, 194, 87, 29, 0)
GUICtrlSetOnEvent(-1, "OptionsEvents")
GUISetState(@SW_DISABLE)
GUISetState(@SW_HIDE)
#EndRegion ### END Koda GUI section ###

_LoadOptions()
GUISwitch($hGuiMain)

GUISetOnEvent($GUI_EVENT_CLOSE, "SystemEvents")
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "SystemEvents")
GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "SystemEvents")

GUIRegisterMsg($WM_MOVING, "WindowEvents")
GUIRegisterMsg($WM_SIZING, "WindowEvents")

GUISetState()

;=== Main loop =========================================
While 1
    Sleep($iSleepTime)
    If BitAnd(WinGetState($hGuiMain), 16) Then ContinueLoop
    If BitAnd(WinGetState($hGuiOpt), 2) Then ContinueLoop
    _Zoom($nZoomFactor, _ZoomGetOptions())
WEnd
;========================================================

Func OptionsEvents()
    Switch @GUI_CtrlId
        Case $btnOK
            WinToggle(@GUI_WinHandle)
        Case $btnMin
            WinToggle(@GUI_WinHandle)
            GUISetState(@SW_MINIMIZE, $hGuiMain)
        Case $btnQuit
            _CloseProgram()
        Case $cbInvert
            $bInvert = BitXOR($bInvert, 1)
        Case $cbInfoPix
            $bShowMini =BitXOR($bShowMini, 1)
            WinToggle($hGuiMini)
        Case $cbInfoWin
            $bShowText = BitXOR($bShowText, 1)
        Case $cbCenter
            $bAlwaysCenter = BitXOR($bAlwaysCenter, 1)
        Case $SliderZoom
            $nZoomFactor = GUICtrlRead($SliderZoom)
            GUICtrlSetData($Label1, "Zoom: x" & $nZoomFactor)
        Case $SliderTrans
            $nTrans = 0-GUICtrlRead($SliderTrans)
            WinSetTrans($hGuiMain, "", $nTrans)
;~          GUICtrlSetTip($SliderTrans, $nTrans)
        Case $inTimer
            $iSleepTime = Int(GUICtrlRead($inTimer))
        Case $cbMouseUpdate
            $bMouseUpdate = BitXOR($bMouseUpdate, 1)
        Case $cbSave
            $bSave = BitXOR($bSave, 1)
            ;_SaveOptions()
    EndSwitch
EndFunc

Func WindowEvents($hWnd, $Msg, $wParam, $lParam)
    Switch $Msg
        Case $WM_MOVING
            ;zoom while moving
            If TimerDiff($nTimer) > $iSleepTime Then 
                _Zoom($nZoomFactor, _ZoomGetOptions())
                $nTimer = TimerInit()
            EndIf
        Case $WM_SIZING
            Local $tRECT = DllStructCreate("long; long; long; long", $lParam)
            $aTmp = WinGetPos($hGuiMini)
            DllCall("user32.dll", "int", "MoveWindow", "hwnd", $hGuiMini, _
                                    "int", DllStructGetData($tRECT, 3)-DllStructGetData($tRECT, 1)-$aTmp[2]-8, _
                                    "int", 0, _
                                    "int", $aTmp[2], "int", $aTmp[3], "int", False)
    EndSwitch
EndFunc

Func SystemEvents()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            _CloseProgram()
        Case $GUI_EVENT_PRIMARYDOWN
            _ChangeCursor($IDC_SIZEALL)
            Drag($hGuiMain)
        Case $GUI_EVENT_PRIMARYUP
            ;
        Case $GUI_EVENT_SECONDARYDOWN
            If Not BitAnd(WinGetState($hGuiOpt), 2) Then
                If Not IsDeclared("aMPosOld") Then Global $aMPosOld[2] = [0,0]
                ;Options gui size - 305,230
                WinMove($hGuiOpt, "", Min(Max($aMPosOld[0]-50, 0), @DesktopWidth-305), _
                                        Min(Max($aMPosOld[1]-50, 0), @DesktopHeight-230))
                WinToggle($hGuiOpt)
            EndIf
    EndSwitch
EndFunc

Func _CloseProgram()
    If BitAND(GUICtrlRead($cbSave), $GUI_CHECKED) Then 
        _SaveOptions()
    Else
        _ClearOptions()
    EndIf
    Exit
EndFunc

;by Zedna
Func Drag($h)
;~  dllcall("user32.dll","int","ReleaseCapture")
    DllCall("user32.dll","int","SendMessage","hWnd", $h,"int",$WM_NCLBUTTONDOWN,"int", $HTCAPTION,"int", 0)
EndFunc

Func WinToggle($hWin)
    If BitAND(WinGetState($hWin), 6) Then
        GUISetState(@SW_DISABLE, $hWin)
        GUISetState(@SW_HIDE, $hWin)
    Else
        GUISetState(@SW_ENABLE, $hWin)
        GUISetState(@SW_SHOW, $hWin)
    EndIf
EndFunc

Func _SaveOptions()
    $aPos = WinGetPos($hGuiMain)
    RegWrite("HKCU\SOFTWARE\SiaoSoft\Magnifier v1", "WindowPos", "REG_SZ", $aPos[0] & ";" & $aPos[1] & ";" & $aPos[2] & ";" & $aPos[3])
    $sOptions = $nTrans & ";" & $nZoomFactor & ";" & $bInvert & ";" & $bAlwaysCenter & ";" &  _
                $bShowText & ";" & $bShowMini & ";" & $iSleepTime & ";" & $bMouseUpdate & ";" & $bSave
    RegWrite("HKCU\SOFTWARE\SiaoSoft\Magnifier v1", "Options", "REG_SZ", $sOptions)
EndFunc
Func _LoadOptions()
    $aWinPos = StringSplit(RegRead("HKCU\SOFTWARE\SiaoSoft\Magnifier v1", "WindowPos"), ";")
    If $aWinPos[0] = 4 Then
        WinMove($hGuiMain, "", Int($aWinPos[1]), Int($aWinPos[2]), Int($aWinPos[3]), Int($aWinPos[4]))
        $aTmp = WinGetPos($hGuiMini)
        WinMove($hGuiMini, "", Int($aWinPos[3])-$aTmp[2]-8, 0)
    EndIf
    $aOpts = StringSplit(RegRead("HKCU\SOFTWARE\SiaoSoft\Magnifier v1", "Options"), ";")    
    If $aOpts[0] = 9 Then
        $nTrans = Int($aOpts[1])
        $nZoomFactor = Int($aOpts[2])
        $bInvert = Int($aOpts[3])
        $bAlwaysCenter = Int($aOpts[4])
        $bShowText = Int($aOpts[5])
        $bShowMini = Int($aOpts[6])
        $iSleepTime = Int($aOpts[7])
        $bMouseUpdate = Int($aOpts[8])
        $bSave = Int($aOpts[9])
    EndIf
    If $bShowMini Then GUICtrlSetState($cbInfoPix, $GUI_CHECKED)
    If $bShowText Then GUICtrlSetState($cbInfoWin, $GUI_CHECKED)
    If $bMouseUpdate Then GUICtrlSetState($cbMouseUpdate, $GUI_CHECKED)
    If $bInvert Then GUICtrlSetState($cbInvert, $GUI_CHECKED)
    If $bAlwaysCenter Then GUICtrlSetState($cbCenter, $GUI_CHECKED)
    If $bSave Then GUICtrlSetState($cbSave, $GUI_CHECKED)
    GUICtrlSetLimit($SliderZoom, 10, 1)
    GUICtrlSetLimit($SliderTrans, 0, -255)
    DllCall("user32.dll","int","SendMessage","hWnd", ControlGetHandle($hGuiOpt, "", $SliderZoom),"int",$TBM_SETTICFREQ,"int", 1,"int", 0)
    DllCall("user32.dll","int","SendMessage","hWnd", ControlGetHandle($hGuiOpt, "", $SliderTrans),"int",$TBM_SETTICFREQ,"int", 16,"int", 0)
    GUICtrlSetData($SliderZoom, $nZoomFactor)
    GUICtrlSetData($Label1, "Zoom: x" & $nZoomFactor)
    GUICtrlSetData($SliderTrans, 0-$nTrans)
    GUICtrlSetData($inTimer, $iSleepTime)
    WinSetTrans($hGuiMain, "", $nTrans)
    GUICtrlSetState($btnOK, $GUI_FOCUS)
    If $bShowMini Then GUISetState(@SW_SHOW, $hGuiMini)
EndFunc
Func _ClearOptions()
    $sRegRoot = "HKCU\SOFTWARE\SiaoSoft"
    RegDelete($sRegRoot & "\Magnifier v1")
    RegEnumKey($sRegRoot, 1)
    $err = @error
    RegEnumVal($sRegRoot, 1)
    If @error <> 0 And $err <> 0 Then RegDelete($sRegRoot)
EndFunc

Func _ChangeCursor($lpCursorName = 0)
    If $lpCursorName <> 0 Then
        $aRet = DllCall("user32.dll","long","LoadCursor","long",0,"long",$lpCursorName)
        $hCurs = $aRet[0]
    Else
        $hCurs = 0
    EndIf
    $aRet = DllCall("user32.dll","long","SetCursor","hwnd",$hCurs)
    Return $aRet[0]
EndFunc

Func _ZoomGetOptions()
    $nOptions = 0
    If $bShowMini Then $nOptions += 1
    If $bShowText Then $nOptions += 2
    If $bMouseUpdate Then $nOptions += 4
    If $bAlwaysCenter Then $nOptions += 8
    If $bInvert Then $nOptions += 16
    Return $nOptions
EndFunc

Func _Zoom($zf, $dwOptions)
;===============================================================================
; Parameter(s):     $zf - zoom factor
;                   $dwOptions - Can be a combination of the following:
;                       1 = Show mini window
;                       2 = Show window info
;                       4 = Update on mouse move only
;                       8 = Always center view (on screen edges)
;                       16 = Invert colors
;===============================================================================
    Local $aMPos, $aMainSize, $aMiniSize, $aMyMainDC, $aMyMiniDC, $aScreenDC, $aPen, $aPenOld, $aMiniFont, $aMiniFontOld
    Local $tRECT, $srcW, $srcH, $srcX, $srcY, $sPixel, $sWinInfo
    
    $aMPos = MouseGetPos()
    If Not IsDeclared("aMPosOld") Then Global $aMPosOld[2] = [0,0]
    If BitAND($dwOptions, 4) And $aMPos[0] = $aMPosOld[0] And $aMPos[1] = $aMPosOld[1] Then Return
    $aMPosOld = $aMPos
    $aMainSize = WinGetClientSize($hGuiMain)
    $aMiniSize = WinGetClientSize($hGuiMini)
    $aMyMainDC = DLLCall("user32.dll","int","GetDC","hwnd",$hGuiMain)
    $aMyMiniDC = DLLCall("user32.dll","int","GetDC","hwnd",$hGuiMini)
    $aScreenDC = DLLCall("user32.dll","int","GetDC","hwnd",0)
    $tRECT = DllStructCreate("long; long; long; long")

    $srcW = $aMainSize[0] / $zf
    $srcH = $aMainSize[1] / $zf
    If BitAND($dwOptions, 8) Then
        $srcX = $aMPos[0] - $aMainSize[0] / (2 * $zf)
        $srcY = $aMPos[1] - $aMainSize[1] / (2 * $zf)
        $dwRop = $MERGECOPY
    Else
        $srcX = Min(Max($aMPos[0] - $aMainSize[0] / (2 * $zf), 0), @DesktopWidth-$srcW)
        $srcY = Min(Max($aMPos[1] - $aMainSize[1] / (2 * $zf), 0), @DesktopHeight-$srcH)
        $dwRop = $SRCCOPY
    EndIf

    If BitAND($dwOptions, 16) Then $dwRop = $NOTSRCCOPY

    DLLCall("gdi32.dll","int","StretchBlt", _
        "int",$aMyMainDC[0],"int", 0,"int",0,"int",$aMainSize[0],"int",$aMainSize[1], _
        "int",$aScreenDC[0],"int", $srcX,"int",$srcY,"int",$srcW,"int",$srcH, _
        "long", $dwRop)
                
    If BitAND($dwOptions, 1) Then
        ; strech 5x5 area around cursor into Mini gui
        DLLCall("gdi32.dll","int","StretchBlt", _
            "int",$aMyMiniDC[0],"int", 0,"int",0,"int",$aMiniSize[0],"int",$aMiniSize[1], _
            "int",$aScreenDC[0],"int", $aMPos[0]-2,"int",$aMPos[1]-2,"int",5,"int",5, _
            "long", $dwRop)
        ;draw crosshair on top of it
        DLLCall("gdi32.dll","int","Arc", "hwnd", $aMyMiniDC[0], _
                            "int", 0, "int", 0, "int", $aMiniSize[0], "int", $aMiniSize[1], _
                            "int", 0, "int", $aMiniSize[1]/2, "int", 0, "int", $aMiniSize[1]/2)
        $aPen = DLLCall("gdi32.dll","hwnd","CreatePen", "int", 3, "int", 0, "int", 0x00000000)
        $aPenOld = DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $aMyMiniDC[0], "hwnd", $aPen[0])
        DLLCall("gdi32.dll","int","MoveToEx", "hwnd", $aMyMiniDC[0], "int", 0, "int", $aMiniSize[1]/2, "ptr", 0)
        DLLCall("gdi32.dll","int","LineTo", "hwnd", $aMyMiniDC[0], "int", $aMiniSize[0], "int", $aMiniSize[1]/2)
        DLLCall("gdi32.dll","int","MoveToEx", "hwnd", $aMyMiniDC[0], "int", $aMiniSize[0]/2, "int", 0, "ptr", 0)
        DLLCall("gdi32.dll","int","LineTo", "hwnd", $aMyMiniDC[0], "int", $aMiniSize[0]/2, "int", $aMiniSize[1])
        ;draw pixel color/pos text
        DllStructSetData($tRECT, 1, 0)
        DllStructSetData($tRECT, 2, 0)
        DllStructSetData($tRECT, 3, $aMiniSize[0])
        DllStructSetData($tRECT, 4, 14)     
        $aMiniFont = DLLCall("gdi32.dll","int","CreateFont", "int", 14, "int", 0, "int", 0, "int", 0, "int", 700, _
                                "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, _
                                "dword", 0, "str", "")
        $aMiniFontOld = DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $aMyMiniDC[0], "hwnd", $aMiniFont[0])
        $sPixel = " 0x" & Hex(PixelGetColor($aMPos[0],$aMPos[1]),6) & " at " & $aMPos[0] & "," & $aMPos[1] & "               "
        DLLCall("user32.dll","int","DrawText", "hwnd", $aMyMiniDC[0], _
                            "str", $sPixel, "int", StringLen($sPixel), "ptr", DllStructGetPtr($tRECT), "uint", 0)
        DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $aMyMiniDC[0], "hwnd", $aMiniFontOld[0])
        DLLCall("gdi32.dll","int","DeleteObject", "hwnd", $aMiniFont[0])
        DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $aMyMiniDC[0], "hwnd", $aPenOld[0])
        DLLCall("gdi32.dll","int","DeleteObject", "hwnd", $aPen[0])
    EndIf
    
    If BitAND($dwOptions, 2) Then
        ;get and show window/control info
        $sWinInfo = _WinInfoFromPoint($aMPos[0], $aMPos[1]) 
        DllStructSetData($tRECT, 1, 0)
        DllStructSetData($tRECT, 2, $aMainSize[1]-48)
        DllStructSetData($tRECT, 3, $aMainSize[0])
        DllStructSetData($tRECT, 4, $aMainSize[1])
        DLLCall("user32.dll","int","DrawText", "hwnd", $aMyMainDC[0], _
                            "str", $sWinInfo, "int", StringLen($sWinInfo), "ptr", DllStructGetPtr($tRECT), "uint", $DT_RIGHT)
    EndIf

    DLLCall("user32.dll","int","ReleaseDC","hwnd",0,"hwnd",$aScreenDC[0])
    DLLCall("user32.dll","int","ReleaseDC","hwnd",$hGuiMain,"hwnd",$aMyMainDC[0])
    DLLCall("user32.dll","int","ReleaseDC","hwnd",$hGuiMini,"hwnd",$aMyMiniDC[0])

EndFunc

;Gets window/control info from cursor pos, returns formatted string
Func _WinInfoFromPoint($nX, $nY)
    Local $tStrBuff, $pStrBuff, $aRet, $hWnd, $hOwnerWnd, $sClassName, $sOwnerClass, $sWinText
    $tStrBuff = DllStructCreate("char[100]")
    $pStrBuff = DllStructGetPtr($tStrBuff)
    $aRet = DllCall("user32.dll", "hwnd", "WindowFromPoint", "uint", $nX, "uint", $nY)
    $hWnd = $aRet[0]
    $aRet = DllCall("user32.dll", "int", "GetClassName", "hwnd", $hWnd, "ptr", $pStrBuff, "int", 100)
    $sClassName = DllStructGetData($tStrBuff, 1)
    DllStructSetData($tStrBuff, 1, "")
    DllCall("user32.dll", "int", "GetWindowText", "hwnd", $hWnd, "ptr", $pStrBuff, "int", 100)
;~  DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "uint", $WM_GETTEXT, "uint", 100, "ptr", $pStrBuff)
    $sWinText = DllStructGetData($tStrBuff, 1)
    DllStructSetData($tStrBuff, 1, "")  
    $aRet = DllCall("user32.dll", "hwnd", "GetAncestor", "hwnd", $hWnd, "uint", 2) ;$GA_ROOT = 2
    $hOwnerWnd = $aRet[0]
    $aRet = DllCall("user32.dll", "int", "GetClassName", "hwnd", $hOwnerWnd, "ptr", $pStrBuff, "int", 100)
    $sOwnerClass = DllStructGetData($tStrBuff, 1)
    DllStructSetData($tStrBuff, 1, "")

    Return $sWinText & @CRLF & "[ Class: " & $sClassName & "; hWnd: " & $hWnd & " ]" & @CRLF & _
                        "( Owner: " & $sOwnerClass & "; " & $hOwnerWnd & " )"
EndFunc

Func Min($n1, $n2)
    If $n1 < $n2 Then Return $n1
    Return $n2
EndFunc
Func Max($n1, $n2)
    If $n1 > $n2 Then Return $n1
    Return $n2
EndFunc

;================

or attachment...

screen_magnifier_v1.au3

"be smart, drink your wine"

Link to comment
Share on other sites

  • 2 months later...

Siao, your code is very handy and does what it's supposed to do very well.

It serves as ideal victim to be hacked into a utility I've always dreamed of...

post-14785-1199471458_thumb.png

;#####################################################
#cs

lod3n\Siao\hilight, by Siao (99%) and lod3n (1%)

Normally when I read text on the web, I have a habit of selecting the text I am
reading, to help keep me focused on where I am in the text. I wrote a utility before
to place a semi-transparent yellow gui line above, but sometimes there would be
contrast problems depending on what I was reading. I really wanted it to be inverted.

This is a Reverse hilight line tool, to help with reading large amounts of 
text on a comptuer screen. I've (very quickly and inefficently) hacked Saio's 
neat Screen Magnifier so that it appears to invert 25 pixels of the screen 
directly above the mouse. There's still a great deal of optimization that could 
be done, but it serves my purposes.

I have a shortcut to the script in my QuickLaunch bar (icon: shell32.dll, #242), 
and if you create a second instance of the script, both scripts shut down, 
essentially turning that shortcut into a toggle switch.

Runs fine on AutoIt 3.2.8.1

;~ Screen Magnifier, Pixel pos and Window info tool
;~ all-in-one, by Siao
;~ Usage:
;~  Main window resizeable
;~  Left click drags window
;~  Right click brings up options
;~  etc.
#ce
;#####################################################
#NoTrayIcon
#include <GUIConstants.au3>
#include <Misc.au3>
$wintitle = "lod3n\Siao\hilight"
Global $iGuiHeight = 25

$hGuiMain = GUICreate($wintitle, @DesktopWidth, $iGuiHeight, -1, -1, _
    BitOR($WS_POPUP,$WS_CLIPCHILDREN), _
    BitOR($WS_EX_TOOLWINDOW,$WS_EX_TOPMOST) _
)

if _Singleton($wintitle,1) = 0 Then
    
    $list = WinList($wintitle)
    for $i = 1 to $list[0][0]
        if $list[$i][1] <> $hGuiMain then 
            ProcessClose(WinGetProcess($list[$i][1]))
        EndIf
    next
    
    Exit
EndIf


Opt("WinWaitDelay", 0)
Opt("GUICloseOnESC", 0)
;~ Opt("GUIOnEventMode", 1) ; 

Global Const $WM_MOVING = 0x0216
;~ Global Const $WM_SIZING = 0x0214
;cursors
;~ Global Const $IDC_SIZEALL = 32646
;~ Global Const $IDC_ARROW = 32512
;~ Global Const $WM_SETCURSOR  = 0x0020
;Drag constants
;~ Global Const $HTCAPTION = 2
;~ Global Const $WM_NCLBUTTONDOWN = 0xA1
;raster opcodes
;normal:
;~ Global Const $SRCCOPY = 0xCC0020
;~ Global Const $MERGECOPY = 0xC000CA
;inverted:
;~ Global Const $NOTSRCCOPY = 0x330008
;text constants:
;~ Global Const $DT_RIGHT = 0x2

Global $nZoomFactor = 1, $aMPosOld[2], $nTrans = 255
Global $iSleepTime = 90, $nTimer = 0, $bShowMini = 1, $bShowText = 1, $bAlwaysCenter = 0, $bInvert = 1, $bMouseUpdate = 1, $bSave = 0



;Main view GUI
;+$WS_EX_LAYERED+$WS_EX_TRANSPARENT

;Mini view GUI
;~ $hGuiMini = GUICreate("Aimpoint 5x5", 128,128,400-130,0,$WS_CHILD+$WS_BORDER, -1, $hGuiMain)


;Options GUI
#Region ### START Koda GUI section ### Form=d:\miniprojects\autoit3\magnifier\guioptions.kxf
$hGuiOpt = GUICreate("Magnifier Options", 305, 230, -1, -1, BitOR($WS_SYSMENU,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS), -1, $hGuiMain)
$btnMin = GUICtrlCreateButton("Minimize", 5, 5, 145, 25, 0)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$btnQuit = GUICtrlCreateButton("Quit Program", 155, 5, 145, 25, 0)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$SliderTrans = GUICtrlCreateSlider(6, 54, 19, 165, BitOR($TBS_VERT,$TBS_AUTOTICKS))
GUICtrlSetCursor (-1, 11)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$grp1 = GUICtrlCreateGroup("View options", 60, 40, 235, 147)
$SliderZoom = GUICtrlCreateSlider(126, 60, 161, 19);, $TBS_AUTOTICKS)
GUICtrlSetLimit(-1, 100, 1)
GUICtrlSetData(-1, 1)
GUICtrlSetCursor (-1, 13)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$cbInvert = GUICtrlCreateCheckbox("Invert colors", 76, 90, 93, 21)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$cbCenter = GUICtrlCreateCheckbox("Always center", 76, 108, 93, 21)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$Label1 = GUICtrlCreateLabel("Zoom:", 74, 60, 50, 17)
$cbInfoPix = GUICtrlCreateCheckbox("Show pixel info", 182, 108, 93, 21)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$cbInfoWin = GUICtrlCreateCheckbox("Show win info", 182, 90, 93, 21)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$inTimer = GUICtrlCreateInput("", 192, 136, 37, 21, $ES_NUMBER)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$Label3 = GUICtrlCreateLabel("Update time (ms):", 106, 138, 86, 17)
$cbMouseUpdate = GUICtrlCreateCheckbox("Update only on mouse move", 104, 159, 161, 21)
GUICtrlSetOnEvent(-1, "OptionsEvents")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label2 = GUICtrlCreateLabel("Trans:", 6, 40, 34, 17)
$Label4 = GUICtrlCreateLabel("(c) Siao, 2007", 300, 226, 1, 1, BitOR($SS_CENTER,$SS_CENTERIMAGE,$WS_BORDER))
GUICtrlSetCursor (-1, 0)
$Label5 = GUICtrlCreateLabel("0", 30, 204, 10, 17)
$Label6 = GUICtrlCreateLabel("255", 30, 57, 22, 17)
$cbSave = GUICtrlCreateCheckbox("Remember options", 70, 194, 113, 30)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$btnOK = GUICtrlCreateButton("OK", 198, 194, 87, 29, 0)
GUICtrlSetOnEvent(-1, "OptionsEvents")
GUISetState(@SW_DISABLE)
GUISetState(@SW_HIDE)
#EndRegion ### END Koda GUI section ###

_LoadOptions()




GUISwitch($hGuiMain)

GUISetOnEvent($GUI_EVENT_CLOSE, "SystemEvents")
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "SystemEvents")
GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "SystemEvents")

GUIRegisterMsg($WM_MOVING, "WindowEvents")
GUIRegisterMsg($WM_SIZING, "WindowEvents")

GUISetState()

;=== Main loop =========================================

$lastY = 0
While 1
    $msg = GUIGetMsg()
    $thisY = MouseGetPos(1)
    if $lastY <> $thisY Then
        $lastY = $thisY
        _Zoom($nZoomFactor, _ZoomGetOptions())
    EndIf
WEnd

;~ While 1
;~  Sleep($iSleepTime)
;~  If BitAnd(WinGetState($hGuiMain), 16) Then ContinueLoop
;~  If BitAnd(WinGetState($hGuiOpt), 2) Then ContinueLoop
;~  _Zoom($nZoomFactor, _ZoomGetOptions())
;~    if TrayGetMsg ( )
;~ WEnd
;========================================================

Func OptionsEvents()
    Switch @GUI_CtrlId
        Case $btnOK
            WinToggle(@GUI_WinHandle)
        Case $btnMin
            WinToggle(@GUI_WinHandle)
            GUISetState(@SW_MINIMIZE, $hGuiMain)
        Case $btnQuit
            _CloseProgram()
        Case $cbInvert
            $bInvert = BitXOR($bInvert, 1)
        Case $cbInfoPix
            $bShowMini =BitXOR($bShowMini, 1)
;~          WinToggle($hGuiMini)
        Case $cbInfoWin
            $bShowText = BitXOR($bShowText, 1)
        Case $cbCenter
            $bAlwaysCenter = BitXOR($bAlwaysCenter, 1)
        Case $SliderZoom
            $nZoomFactor = GUICtrlRead($SliderZoom)
            GUICtrlSetData($Label1, "Zoom: x" & $nZoomFactor)
        Case $SliderTrans
            $nTrans = 0-GUICtrlRead($SliderTrans)
            WinSetTrans($hGuiMain, "", $nTrans)
;~          GUICtrlSetTip($SliderTrans, $nTrans)
        Case $inTimer
            $iSleepTime = Int(GUICtrlRead($inTimer))
        Case $cbMouseUpdate
            $bMouseUpdate = BitXOR($bMouseUpdate, 1)
        Case $cbSave
            $bSave = BitXOR($bSave, 1)
            ;_SaveOptions()
    EndSwitch
EndFunc

Func WindowEvents($hWnd, $Msg, $wParam, $lParam)
    Switch $Msg
        Case $WM_MOVING
            ;zoom while moving
            If TimerDiff($nTimer) > $iSleepTime Then 
                _Zoom($nZoomFactor, _ZoomGetOptions())
                $nTimer = TimerInit()
            EndIf
        Case $WM_SIZING
;~          Local $tRECT = DllStructCreate("long; long; long; long", $lParam)
;~          $aTmp = WinGetPos($hGuiMini)
;~          DllCall("user32.dll", "int", "MoveWindow", "hwnd", $hGuiMini, _
;~                                  "int", DllStructGetData($tRECT, 3)-DllStructGetData($tRECT, 1)-$aTmp[2]-8, _
;~                                  "int", 0, _
;~                                  "int", $aTmp[2], "int", $aTmp[3], "int", False)
    EndSwitch
EndFunc

Func SystemEvents()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            _CloseProgram()
        Case $GUI_EVENT_PRIMARYDOWN
            _ChangeCursor($IDC_SIZEALL)
            Drag($hGuiMain)
        Case $GUI_EVENT_PRIMARYUP
            ;
        Case $GUI_EVENT_SECONDARYDOWN
            If Not BitAnd(WinGetState($hGuiOpt), 2) Then
                If Not IsDeclared("aMPosOld") Then Global $aMPosOld[2] = [0,0]
                ;Options gui size - 305,230
                WinMove($hGuiOpt, "", Min(Max($aMPosOld[0]-50, 0), @DesktopWidth-305), _
                                        Min(Max($aMPosOld[1]-50, 0), @DesktopHeight-230))
                WinToggle($hGuiOpt)
            EndIf
    EndSwitch
EndFunc

Func _CloseProgram()
;~  If BitAND(GUICtrlRead($cbSave), $GUI_CHECKED) Then 
;~      _SaveOptions()
;~  Else
;~      _ClearOptions()
;~  EndIf
    Exit
EndFunc

;by Zedna
Func Drag($h)
;~  dllcall("user32.dll","int","ReleaseCapture")
    DllCall("user32.dll","int","SendMessage","hWnd", $h,"int",$WM_NCLBUTTONDOWN,"int", $HTCAPTION,"int", 0)
EndFunc

Func WinToggle($hWin)
    If BitAND(WinGetState($hWin), 6) Then
        GUISetState(@SW_DISABLE, $hWin)
        GUISetState(@SW_HIDE, $hWin)
    Else
        GUISetState(@SW_ENABLE, $hWin)
        GUISetState(@SW_SHOW, $hWin)
    EndIf
EndFunc

;~ Func _SaveOptions()
;~  $aPos = WinGetPos($hGuiMain)
;~  RegWrite("HKCU\SOFTWARE\SiaoSoft\Magnifier v1", "WindowPos", "REG_SZ", $aPos[0] & ";" & $aPos[1] & ";" & $aPos[2] & ";" & $aPos[3])
;~  $sOptions = $nTrans & ";" & $nZoomFactor & ";" & $bInvert & ";" & $bAlwaysCenter & ";" &  _
;~              $bShowText & ";" & $bShowMini & ";" & $iSleepTime & ";" & $bMouseUpdate & ";" & $bSave
;~  RegWrite("HKCU\SOFTWARE\SiaoSoft\Magnifier v1", "Options", "REG_SZ", $sOptions)
;~ EndFunc
Func _LoadOptions()
;~  $aWinPos = StringSplit(RegRead("HKCU\SOFTWARE\SiaoSoft\Magnifier v1", "WindowPos"), ";")
;~  If $aWinPos[0] = 4 Then
;~      WinMove($hGuiMain, "", Int($aWinPos[1]), Int($aWinPos[2]), Int($aWinPos[3]), Int($aWinPos[4]))
;~      $aTmp = WinGetPos($hGuiMini)
;~      WinMove($hGuiMini, "", Int($aWinPos[3])-$aTmp[2]-8, 0)
;~  EndIf
;~  $aOpts = StringSplit(RegRead("HKCU\SOFTWARE\SiaoSoft\Magnifier v1", "Options"), ";")    
;~  If $aOpts[0] = 9 Then
;~      $nTrans = Int($aOpts[1])
;~      $nZoomFactor = Int($aOpts[2])
;~      $bInvert = Int($aOpts[3])
;~      $bAlwaysCenter = Int($aOpts[4])
;~      $bShowText = Int($aOpts[5])
;~      $bShowMini = Int($aOpts[6])
;~      $iSleepTime = Int($aOpts[7])
;~      $bMouseUpdate = Int($aOpts[8])
;~      $bSave = Int($aOpts[9])
;~  EndIf
    If $bShowMini Then GUICtrlSetState($cbInfoPix, $GUI_CHECKED)
    If $bShowText Then GUICtrlSetState($cbInfoWin, $GUI_CHECKED)
    If $bMouseUpdate Then GUICtrlSetState($cbMouseUpdate, $GUI_CHECKED)
    If $bInvert Then GUICtrlSetState($cbInvert, $GUI_CHECKED)
    If $bAlwaysCenter Then GUICtrlSetState($cbCenter, $GUI_CHECKED)
    If $bSave Then GUICtrlSetState($cbSave, $GUI_CHECKED)
    GUICtrlSetLimit($SliderZoom, 10, 1)
    GUICtrlSetLimit($SliderTrans, 0, -255)
    DllCall("user32.dll","int","SendMessage","hWnd", ControlGetHandle($hGuiOpt, "", $SliderZoom),"int",$TBM_SETTICFREQ,"int", 1,"int", 0)
    DllCall("user32.dll","int","SendMessage","hWnd", ControlGetHandle($hGuiOpt, "", $SliderTrans),"int",$TBM_SETTICFREQ,"int", 16,"int", 0)
    GUICtrlSetData($SliderZoom, $nZoomFactor)
    GUICtrlSetData($Label1, "Zoom: x" & $nZoomFactor)
    GUICtrlSetData($SliderTrans, 0-$nTrans)
    GUICtrlSetData($inTimer, $iSleepTime)
    WinSetTrans($hGuiMain, "", $nTrans)
    GUICtrlSetState($btnOK, $GUI_FOCUS)
;~  If $bShowMini Then GUISetState(@SW_SHOW, $hGuiMini)
EndFunc
;~ Func _ClearOptions()
;~  $sRegRoot = "HKCU\SOFTWARE\SiaoSoft"
;~  RegDelete($sRegRoot & "\Magnifier v1")
;~  RegEnumKey($sRegRoot, 1)
;~  $err = @error
;~  RegEnumVal($sRegRoot, 1)
;~  If @error <> 0 And $err <> 0 Then RegDelete($sRegRoot)
;~ EndFunc

Func _ChangeCursor($lpCursorName = 0)
    If $lpCursorName <> 0 Then
        $aRet = DllCall("user32.dll","long","LoadCursor","long",0,"long",$lpCursorName)
        $hCurs = $aRet[0]
    Else
        $hCurs = 0
    EndIf
    $aRet = DllCall("user32.dll","long","SetCursor","hwnd",$hCurs)
    Return $aRet[0]
EndFunc

Func _ZoomGetOptions()
    $nOptions = 0
    If $bShowMini Then $nOptions += 1
    If $bShowText Then $nOptions += 2
    If $bMouseUpdate Then $nOptions += 4
    If $bAlwaysCenter Then $nOptions += 8
    If $bInvert Then $nOptions += 16
    Return $nOptions
EndFunc

Func _Zoom($zf, $dwOptions)
;===============================================================================
; Parameter(s):     $zf - zoom factor
;                   $dwOptions - Can be a combination of the following:
;                       1 = Show mini window
;                       2 = Show window info
;                       4 = Update on mouse move only
;                       8 = Always center view (on screen edges)
;                       16 = Invert colors
;===============================================================================
    Local $aMPos, $aMainSize, $aMiniSize, $aMyMainDC, $aMyMiniDC, $aScreenDC, $aPen, $aPenOld, $aMiniFont, $aMiniFontOld
    Local $tRECT, $srcW, $srcH, $srcX, $srcY, $sPixel, $sWinInfo
    
    $aMPos = MouseGetPos()
    $aMPos[1] = $aMPos[1]-$iGuiHeight
    
    If Not IsDeclared("aMPosOld") Then Global $aMPosOld[2] = [0,0]
    If BitAND($dwOptions, 4) And $aMPos[0] = $aMPosOld[0] And $aMPos[1] = $aMPosOld[1] Then Return
    
;~  winmove($hGuiMain,"",0,$aMPos[1]-13)
    
    
    $aMPosOld = $aMPos
    $aMainSize = WinGetClientSize($hGuiMain)
;~  $aMiniSize = WinGetClientSize($hGuiMini)
    $aMyMainDC = DLLCall("user32.dll","int","GetDC","hwnd",$hGuiMain)
;~  $aMyMiniDC = DLLCall("user32.dll","int","GetDC","hwnd",$hGuiMini)
    $aScreenDC = DLLCall("user32.dll","int","GetDC","hwnd",0)
    $tRECT = DllStructCreate("long; long; long; long")

    $srcW = $aMainSize[0] / $zf
    $srcH = $aMainSize[1] / $zf
    If BitAND($dwOptions, 8) Then
        $srcX = $aMPos[0] - $aMainSize[0] / (2 * $zf)
        $srcY = $aMPos[1] - $aMainSize[1] / (2 * $zf)
        $dwRop = $MERGECOPY
    Else
        $srcX = Min(Max($aMPos[0] - $aMainSize[0] / (2 * $zf), 0), @DesktopWidth-$srcW)
        $srcY = Min(Max($aMPos[1] - $aMainSize[1] / (2 * $zf), 0), @DesktopHeight-$srcH)
        $dwRop = $SRCCOPY
    EndIf

    If BitAND($dwOptions, 16) Then $dwRop = $NOTSRCCOPY

    DLLCall("gdi32.dll","int","StretchBlt", _
        "int",$aMyMainDC[0],"int", 0,"int",0,"int",$aMainSize[0],"int",$aMainSize[1], _
        "int",$aScreenDC[0],"int", $srcX,"int",$srcY,"int",$srcW,"int",$srcH, _
        "long", $dwRop)
                
;~  If BitAND($dwOptions, 1) Then
        ; strech 5x5 area around cursor into Mini gui
;~      DLLCall("gdi32.dll","int","StretchBlt", _
;~          "int",$aMyMiniDC[0],"int", 0,"int",0,"int",$aMiniSize[0],"int",$aMiniSize[1], _
;~          "int",$aScreenDC[0],"int", $aMPos[0]-2,"int",$aMPos[1]-2,"int",5,"int",5, _
;~          "long", $dwRop)
        ;draw crosshair on top of it
;~      DLLCall("gdi32.dll","int","Arc", "hwnd", $aMyMiniDC[0], _
;~                          "int", 0, "int", 0, "int", $aMiniSize[0], "int", $aMiniSize[1], _
;~                          "int", 0, "int", $aMiniSize[1]/2, "int", 0, "int", $aMiniSize[1]/2)
;~      $aPen = DLLCall("gdi32.dll","hwnd","CreatePen", "int", 3, "int", 0, "int", 0x00000000)
;~      $aPenOld = DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $aMyMiniDC[0], "hwnd", $aPen[0])
;~      DLLCall("gdi32.dll","int","MoveToEx", "hwnd", $aMyMiniDC[0], "int", 0, "int", $aMiniSize[1]/2, "ptr", 0)
;~      DLLCall("gdi32.dll","int","LineTo", "hwnd", $aMyMiniDC[0], "int", $aMiniSize[0], "int", $aMiniSize[1]/2)
;~      DLLCall("gdi32.dll","int","MoveToEx", "hwnd", $aMyMiniDC[0], "int", $aMiniSize[0]/2, "int", 0, "ptr", 0)
;~      DLLCall("gdi32.dll","int","LineTo", "hwnd", $aMyMiniDC[0], "int", $aMiniSize[0]/2, "int", $aMiniSize[1])
        ;draw pixel color/pos text
;~      DllStructSetData($tRECT, 1, 0)
;~      DllStructSetData($tRECT, 2, 0)
;~      DllStructSetData($tRECT, 3, $aMiniSize[0])
;~      DllStructSetData($tRECT, 4, 14)     
;~      $aMiniFont = DLLCall("gdi32.dll","int","CreateFont", "int", 14, "int", 0, "int", 0, "int", 0, "int", 700, _
;~                              "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, _
;~                              "dword", 0, "str", "")
;~      $aMiniFontOld = DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $aMyMiniDC[0], "hwnd", $aMiniFont[0])
;~      $sPixel = " 0x" & Hex(PixelGetColor($aMPos[0],$aMPos[1]),6) & " at " & $aMPos[0] & "," & $aMPos[1] & "               "
;~      DLLCall("user32.dll","int","DrawText", "hwnd", $aMyMiniDC[0], _
;~                          "str", $sPixel, "int", StringLen($sPixel), "ptr", DllStructGetPtr($tRECT), "uint", 0)
;~      DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $aMyMiniDC[0], "hwnd", $aMiniFontOld[0])
;~      DLLCall("gdi32.dll","int","DeleteObject", "hwnd", $aMiniFont[0])
;~      DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $aMyMiniDC[0], "hwnd", $aPenOld[0])
;~      DLLCall("gdi32.dll","int","DeleteObject", "hwnd", $aPen[0])
;~  EndIf
    
    If BitAND($dwOptions, 2) Then
        ;get and show window/control info
        $sWinInfo = _WinInfoFromPoint($aMPos[0], $aMPos[1]) 
        DllStructSetData($tRECT, 1, 0)
        DllStructSetData($tRECT, 2, $aMainSize[1]-48)
        DllStructSetData($tRECT, 3, $aMainSize[0])
        DllStructSetData($tRECT, 4, $aMainSize[1])
        DLLCall("user32.dll","int","DrawText", "hwnd", $aMyMainDC[0], _
                            "str", $sWinInfo, "int", StringLen($sWinInfo), "ptr", DllStructGetPtr($tRECT), "uint", $DT_RIGHT)
    EndIf

    DLLCall("user32.dll","int","ReleaseDC","hwnd",0,"hwnd",$aScreenDC[0])
    DLLCall("user32.dll","int","ReleaseDC","hwnd",$hGuiMain,"hwnd",$aMyMainDC[0])
;~  DLLCall("user32.dll","int","ReleaseDC","hwnd",$hGuiMini,"hwnd",$aMyMiniDC[0])
    winmove($hGuiMain,"",0,$aMPos[1]-13)
EndFunc

;Gets window/control info from cursor pos, returns formatted string
Func _WinInfoFromPoint($nX, $nY)
    Local $tStrBuff, $pStrBuff, $aRet, $hWnd, $hOwnerWnd, $sClassName, $sOwnerClass, $sWinText
    $tStrBuff = DllStructCreate("char[100]")
    $pStrBuff = DllStructGetPtr($tStrBuff)
    $aRet = DllCall("user32.dll", "hwnd", "WindowFromPoint", "uint", $nX, "uint", $nY)
    $hWnd = $aRet[0]
    $aRet = DllCall("user32.dll", "int", "GetClassName", "hwnd", $hWnd, "ptr", $pStrBuff, "int", 100)
    $sClassName = DllStructGetData($tStrBuff, 1)
    DllStructSetData($tStrBuff, 1, "")
    DllCall("user32.dll", "int", "GetWindowText", "hwnd", $hWnd, "ptr", $pStrBuff, "int", 100)
;~  DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "uint", $WM_GETTEXT, "uint", 100, "ptr", $pStrBuff)
    $sWinText = DllStructGetData($tStrBuff, 1)
    DllStructSetData($tStrBuff, 1, "")  
    $aRet = DllCall("user32.dll", "hwnd", "GetAncestor", "hwnd", $hWnd, "uint", 2) ;$GA_ROOT = 2
    $hOwnerWnd = $aRet[0]
    $aRet = DllCall("user32.dll", "int", "GetClassName", "hwnd", $hOwnerWnd, "ptr", $pStrBuff, "int", 100)
    $sOwnerClass = DllStructGetData($tStrBuff, 1)
    DllStructSetData($tStrBuff, 1, "")
    Return ""
;~  Return $sWinText & @CRLF & "[ Class: " & $sClassName & "; hWnd: " & $hWnd & " ]" & @CRLF & _
;~                      "( Owner: " & $sOwnerClass & "; " & $hOwnerWnd & " )"
EndFunc

Func Min($n1, $n2)
    If $n1 < $n2 Then Return $n1
    Return $n2
EndFunc
Func Max($n1, $n2)
    If $n1 > $n2 Then Return $n1
    Return $n2
EndFunc

;================

Updated to work with AutoIt Prod 3.2.10.0

Edited by lod3n

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

This is a Reverse highlight screen line tool, to help with reading large amounts of

text on a computer screen.

An interesting effect. Would be very useful for demos and teaching on remote PCs where someone else is looking at your screen. In that case also having a way to select an area would be good. And then I suppose you would need Select Area, Show Inverted, Show Border and so on.

You have left the code for _SaveOptions() and _ClearOptions() in the function CloseProgram but have commented out those 2 functions, so there are errors.

Also there is nothing in the script that I can see to allow you to stop it.

The effect goes wrong when the rectangle reaches beyond the top of the screen.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

@martin:

>An interesting effect. Would be very useful for demos and teaching on remote PCs where someone else is looking at your screen. In that case also having a way to select an area would be good. And then I suppose you would need Select Area, Show Inverted, Show Border and so on.

In that case, Siao's original script is pretty much ideal, as it does everything you mentioned. Might just comment out the bits that create the crosshair and window info.

>You have left the code for _SaveOptions() and _ClearOptions() in the function CloseProgram but have commented out those 2 functions, so there are errors.

Thanks, I've corrected that.

>Also there is nothing in the script that I can see to allow you to stop it.

There isn't a way to stop it except to run a second instance of the script. I wanted the shortcut to the script work as a toggle.

>The effect goes wrong when the rectangle reaches beyond the top of the screen.

I don't see what I could really do about it, except move the gui below the mouse. But for my purposes it doesn't really matter, as the text I want to hilight is always lower than that.

@Manadar:

Thanks! All credit goes to Siao, I just built a little bit upon what he already wrote.

Edited by lod3n

[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Link to comment
Share on other sites

Really usefull for finding colors. My only critism is that the super zoomed in window on the top right is too small for the amount of magnification being used. Sometimes it's hard to exactly place where you are. An option to expand that box to use the entire GUI would be cool.

Hallman

Edited by Hallman
Link to comment
Share on other sites

  • 1 month later...

This looks like what I've been searching for (window info tool that I can brand/wrap), but it's not running for me.

I downloaded 'screen magnifier v1.au3' and attempted to run it (without changing the code), but I'm getting this error...

~~~~~~~~~~~~~~~~~~~~~~

Line 23

Global Const $IDC_SIZEALL = 32646

Global Const ^ERROR

Error: Can not redeclare a constant.

~~~~~~~~~~~~~~~~~~~~~~~

It looks to me like it's being declared, but not redeclared. I'm using AutoIt v3.

Any ideas how to fix this would be appreciated.

Link to comment
Share on other sites

This looks like what I've been searching for (window info tool that I can brand/wrap), but it's not running for me.

I downloaded 'screen magnifier v1.au3' and attempted to run it (without changing the code), but I'm getting this error...

~~~~~~~~~~~~~~~~~~~~~~

Line 23

Global Const $IDC_SIZEALL = 32646

Global Const ^ERROR

Error: Can not redeclare a constant.

~~~~~~~~~~~~~~~~~~~~~~~

It looks to me like it's being declared, but not redeclared. I'm using AutoIt v3.

Any ideas how to fix this would be appreciated.

Comment out that line and any others that throw the same error.

Edit: Spelling

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

GEOSoft, thanks for the quick reply.

I commented out lines 23, 24, 27, 28, 31, 32, 34, and 36.

The program now runs and I'm able to see class and handle information for a window and window title for windows with a title bar. However, I need to also collect some other information: window title for windows that don't have a title bar, visible text, control id.

Can I add this information to the script? After looking in the help file, I'm not able to determine which "function"s are available for the dll that is called, user32.dll.

I would also like to have a way to capture the window/control information. Maybe I can use ClipPut and then paste it into Notepad or something. I would need a hotkey to do the ClipPut and then a button to paste it into Notepad.

Any ideas would be appreciated.

Link to comment
Share on other sites

However, I need to also collect some other information: window title for windows that don't have a title bar, visible text, control id.

GetWindowText, GetDlgCtrlID (both have wrappers written already, see WinAPI Management in helpfile).

"be smart, drink your wine"

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 year later...

Getting these errors when running on vista with admin rights. Any help?

CODE
C:\Users\Tom\Desktop\DFPBAG\tests\magnifier\magnifier2.au3(44,21) : WARNING: $WS_POPUP: possibly used before declaration.

BitOR($WS_POPUP,

~~~~~~~~~~~~~~~^

C:\Users\Tom\Desktop\DFPBAG\tests\magnifier\magnifier2.au3(44,32) : WARNING: $WS_BORDER: possibly used before declaration.

BitOR($WS_POPUP,$WS_BORDER,

~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Tom\Desktop\DFPBAG\tests\magnifier\magnifier2.au3(44,44) : WARNING: $WS_SIZEBOX: possibly used before declaration.

BitOR($WS_POPUP,$WS_BORDER,$WS_SIZEBOX+

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Tom\Desktop\DFPBAG\tests\magnifier\magnifier2.au3(44,61) : WARNING: $WS_CLIPCHILDREN: possibly used before declaration.

BitOR($WS_POPUP,$WS_BORDER,$WS_SIZEBOX+$WS_CLIPCHILDREN)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Tom\Desktop\DFPBAG\tests\magnifier\magnifier2.au3(46,6) : WARNING: $WS_EX_TOPMOST: possibly used before declaration.

)

^

C:\Users\Tom\Desktop\DFPBAG\tests\magnifier\magnifier2.au3(49,66) : WARNING: $WS_CHILD: possibly used before declaration.

$hGuiMini = GUICreate("Aimpoint 5x5", 128,128,400-130,0,$WS_CHILD+

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Tom\Desktop\DFPBAG\tests\magnifier\magnifier2.au3(54,78) : WARNING: $WS_SYSMENU: possibly used before declaration.

$hGuiOpt = GUICreate("Magnifier Options", 305, 230, -1, -1, BitOR($WS_SYSMENU,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Tom\Desktop\DFPBAG\tests\magnifier\magnifier2.au3(54,104) : WARNING: $WS_POPUPWINDOW: possibly used before declaration.

$hGuiOpt = GUICreate("Magnifier Options", 305, 230, -1, -1, BitOR($WS_SYSMENU,$WS_POPUP,$WS_POPUPWINDOW,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~^

C:\Users\Tom\Desktop\DFPBAG\tests\magnifier\magnifier2.au3(54,132) : WARNING: $WS_CLIPSIBLINGS: possibly used before declaration.

$hGuiOpt = GUICreate("Magnifier Options", 305, 230, -1, -1, BitOR($WS_SYSMENU,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Tom\Desktop\DFPBAG\tests\magnifier\magnifier2.au3(59,67) : WARNING: $TBS_VERT: possibly used before declaration.

$SliderTrans = GUICtrlCreateSlider(6, 54, 19, 165, BitOR($TBS_VERT,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Tom\Desktop\DFPBAG\tests\magnifier\magnifier2.au3(59,82) : WARNING: $TBS_AUTOTICKS: possibly used before declaration.

$SliderTrans = GUICtrlCreateSlider(6, 54, 19, 165, BitOR($TBS_VERT,$TBS_AUTOTICKS)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Tom\Desktop\DFPBAG\tests\magnifier\magnifier2.au3(77,63) : WARNING: $ES_NUMBER: possibly used before declaration.

$inTimer = GUICtrlCreateInput("", 192, 136, 37, 21, $ES_NUMBER)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Tom\Desktop\DFPBAG\tests\magnifier\magnifier2.au3(84,80) : WARNING: $SS_CENTER: possibly used before declaration.

$Label4 = GUICtrlCreateLabel("© Siao, 2007", 300, 226, 1, 1, BitOR($SS_CENTER,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Tom\Desktop\DFPBAG\tests\magnifier\magnifier2.au3(84,96) : WARNING: $SS_CENTERIMAGE: possibly used before declaration.

$Label4 = GUICtrlCreateLabel("© Siao, 2007", 300, 226, 1, 1, BitOR($SS_CENTER,$SS_CENTERIMAGE,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Tom\Desktop\DFPBAG\tests\magnifier\magnifier2.au3(104,26) : WARNING: $WM_SIZING: possibly used before declaration.

GUIRegisterMsg($WM_SIZING,

~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Tom\Desktop\DFPBAG\tests\magnifier\magnifier2.au3(249,116) : WARNING: $TBM_SETTICFREQ: possibly used before declaration.

DllCall("user32.dll","int","SendMessage","hWnd", ControlGetHandle($hGuiOpt, "", $SliderZoom),"int",$TBM_SETTICFREQ,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~^

C:\Users\Tom\Desktop\DFPBAG\tests\magnifier\magnifier2.au3(44,21) : ERROR: $WS_POPUP: undeclared global variable.

BitOR($WS_POPUP,

~~~~~~~~~~~~~~~^

C:\Users\Tom\Desktop\DFPBAG\tests\magnifier\magnifier2.au3 - 1 error(s), 16 warning(s)

Script as I have it:

;#####################################################
#cs
Screen Magnifier, Pixel pos and Window info tool
all-in-one, by Siao
Usage:
    Main window resizeable
    Left click drags window
    Right click brings up options
    etc.
#ce
;#####################################################

#requireadmin
#include <GUIConstants.au3>

#NoTrayIcon
Opt("WinWaitDelay", 0)
Opt("GUICloseOnESC", 0)
Opt("GUIOnEventMode", 1)

Global Const $WM_MOVING = 0x0216
;~ Global Const $WM_SIZING = 0x0214
;cursors
Global Const $IDC_SIZEALL = 32646
Global Const $IDC_ARROW = 32512
;~ Global Const $WM_SETCURSOR  = 0x0020
;Drag constants
Global Const $HTCAPTION = 2
Global Const $WM_NCLBUTTONDOWN = 0xA1
;raster opcodes
;normal:
Global Const $SRCCOPY = 0xCC0020
Global Const $MERGECOPY = 0xC000CA
;inverted:
Global Const $NOTSRCCOPY = 0x330008
;text constants:
Global Const $DT_RIGHT = 0x2

Global $nZoomFactor = 2, $aMPosOld[2], $nTrans = 200
Global $iSleepTime = 90, $nTimer = 0, $bShowMini = 1, $bShowText = 1, $bAlwaysCenter = 0, $bInvert = 0, $bMouseUpdate = 1, $bSave = 0

;Main view GUI
$hGuiMain = GUICreate("Magnifier by Siao", 400, 300, -1, -1, _
                    BitOR($WS_POPUP,$WS_BORDER,$WS_SIZEBOX+$WS_CLIPCHILDREN), _
                    $WS_EX_TOPMOST _
                    );+$WS_EX_LAYERED+$WS_EX_TRANSPARENT

;Mini view GUI
$hGuiMini = GUICreate("Aimpoint 5x5", 128,128,400-130,0,$WS_CHILD+$WS_BORDER, -1, $hGuiMain)


;Options GUI
#Region ### START Koda GUI section ### Form=d:\miniprojects\autoit3\magnifier\guioptions.kxf
$hGuiOpt = GUICreate("Magnifier Options", 305, 230, -1, -1, BitOR($WS_SYSMENU,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS), -1, $hGuiMain)
$btnMin = GUICtrlCreateButton("Minimize", 5, 5, 145, 25, 0)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$btnQuit = GUICtrlCreateButton("Quit Program", 155, 5, 145, 25, 0)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$SliderTrans = GUICtrlCreateSlider(6, 54, 19, 165, BitOR($TBS_VERT,$TBS_AUTOTICKS))
GUICtrlSetCursor (-1, 11)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$grp1 = GUICtrlCreateGroup("View options", 60, 40, 235, 147)
$SliderZoom = GUICtrlCreateSlider(126, 60, 161, 19);, $TBS_AUTOTICKS)
GUICtrlSetLimit(-1, 100, 1)
GUICtrlSetData(-1, 2)
GUICtrlSetCursor (-1, 13)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$cbInvert = GUICtrlCreateCheckbox("Invert colors", 76, 90, 93, 21)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$cbCenter = GUICtrlCreateCheckbox("Always center", 76, 108, 93, 21)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$Label1 = GUICtrlCreateLabel("Zoom:", 74, 60, 50, 17)
$cbInfoPix = GUICtrlCreateCheckbox("Show pixel info", 182, 108, 93, 21)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$cbInfoWin = GUICtrlCreateCheckbox("Show win info", 182, 90, 93, 21)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$inTimer = GUICtrlCreateInput("", 192, 136, 37, 21, $ES_NUMBER)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$Label3 = GUICtrlCreateLabel("Update time (ms):", 106, 138, 86, 17)
$cbMouseUpdate = GUICtrlCreateCheckbox("Update only on mouse move", 104, 159, 161, 21)
GUICtrlSetOnEvent(-1, "OptionsEvents")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label2 = GUICtrlCreateLabel("Trans:", 6, 40, 34, 17)
$Label4 = GUICtrlCreateLabel("(c) Siao, 2007", 300, 226, 1, 1, BitOR($SS_CENTER,$SS_CENTERIMAGE,$WS_BORDER))
GUICtrlSetCursor (-1, 0)
$Label5 = GUICtrlCreateLabel("0", 30, 204, 10, 17)
$Label6 = GUICtrlCreateLabel("255", 30, 57, 22, 17)
$cbSave = GUICtrlCreateCheckbox("Remember options", 70, 194, 113, 30)
GUICtrlSetOnEvent(-1, "OptionsEvents")
$btnOK = GUICtrlCreateButton("OK", 198, 194, 87, 29, 0)
GUICtrlSetOnEvent(-1, "OptionsEvents")
GUISetState(@SW_DISABLE)
GUISetState(@SW_HIDE)
#EndRegion ### END Koda GUI section ###

_LoadOptions()
GUISwitch($hGuiMain)

GUISetOnEvent($GUI_EVENT_CLOSE, "SystemEvents")
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "SystemEvents")
GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "SystemEvents")

GUIRegisterMsg($WM_MOVING, "WindowEvents")
GUIRegisterMsg($WM_SIZING, "WindowEvents")

GUISetState()

;=== Main loop =========================================
While 1
    Sleep($iSleepTime)
    If BitAnd(WinGetState($hGuiMain), 16) Then ContinueLoop
    If BitAnd(WinGetState($hGuiOpt), 2) Then ContinueLoop
    _Zoom($nZoomFactor, _ZoomGetOptions())
WEnd
;========================================================

Func OptionsEvents()
    Switch @GUI_CtrlId
        Case $btnOK
            WinToggle(@GUI_WinHandle)
        Case $btnMin
            WinToggle(@GUI_WinHandle)
            GUISetState(@SW_MINIMIZE, $hGuiMain)
        Case $btnQuit
            _CloseProgram()
        Case $cbInvert
            $bInvert = BitXOR($bInvert, 1)
        Case $cbInfoPix
            $bShowMini =BitXOR($bShowMini, 1)
            WinToggle($hGuiMini)
        Case $cbInfoWin
            $bShowText = BitXOR($bShowText, 1)
        Case $cbCenter
            $bAlwaysCenter = BitXOR($bAlwaysCenter, 1)
        Case $SliderZoom
            $nZoomFactor = GUICtrlRead($SliderZoom)
            GUICtrlSetData($Label1, "Zoom: x" & $nZoomFactor)
        Case $SliderTrans
            $nTrans = 0-GUICtrlRead($SliderTrans)
            WinSetTrans($hGuiMain, "", $nTrans)
;~          GUICtrlSetTip($SliderTrans, $nTrans)
        Case $inTimer
            $iSleepTime = Int(GUICtrlRead($inTimer))
        Case $cbMouseUpdate
            $bMouseUpdate = BitXOR($bMouseUpdate, 1)
        Case $cbSave
            $bSave = BitXOR($bSave, 1)
            ;_SaveOptions()
    EndSwitch
EndFunc

Func WindowEvents($hWnd, $Msg, $wParam, $lParam)
    Switch $Msg
        Case $WM_MOVING
            ;zoom while moving
            If TimerDiff($nTimer) > $iSleepTime Then 
                _Zoom($nZoomFactor, _ZoomGetOptions())
                $nTimer = TimerInit()
            EndIf
        Case $WM_SIZING
            Local $tRECT = DllStructCreate("long; long; long; long", $lParam)
            $aTmp = WinGetPos($hGuiMini)
            DllCall("user32.dll", "int", "MoveWindow", "hwnd", $hGuiMini, _
                                    "int", DllStructGetData($tRECT, 3)-DllStructGetData($tRECT, 1)-$aTmp[2]-8, _
                                    "int", 0, _
                                    "int", $aTmp[2], "int", $aTmp[3], "int", False)
    EndSwitch
EndFunc

Func SystemEvents()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            _CloseProgram()
        Case $GUI_EVENT_PRIMARYDOWN
            _ChangeCursor($IDC_SIZEALL)
            Drag($hGuiMain)
        Case $GUI_EVENT_PRIMARYUP
            ;
        Case $GUI_EVENT_SECONDARYDOWN
            If Not BitAnd(WinGetState($hGuiOpt), 2) Then
                If Not IsDeclared("aMPosOld") Then Global $aMPosOld[2] = [0,0]
                ;Options gui size - 305,230
                WinMove($hGuiOpt, "", Min(Max($aMPosOld[0]-50, 0), @DesktopWidth-305), _
                                        Min(Max($aMPosOld[1]-50, 0), @DesktopHeight-230))
                WinToggle($hGuiOpt)
            EndIf
    EndSwitch
EndFunc

Func _CloseProgram()
    If BitAND(GUICtrlRead($cbSave), $GUI_CHECKED) Then 
        _SaveOptions()
    Else
        _ClearOptions()
    EndIf
    Exit
EndFunc

;by Zedna
Func Drag($h)
;~  dllcall("user32.dll","int","ReleaseCapture")
    DllCall("user32.dll","int","SendMessage","hWnd", $h,"int",$WM_NCLBUTTONDOWN,"int", $HTCAPTION,"int", 0)
EndFunc

Func WinToggle($hWin)
    If BitAND(WinGetState($hWin), 6) Then
        GUISetState(@SW_DISABLE, $hWin)
        GUISetState(@SW_HIDE, $hWin)
    Else
        GUISetState(@SW_ENABLE, $hWin)
        GUISetState(@SW_SHOW, $hWin)
    EndIf
EndFunc

Func _SaveOptions()
    $aPos = WinGetPos($hGuiMain)
    RegWrite("HKCU\SOFTWARE\SiaoSoft\Magnifier v1", "WindowPos", "REG_SZ", $aPos[0] & ";" & $aPos[1] & ";" & $aPos[2] & ";" & $aPos[3])
    $sOptions = $nTrans & ";" & $nZoomFactor & ";" & $bInvert & ";" & $bAlwaysCenter & ";" &  _
                $bShowText & ";" & $bShowMini & ";" & $iSleepTime & ";" & $bMouseUpdate & ";" & $bSave
    RegWrite("HKCU\SOFTWARE\SiaoSoft\Magnifier v1", "Options", "REG_SZ", $sOptions)
EndFunc
Func _LoadOptions()
    $aWinPos = StringSplit(RegRead("HKCU\SOFTWARE\SiaoSoft\Magnifier v1", "WindowPos"), ";")
    If $aWinPos[0] = 4 Then
        WinMove($hGuiMain, "", Int($aWinPos[1]), Int($aWinPos[2]), Int($aWinPos[3]), Int($aWinPos[4]))
        $aTmp = WinGetPos($hGuiMini)
        WinMove($hGuiMini, "", Int($aWinPos[3])-$aTmp[2]-8, 0)
    EndIf
    $aOpts = StringSplit(RegRead("HKCU\SOFTWARE\SiaoSoft\Magnifier v1", "Options"), ";")    
    If $aOpts[0] = 9 Then
        $nTrans = Int($aOpts[1])
        $nZoomFactor = Int($aOpts[2])
        $bInvert = Int($aOpts[3])
        $bAlwaysCenter = Int($aOpts[4])
        $bShowText = Int($aOpts[5])
        $bShowMini = Int($aOpts[6])
        $iSleepTime = Int($aOpts[7])
        $bMouseUpdate = Int($aOpts[8])
        $bSave = Int($aOpts[9])
    EndIf
    If $bShowMini Then GUICtrlSetState($cbInfoPix, $GUI_CHECKED)
    If $bShowText Then GUICtrlSetState($cbInfoWin, $GUI_CHECKED)
    If $bMouseUpdate Then GUICtrlSetState($cbMouseUpdate, $GUI_CHECKED)
    If $bInvert Then GUICtrlSetState($cbInvert, $GUI_CHECKED)
    If $bAlwaysCenter Then GUICtrlSetState($cbCenter, $GUI_CHECKED)
    If $bSave Then GUICtrlSetState($cbSave, $GUI_CHECKED)
    GUICtrlSetLimit($SliderZoom, 10, 1)
    GUICtrlSetLimit($SliderTrans, 0, -255)
    DllCall("user32.dll","int","SendMessage","hWnd", ControlGetHandle($hGuiOpt, "", $SliderZoom),"int",$TBM_SETTICFREQ,"int", 1,"int", 0)
    DllCall("user32.dll","int","SendMessage","hWnd", ControlGetHandle($hGuiOpt, "", $SliderTrans),"int",$TBM_SETTICFREQ,"int", 16,"int", 0)
    GUICtrlSetData($SliderZoom, $nZoomFactor)
    GUICtrlSetData($Label1, "Zoom: x" & $nZoomFactor)
    GUICtrlSetData($SliderTrans, 0-$nTrans)
    GUICtrlSetData($inTimer, $iSleepTime)
    WinSetTrans($hGuiMain, "", $nTrans)
    GUICtrlSetState($btnOK, $GUI_FOCUS)
    If $bShowMini Then GUISetState(@SW_SHOW, $hGuiMini)
EndFunc
Func _ClearOptions()
    $sRegRoot = "HKCU\SOFTWARE\SiaoSoft"
    RegDelete($sRegRoot & "\Magnifier v1")
    RegEnumKey($sRegRoot, 1)
    $err = @error
    RegEnumVal($sRegRoot, 1)
    If @error <> 0 And $err <> 0 Then RegDelete($sRegRoot)
EndFunc

Func _ChangeCursor($lpCursorName = 0)
    If $lpCursorName <> 0 Then
        $aRet = DllCall("user32.dll","long","LoadCursor","long",0,"long",$lpCursorName)
        $hCurs = $aRet[0]
    Else
        $hCurs = 0
    EndIf
    $aRet = DllCall("user32.dll","long","SetCursor","hwnd",$hCurs)
    Return $aRet[0]
EndFunc

Func _ZoomGetOptions()
    $nOptions = 0
    If $bShowMini Then $nOptions += 1
    If $bShowText Then $nOptions += 2
    If $bMouseUpdate Then $nOptions += 4
    If $bAlwaysCenter Then $nOptions += 8
    If $bInvert Then $nOptions += 16
    Return $nOptions
EndFunc

Func _Zoom($zf, $dwOptions)
;===============================================================================
; Parameter(s):     $zf - zoom factor
;                   $dwOptions - Can be a combination of the following:
;                       1 = Show mini window
;                       2 = Show window info
;                       4 = Update on mouse move only
;                       8 = Always center view (on screen edges)
;                       16 = Invert colors
;===============================================================================
    Local $aMPos, $aMainSize, $aMiniSize, $aMyMainDC, $aMyMiniDC, $aScreenDC, $aPen, $aPenOld, $aMiniFont, $aMiniFontOld
    Local $tRECT, $srcW, $srcH, $srcX, $srcY, $sPixel, $sWinInfo
    
    $aMPos = MouseGetPos()
    If Not IsDeclared("aMPosOld") Then Global $aMPosOld[2] = [0,0]
    If BitAND($dwOptions, 4) And $aMPos[0] = $aMPosOld[0] And $aMPos[1] = $aMPosOld[1] Then Return
    $aMPosOld = $aMPos
    $aMainSize = WinGetClientSize($hGuiMain)
    $aMiniSize = WinGetClientSize($hGuiMini)
    $aMyMainDC = DLLCall("user32.dll","int","GetDC","hwnd",$hGuiMain)
    $aMyMiniDC = DLLCall("user32.dll","int","GetDC","hwnd",$hGuiMini)
    $aScreenDC = DLLCall("user32.dll","int","GetDC","hwnd",0)
    $tRECT = DllStructCreate("long; long; long; long")

    $srcW = $aMainSize[0] / $zf
    $srcH = $aMainSize[1] / $zf
    If BitAND($dwOptions, 8) Then
        $srcX = $aMPos[0] - $aMainSize[0] / (2 * $zf)
        $srcY = $aMPos[1] - $aMainSize[1] / (2 * $zf)
        $dwRop = $MERGECOPY
    Else
        $srcX = Min(Max($aMPos[0] - $aMainSize[0] / (2 * $zf), 0), @DesktopWidth-$srcW)
        $srcY = Min(Max($aMPos[1] - $aMainSize[1] / (2 * $zf), 0), @DesktopHeight-$srcH)
        $dwRop = $SRCCOPY
    EndIf

    If BitAND($dwOptions, 16) Then $dwRop = $NOTSRCCOPY

    DLLCall("gdi32.dll","int","StretchBlt", _
        "int",$aMyMainDC[0],"int", 0,"int",0,"int",$aMainSize[0],"int",$aMainSize[1], _
        "int",$aScreenDC[0],"int", $srcX,"int",$srcY,"int",$srcW,"int",$srcH, _
        "long", $dwRop)
                
    If BitAND($dwOptions, 1) Then
        ; strech 5x5 area around cursor into Mini gui
        DLLCall("gdi32.dll","int","StretchBlt", _
            "int",$aMyMiniDC[0],"int", 0,"int",0,"int",$aMiniSize[0],"int",$aMiniSize[1], _
            "int",$aScreenDC[0],"int", $aMPos[0]-2,"int",$aMPos[1]-2,"int",5,"int",5, _
            "long", $dwRop)
        ;draw crosshair on top of it
        DLLCall("gdi32.dll","int","Arc", "hwnd", $aMyMiniDC[0], _
                            "int", 0, "int", 0, "int", $aMiniSize[0], "int", $aMiniSize[1], _
                            "int", 0, "int", $aMiniSize[1]/2, "int", 0, "int", $aMiniSize[1]/2)
        $aPen = DLLCall("gdi32.dll","hwnd","CreatePen", "int", 3, "int", 0, "int", 0x00000000)
        $aPenOld = DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $aMyMiniDC[0], "hwnd", $aPen[0])
        DLLCall("gdi32.dll","int","MoveToEx", "hwnd", $aMyMiniDC[0], "int", 0, "int", $aMiniSize[1]/2, "ptr", 0)
        DLLCall("gdi32.dll","int","LineTo", "hwnd", $aMyMiniDC[0], "int", $aMiniSize[0], "int", $aMiniSize[1]/2)
        DLLCall("gdi32.dll","int","MoveToEx", "hwnd", $aMyMiniDC[0], "int", $aMiniSize[0]/2, "int", 0, "ptr", 0)
        DLLCall("gdi32.dll","int","LineTo", "hwnd", $aMyMiniDC[0], "int", $aMiniSize[0]/2, "int", $aMiniSize[1])
        ;draw pixel color/pos text
        DllStructSetData($tRECT, 1, 0)
        DllStructSetData($tRECT, 2, 0)
        DllStructSetData($tRECT, 3, $aMiniSize[0])
        DllStructSetData($tRECT, 4, 14)     
        $aMiniFont = DLLCall("gdi32.dll","int","CreateFont", "int", 14, "int", 0, "int", 0, "int", 0, "int", 700, _
                                "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, "dword", 0, _
                                "dword", 0, "str", "")
        $aMiniFontOld = DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $aMyMiniDC[0], "hwnd", $aMiniFont[0])
        $sPixel = " 0x" & Hex(PixelGetColor($aMPos[0],$aMPos[1]),6) & " at " & $aMPos[0] & "," & $aMPos[1] & "               "
        DLLCall("user32.dll","int","DrawText", "hwnd", $aMyMiniDC[0], _
                            "str", $sPixel, "int", StringLen($sPixel), "ptr", DllStructGetPtr($tRECT), "uint", 0)
        DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $aMyMiniDC[0], "hwnd", $aMiniFontOld[0])
        DLLCall("gdi32.dll","int","DeleteObject", "hwnd", $aMiniFont[0])
        DLLCall("gdi32.dll","hwnd","SelectObject", "hwnd", $aMyMiniDC[0], "hwnd", $aPenOld[0])
        DLLCall("gdi32.dll","int","DeleteObject", "hwnd", $aPen[0])
    EndIf
    
    If BitAND($dwOptions, 2) Then
        ;get and show window/control info
        $sWinInfo = _WinInfoFromPoint($aMPos[0], $aMPos[1]) 
        DllStructSetData($tRECT, 1, 0)
        DllStructSetData($tRECT, 2, $aMainSize[1]-48)
        DllStructSetData($tRECT, 3, $aMainSize[0])
        DllStructSetData($tRECT, 4, $aMainSize[1])
        DLLCall("user32.dll","int","DrawText", "hwnd", $aMyMainDC[0], _
                            "str", $sWinInfo, "int", StringLen($sWinInfo), "ptr", DllStructGetPtr($tRECT), "uint", $DT_RIGHT)
    EndIf

    DLLCall("user32.dll","int","ReleaseDC","hwnd",0,"hwnd",$aScreenDC[0])
    DLLCall("user32.dll","int","ReleaseDC","hwnd",$hGuiMain,"hwnd",$aMyMainDC[0])
    DLLCall("user32.dll","int","ReleaseDC","hwnd",$hGuiMini,"hwnd",$aMyMiniDC[0])

EndFunc

;Gets window/control info from cursor pos, returns formatted string
Func _WinInfoFromPoint($nX, $nY)
    Local $tStrBuff, $pStrBuff, $aRet, $hWnd, $hOwnerWnd, $sClassName, $sOwnerClass, $sWinText
    $tStrBuff = DllStructCreate("char[100]")
    $pStrBuff = DllStructGetPtr($tStrBuff)
    $aRet = DllCall("user32.dll", "hwnd", "WindowFromPoint", "uint", $nX, "uint", $nY)
    $hWnd = $aRet[0]
    $aRet = DllCall("user32.dll", "int", "GetClassName", "hwnd", $hWnd, "ptr", $pStrBuff, "int", 100)
    $sClassName = DllStructGetData($tStrBuff, 1)
    DllStructSetData($tStrBuff, 1, "")
    DllCall("user32.dll", "int", "GetWindowText", "hwnd", $hWnd, "ptr", $pStrBuff, "int", 100)
;~  DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "uint", $WM_GETTEXT, "uint", 100, "ptr", $pStrBuff)
    $sWinText = DllStructGetData($tStrBuff, 1)
    DllStructSetData($tStrBuff, 1, "")  
    $aRet = DllCall("user32.dll", "hwnd", "GetAncestor", "hwnd", $hWnd, "uint", 2) ;$GA_ROOT = 2
    $hOwnerWnd = $aRet[0]
    $aRet = DllCall("user32.dll", "int", "GetClassName", "hwnd", $hOwnerWnd, "ptr", $pStrBuff, "int", 100)
    $sOwnerClass = DllStructGetData($tStrBuff, 1)
    DllStructSetData($tStrBuff, 1, "")

    Return $sWinText & @CRLF & "[ Class: " & $sClassName & "; hWnd: " & $hWnd & " ]" & @CRLF & _
                        "( Owner: " & $sOwnerClass & "; " & $hOwnerWnd & " )"
EndFunc

Func Min($n1, $n2)
    If $n1 < $n2 Then Return $n1
    Return $n2
EndFunc
Func Max($n1, $n2)
    If $n1 > $n2 Then Return $n1
    Return $n2
EndFunc

;================
Link to comment
Share on other sites

Link to comment
Share on other sites

@tom13

Replace the top of the script with this :

;#####################################################
#cs
Screen Magnifier, Pixel pos and Window info tool
all-in-one, by Siao
Usage:
    Main window resizeable
    Left click drags window
    Right click brings up options
    etc.
#ce
;#####################################################
#NoTrayIcon
#include<Constants.au3>
#include<EditConstants.au3>
#include<GUIConstantsEx.au3>
#include<SliderConstants.au3>
#include<StaticConstants.au3>
#include<WindowsConstants.au3>

Opt("WinWaitDelay", 0)
Opt("GUICloseOnESC", 0)
Opt("GUIOnEventMode", 1)

Global Const $WM_MOVING = 0x0216
;~ Global Const $WM_SIZING = 0x0214
;cursors
;Global Const $IDC_SIZEALL = 32646
;Global Const $IDC_ARROW = 32512
;~ Global Const $WM_SETCURSOR  = 0x0020
;Drag constants
;Global Const $HTCAPTION = 2
;Global Const $WM_NCLBUTTONDOWN = 0xA1
;raster opcodes
;normal:
;Global Const $SRCCOPY = 0xCC0020
;Global Const $MERGECOPY = 0xC000CA
;inverted:
;Global Const $NOTSRCCOPY = 0x330008
;text constants:
;Global Const $DT_RIGHT = 0x2

Global $nZoomFactor = 2, $aMPosOld[2], $nTrans = 200
Global $iSleepTime = 90, $nTimer = 0, $bShowMini = 1, $bShowText = 1, $bAlwaysCenter = 0, $bInvert = 0, $bMouseUpdate = 1, $bSave = 0

Enjoy !!

Regards,

ptrex

Link to comment
Share on other sites

  • 8 months later...
  • 1 year later...

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...