Jump to content

Yet another... screen magnifier and info tool


Siao
 Share

Recommended Posts

#include <GUIConstants.au3>
#Include <WindowsConstants.au3>
#Include <GuiSlider.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#NoTrayIcon
Opt("WinWaitDelay", 0)
Opt("GUICloseOnESC", 0)
Opt("GUIOnEventMode", 1)
Global Const $WM_MOVING = 0x0216
;cursors
Global Const $IDC_SIZEALL = 32646
Global Const $IDC_ARROW = 32512
Global $nZoomFactor = 2, $aMPosOld[2], $nTrans = 255
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:miniprojectsautoit3magnifierguioptions.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("HKCUSOFTWARESiaoSoftMagnifier v1", "WindowPos", "REG_SZ", $aPos[0] & ";" & $aPos[1] & ";" & $aPos[2] & ";" & $aPos[3])
    $sOptions = $nTrans & ";" & $nZoomFactor & ";" & $bInvert & ";" & $bAlwaysCenter & ";" &  _
                $bShowText & ";" & $bShowMini & ";" & $iSleepTime & ";" & $bMouseUpdate & ";" & $bSave
    RegWrite("HKCUSOFTWARESiaoSoftMagnifier v1", "Options", "REG_SZ", $sOptions)
EndFunc
Func _LoadOptions()
    $aWinPos = StringSplit(RegRead("HKCUSOFTWARESiaoSoftMagnifier 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("HKCUSOFTWARESiaoSoftMagnifier 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 = "HKCUSOFTWARESiaoSoft"
    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, $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
        $srcDC = _WinAPI_GetDC(0)
        $trgDC = _WinAPI_CreateCompatibleDC($srcDC)
        $hBitmap = _WinAPI_CreateCompatibleBitmap($srcDC, $srcW, $srcH)
        $old = _WinAPI_SelectObject($trgDC, $hBitmap)
        ;select area copy
        _WinAPI_BitBlt($trgDC, 0, 0, $srcW, $srcH, $srcDC, $srcX, $srcY, BitOR($SRCCOPY, 0x40000000))
        DLLCall("gdi32.dll","int","StretchBlt", _
        "int",$aMyMainDC[0],"int", 0,"int",0,"int",$aMainSize[0],"int",$aMainSize[1], _
        "int",$trgDC, "int", 0, "int", 0, "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",$trgDC,"int", $srcW/2,"int",$srcH/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(GetPixelColor($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

        _WinAPI_SelectObject($trgDC, $old)
        _WinAPI_DeleteObject($hBitmap)
        _WinAPI_DeleteDC($trgDC)
        _WinAPI_ReleaseDC(0, $srcDC)

    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
Func GetPixelColor($x, $y)
Local $col
$Width = 1
$Height = 1
$srcDC = _WinAPI_GetDC(0)
$trgDC = _WinAPI_CreateCompatibleDC($srcDC)
$hBitmap = _WinAPI_CreateCompatibleBitmap($srcDC, $Width, $Height)
$old = _WinAPI_SelectObject($trgDC, $hBitmap)
;select copy
_WinAPI_BitBlt($trgDC, 0, 0, $Width, $Height, $srcDC, $x, $y, BitOR($SRCCOPY, 0x40000000))
;copy area  (0, 0) get pixecolor.
$col = DllCall("gdi32.dll", "int", "GetPixel", "int", $trgDC, "int", 0, "int", 0)
$col[0] = BitOR(BitShift(BitAND($col[0], 0xFF), -16), BitAND($col[0], 0xFF00), BitShift(BitAND($col[0], 0xFF0000), 16))
_WinAPI_SelectObject($trgDC, $old)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteDC($trgDC)
_WinAPI_ReleaseDC(0, $srcDC)
Return $col[0]
EndFunc

Posted Image

Have modified the structure of the code,

Is very good.

this code editor by [하늘빛]

thanks [하늘빛]

Edited by davidkim

I interest am many quite in AutoitScript.From that is [http://cafe.naver.com/autoitscript[/color]] Korea of cafe(blog) to be operating, [size="2"][color="#ff00ff"]English cannot well[/size].Many help it requests.To read, it stands it thanks.

Link to comment
Share on other sites

  • 5 years later...

 An oldie, but a goodie.

This is a modified version of Siao's script of post #1 for easy download and run/compile.

Changes made in this copy are:-
  - Commenting out the Global Const lines that are already been declared;
  - Added $iScale, for use when Desktop (right mouse click) > "Display settings" > "Scale and Layout" is other than 100%.
  - Added arrow keys movement.  (When scale is not 100%, pixel movement is not always one pixel at a time.)
  - Add colour and position of pixel to clipboard when Ctrl-c is pressed.

I liked using this pixel viewer (magnifier) until it stopped being accurate on my new laptop with a desktop display scale of 125%.
The thread in AutoIt Example Scripts Forum  which is also inaccurate because my desktop scale is not 100%, motivated me to resurrect Siao's magnifier.

Spoiler

On my laptop (OS:WIN_10 Running:(3.3.14.5)), under the system's 'Display Settings' (Right mouse click on desktop), the 'Scale and Layout' has the size as 125% (Recommended). And the 'Display Resolution' is 1920 x 1080 (Recommended). The actual desktop size (as returned from @DesktopWidth and @DesktopHeight) is 1536 x 864 because of the 125% scale.

Now MouseGetPos() function returns the actual position of the mouse, or, 125% of the Display Resolution.
The PixelGetColor() function  returns the colour from 100% of the Display Resolution.
The scaled X, Y mouse position values needed to be multiplied by the scale value in order for the mouse to appear in the correct position on the 100% sized desktop.

Should the 'Scale and Layout' setting value be 100%, then the scale value will be 1.  So, the X, Y mouse position values multiplied by the scale value, 1, will be the same position on the 100% sized desktop.  So, the use of this scale value only becomes important when the desktop scale is not 100%.

;#####################################################
#cs
Screen Magnifier, Pixel pos and Window info tool
all-in-one, by Siao
Usage:
    Main window resizeable
    Left click drags window
    Right mouse click on GUI brings up options.    <----------------- Note well <---------
    etc.
Modified:
Malkey - Added $iScale, for use when on clear Desktop
         (right mouse click) > "Display settings" >
         "Scale and Layout" is other than 100%.
       - Added arrow keys movement. When scale is not 100%,
         pixel movement is not always one pixel at a time.
       - Added colour and position of pixel to clipboard
         when Ctrl-c is pressed.
        See -  https://www.autoitscript.com/forum/topic/54776-yet-another-screen-magnifier-and-info-tool/?do=findComment&comment=1361170
#ce
;##########################################################

#include <GUIConstants.au3>
#include <WinAPIGdi.au3>; Added
#include <Misc.au3>; Added

#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

HotKeySet("^c", "HotKeyCopy") ; Control c

Global $iScale = _WinAPI_EnumDisplaySettings('', $ENUM_CURRENT_SETTINGS)[0] / @DesktopWidth ; Added
Global $iXMove = 0, $iYMove = 0, $sPixel
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

    If _IsPressed("26") Then ; UP ARROW key
        While _IsPressed("26")
        WEnd
        $iXMove = 0.00
        $iYMove = -1.00
    ElseIf _IsPressed("28") Then ; DOWN ARROW key
        While _IsPressed("28")
        WEnd
        $iXMove = 0.00
        $iYMove = 1.00
    ElseIf _IsPressed("25") Then     ; LEFT ARROW key
        While _IsPressed("25")
        WEnd
        $iXMove = -1.00
        $iYMove = 0.00
    ElseIf _IsPressed("27") Then ; RIGHT ARROW key
        While _IsPressed("27")
        WEnd
        $iXMove = 1.00
        $iYMove = 0.00
    Else
        $iXMove = 0.00
        $iYMove = 0.00
    EndIf
    _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   ;==>OptionsEvents

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   ;==>WindowEvents

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   ;==>SystemEvents

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

;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   ;==>Drag

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   ;==>WinToggle

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   ;==>_SaveOptions

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   ;==>_LoadOptions

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   ;==>_ClearOptions

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   ;==>_ChangeCursor

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   ;==>_ZoomGetOptions

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, $sWinInfo

    $aMPos = MouseGetPos()
    If $iXMove Or $iYMove Then
        MouseMove(Int($aMPos[0] + ($iXMove * $iScale)), Int($aMPos[1] + ($iYMove * $iScale)), 0)
        $aMPos = MouseGetPos()
    EndIf
    $aMPos[0] = Int($aMPos[0] * $iScale) ; Added
    $aMPos[1] = Int($aMPos[1] * $iScale)  ; Added
    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])

        $aPenOld = DllCall("gdi32.dll", "hwnd", "SelectObject", "hwnd", $aMyMainDC[0], "hwnd", $aPen[0])
        DllCall("gdi32.dll", "int", "MoveToEx", "hwnd", $aMyMainDC[0], "int", 0, "int", $aMainSize[1] / 2, "ptr", 0)
        DllCall("gdi32.dll", "int", "LineTo", "hwnd", $aMyMainDC[0], "int", $aMainSize[0], "int", $aMainSize[1] / 2)
        DllCall("gdi32.dll", "int", "MoveToEx", "hwnd", $aMyMainDC[0], "int", $aMainSize[0] / 2, "int", 0, "ptr", 0)
        DllCall("gdi32.dll", "int", "LineTo", "hwnd", $aMyMainDC[0], "int", $aMainSize[0] / 2, "int", $aMainSize[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   ;==>_Zoom

;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   ;==>_WinInfoFromPoint

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

Func Max($n1, $n2)
    If $n1 > $n2 Then Return $n1
    Return $n2
EndFunc   ;==>Max

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

Func HotKeyCopy()
    ClipPut($sPixel)
EndFunc   ;==>HotKeyCopy

 

Edited by Malkey
Link to comment
Share on other sites

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