Jump to content

Zoom tool editing


Recommended Posts

**edit**

I should mention 'z' key to toggle zoom on/off

'esc' key to exit

**end edit**

#include <Misc.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPIEx.au3>

$dll = DllOpen("user32.dll")
Global $hParent, $hForm, $Pos, $hBitmap = 0, $Go = 1, $XPrev = MouseGetPos(0), $YPrev = MouseGetPos(1)
Global $hDC, $hMemDC, $hSv, $pBlend, $tBlend, $pSize, $tSize, $pSource, $tSource, $hWnd
Global $scope = 0

$hParent = GUICreate('', -1, -1, -1, -1, -1, $WS_EX_TOOLWINDOW)
$hForm = GUICreate('', 100, 100, $XPrev + 25, $YPrev + 25, BitOR($WS_DISABLED, $WS_POPUPWINDOW), BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST), $hParent)
GUISetState(@SW_HIDE, $hForm)

While 1

    If _IsPressed("1B", $dll) Then
        DllClose($dll)
        Exit (1)
    EndIf

    If _IsPressed("5A", $dll) And $scope = 0 Then
        $scope = 1
        Sleep(500)
    EndIf

    If _IsPressed("5A", $dll) And $scope = 1 Then
        $scope = 0
        GUISetState(@SW_HIDE, $hForm)
        Sleep(500)
    EndIf

    If $scope = 1 Then

        GUISetState(@SW_SHOWNOACTIVATE, $hForm)

        $Pos = MouseGetPos()
        If ($Go) Or ($Pos[0] <> $XPrev) Or ($Pos[1] <> $YPrev) Then
            WinMove($hForm, '', $Pos[0] - 50, $Pos[1] - 50)
            _Capture($Pos[0] - 25, $Pos[1] - 25, 50, 50)
            $XPrev = $Pos[0]
            $YPrev = $Pos[1]
            $Go = 0
        EndIf

    EndIf

WEnd

Func _Capture($iX, $iY, $iWidth, $iHeight)

    Local $tRect, $hDC, $hMemDC, $hScreenshort = _ScreenCapture($iX, $iY, $iWidth, $iHeight)

    _WinAPI_FreeObject($hBitmap)
    $hBitmap = _WinAPI_FitToBitmap($hScreenshort, 100, 100)
    _WinAPI_FreeObject($hScreenshort)
    $hDC = _WinAPI_GetDC($hForm)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    _WinAPI_SelectObject($hMemDC, $hBitmap)
    _WinAPI_SelectObject($hMemDC, _WinAPI_GetStockObject($NULL_BRUSH))
    _WinAPI_SelectObject($hMemDC, _WinAPI_GetStockObject($DC_PEN))
    _WinAPI_SetDCPenColor($hMemDC, 0xA00000)
    $tRect = _WinAPI_CreateRoundRectRgn(0, 0, 100, 100, 25, 25);tried changing this line to make the square a circle
    ; _WinAPI_Rectangle($hMemDC, $tRect)
    _WinAPI_ReleaseDC($hForm, $hDC)
    _WinAPI_DeleteDC($hMemDC)
    _SetBitmap($hForm, $hBitmap, 255)
EndFunc   ;==>_Capture

Func _ScreenCapture($iX, $iY, $iWidth, $iHeight)

    Local $hWnd, $hDC, $hMemDC, $hBitmap

    $hWnd = _WinAPI_GetDesktopWindow()
    $hDC = _WinAPI_GetDC($hWnd)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
    _WinAPI_SelectObject($hMemDC, $hBitmap)
    _WinAPI_BitBlt($hMemDC, 0, 0, $iWidth, $iHeight, $hDC, $iX, $iY, $MERGECOPY)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_DeleteDC($hMemDC)
    Return $hBitmap
EndFunc   ;==>_ScreenCapture

Func _SetBitmap($hWnd, $hBitmap, $iOpacity)

    $hDC = _WinAPI_GetDC($hWnd)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    $hSv = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = _WinAPI_GetBitmapDimension($hBitmap)
    $pSize = DllStructGetPtr($tSize)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, 'Alpha', $iOpacity)
    DllStructSetData($tBlend, 'Format', 0)
    _WinAPI_UpdateLayeredWindow($hWnd, $hDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_SelectObject($hMemDC, $hSv)
    _WinAPI_DeleteDC($hMemDC)
EndFunc   ;==>_SetBitmap

what I would like to do is change the box from a square to a circle, outline it and add crosshairs through it. (to make it look like a scope)

I know to do the crosshairs I should use GDI plus, but since this is a slightly modified version of someone elses zoom, I don't know where to put it and also I've not worked with GDI plus yet. (just a pointer as to where the line code goes would be great!)

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

I've tried adding a _GDIPlus_GraphicsDrawLine, guictrlsetimage, guictrlcreatepic (I created a crosshair bmp in case that would be easier) at lines 64, 80 and 99 using all the variables I could think of in the script that looked like they were setting the zoomed image but the crosshairs never showed :D

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

ok, I've got the + to draw through the zoom for crosshairs, got the clickthrough to work on the zoom so you can click on stuff but I just cannot get a circle drawn around the + :D

#include <Misc.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPIEx.au3>

$dll = DllOpen("user32.dll")
Global $hParent, $hForm, $Pos, $hBitmap = 0, $Go = 1, $XPrev = MouseGetPos(0), $YPrev = MouseGetPos(1)
Global $hDC, $hMemDC, $hSv, $pBlend, $tBlend, $pSize, $tSize, $pSource, $tSource, $hWnd,$iX,$iY,$iHeight
Global $scope = 0
;$Cursor="H:\Shawns_Stuff\Terisi_PF\data\cross_l.cur"
;$CursorBack = 'H:\Shawns_Stuff\Terisi_PF\data\arrow_m.cur'

$hParent = GUICreate('', -1, -1, -1, -1, -1, BitOR($WS_EX_LAYERED,$WS_EX_TOOLWINDOW,$WS_EX_TRANSPARENT ))
$hForm = GUICreate('', 150, 150, $XPrev + 25, $YPrev + 25, BitOR($WS_DISABLED, $WS_POPUPWINDOW), BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST,$WS_EX_TRANSPARENT ), $hParent)
GUISetState(@SW_HIDE, $hForm)

While 1

    If _IsPressed("1B", $dll) Then
        DllClose($dll)
        Exit (1)
    EndIf

    If _IsPressed("5A", $dll) And $scope = 0 Then
        ;$cDll = DllCall($dll, "hwnd", "LoadCursorFromFile", "str", $Cursor)
        ;DllCall($dll, "int", "SetSystemCursor", "int", $cDll[0], "int", 32512)
        $scope = 1
        Sleep(500)
    EndIf

    If _IsPressed("5A", $dll) And $scope = 1 Then
        ;$cDll = DllCall($dll, "hwnd", "LoadCursorFromFile", "str", $CursorBack)
        ;DllCall($dll, "int", "SetSystemCursor", "int", $cDll[0], "int", 32512)
        $scope = 0
        GUISetState(@SW_HIDE, $hForm)
        Sleep(500)
    EndIf

    If $scope = 1 Then

        GUISetState(@SW_SHOWNOACTIVATE, $hForm)

        $Pos = MouseGetPos()
        If ($Go) Or ($Pos[0] <> $XPrev) Or ($Pos[1] <> $YPrev) Then
            WinMove($hForm, '', $Pos[0] - 75, $Pos[1] - 75)
            _Capture($Pos[0] - 25, $Pos[1] - 25, 50, 50)
            $XPrev = $Pos[0]
            $YPrev = $Pos[1]
            $Go = 0
        EndIf
        _Capture($Pos[0] - 25, $Pos[1] - 25, 50, 50)
    EndIf

WEnd

Func _Capture($iX, $iY, $iWidth, $iHeight)

    Local $tRect, $hDC, $hMemDC, $hScreenshort = _ScreenCapture($iX, $iY, $iWidth, $iHeight)
    _WinAPI_FreeObject($hBitmap)
    $hBitmap = _WinAPI_FitToBitmap($hScreenshort, 150, 150)
    _WinAPI_FreeObject($hScreenshort)
    $hDC = _WinAPI_GetDC($hForm)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    _WinAPI_SelectObject($hMemDC, $hBitmap)
    _WinAPI_SelectObject($hMemDC, _WinAPI_GetStockObject($NULL_BRUSH))
    _WinAPI_SelectObject($hMemDC, _WinAPI_GetStockObject($DC_PEN))
    _WinAPI_SetDCPenColor($hMemDC, 0xA00000)
    _WinAPI_DrawLine($hMemDC, 150, 75, -150, 75)
    _WinAPI_DrawLine($hMemDC, 75, 150, 75, -150)
    _WinAPI_ReleaseDC($hForm, $hDC)
    _WinAPI_DeleteDC($hMemDC)
    _SetBitmap($hForm, $hBitmap, 254)
EndFunc   ;==>_Capture

Func _ScreenCapture($iX, $iY, $iWidth, $iHeight)

    Local $hWnd, $hDC, $hMemDC, $hBitmap

    $hWnd = _WinAPI_GetDesktopWindow()
    $hDC = _WinAPI_GetDC($hWnd)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
    _WinAPI_SelectObject($hMemDC, $hBitmap)
    _WinAPI_BitBlt($hMemDC, 0, 0, $iWidth, $iHeight, $hDC, $iX, $iY, $MERGECOPY)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_DeleteDC($hMemDC)
    Return $hBitmap
EndFunc   ;==>_ScreenCapture

Func _SetBitmap($hWnd, $hBitmap, $iOpacity)

    $hDC = _WinAPI_GetDC($hWnd)
    $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    $hSv = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = _WinAPI_GetBitmapDimension($hBitmap)
    $pSize = DllStructGetPtr($tSize)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, 'Alpha', $iOpacity)
    DllStructSetData($tBlend, 'Format', 0)
    _WinAPI_UpdateLayeredWindow($hWnd, $hDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    _WinAPI_SelectObject($hMemDC, $hSv)
    _WinAPI_DeleteDC($hMemDC)
EndFunc   ;==>_SetBitmap

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

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