Jump to content

Help with GDI brush pen please


Recommended Posts

I pulled this slighty modified code here on this forum but not sure what parameters to change in order to get the cross drawn rather then just the dot.

I stripped unwanted parts leaving just enough for it to run.

Can someone look at it and help me with drawing the cross ?

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>

Global $TargetWindow = ""
Global $BrushColor = 0x0000FF
Global $BrushWidth = "10"
While 1
    SetPixel()
WEnd

Func SetPixel()

    $Mpos = WinGetPos($TargetWindow)

    $Mpos_x = $Mpos[0] + $Mpos[2]/2 ;X my own center coordinates
    $Mpos_y = $Mpos[1] + $Mpos[3]/2+10  ;Y my own center coordinates

    $hd = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)
    $pen = DllCall("GDI32.dll", "int", "CreatePen", "int", 0, "int", $BrushWidth, "int", $BrushColor)
    $old_pen = DllCall("GDI32.dll", "int", "SelectObject", "int", $hd[0], "int", $pen[0])
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int", $Mpos_x, "int", $Mpos_y, "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $Mpos_x, "int", $Mpos_y)
    DllCall("GDI32.dll", "int", "SelectObject", "int", $hd[0], "int", $old_pen[0]) ;Need to select original object back into DC
    DllCall("GDI32.dll", "int", "DeleteObject", "int", $pen[0]) ;Need To delete the created object
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $hd[0])
    $Mpos_x = 0
    $Mpos_y = 0
    $Mpos = 0

EndFunc

 

Edited by tonycst
Link to comment
Share on other sites

The script below is based on one by Melba23 to make a magnifier
Please look at the crosshair part

; http://www.autoitscript.com/forum/topic/150136-window-zoom-out-tool/#entry1071721

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPIGdi.au3>
#include <Misc.au3>

Opt("GUICloseOnESC", 0)
HotKeySet("{ESC}", "On_Exit")

Global $hMag_GUI, $hMagDC, $hDeskDC, $hPen, $oObj, $aMouse_Pos[2], $iLast_Mouse_X = 0, $iLast_Mouse_Y = 0, $zoom = 3

$hMag_Win = GUICreate("MAG", 100, 100, 0, 0, $WS_POPUP+$WS_BORDER, $WS_EX_TOPMOST)
GUISetState(@SW_SHOW, $hMag_Win)
$hMag_GUI = WinGetHandle("MAG")
$hMagDC = _WinAPI_GetDC($hMag_GUI)
$hDeskDC = _WinAPI_GetDC(0)
$hPen = _WinAPI_CreatePen($PS_SOLID, 1, 0x000000)
$oObj = _WinAPI_SelectObject($hMagDC, $hPen)


While 1
    $aMouse_Pos = MouseGetPos()
    If $aMouse_Pos[0] <> $iLast_Mouse_X Or $aMouse_Pos[1] <> $iLast_Mouse_Y Then
        Loupe($aMouse_Pos)
        $iLast_Mouse_X = $aMouse_Pos[0]
        $iLast_Mouse_Y = $aMouse_Pos[1]
    EndIf
    If _IsPressed("11") Then
       For $i = 31 to 39
           If _IsPressed($i) Then $zoom = $i-30
       Next
       For $i = 61 to 69
           If _IsPressed($i) Then $zoom = $i-60
       Next
       Loupe($aMouse_Pos)
EndIf
WEnd


Func On_Exit()
    _WinAPI_SelectObject($hMagDC, $oObj)
    _WinAPI_DeleteObject($hPen)
    _WinAPI_ReleaseDC(0, $hDeskDC)
    _WinAPI_ReleaseDC($hMag_GUI, $hMagDC)
    GUIDelete($hMag_GUI)
    Exit
EndFunc   ;==>On_Exit


Func Loupe($aMouse_Pos)
    Local $iX, $iY
    _WinAPI_StretchBlt($hMagDC, 0, 0, 100, 100, $hDeskDC, $aMouse_Pos[0] - 50/$zoom+1, $aMouse_Pos[1] - 50/$zoom+1, 100/$zoom, 100/$zoom, $SRCCOPY)

; crosshair ========
    _WinAPI_MoveTo ($hMagDC, 0, 50)
    _WinAPI_LineTo ($hMagDC, 46, 50)
    _WinAPI_MoveTo ($hMagDC, 54, 50)
    _WinAPI_LineTo ($hMagDC, 100, 50)

    _WinAPI_MoveTo ($hMagDC, 50, 0)
    _WinAPI_LineTo ($hMagDC, 50, 46)
    _WinAPI_MoveTo ($hMagDC, 50, 54)
    _WinAPI_LineTo ($hMagDC, 50, 100)
;================

; center dot
    DllCall("gdi32.dll","int","Arc", "hwnd", $hMagDC, "int", 46, "int", 46, "int", 55, "int", 55, "int", 0, "int", 50, "int", 0, "int", 50)

    If $aMouse_Pos[0] < (@DesktopWidth - 100 -100/$zoom) Then
        $iX = $aMouse_Pos[0] + 100/$zoom
    Else
        $iX = $aMouse_Pos[0] - 100 -100/$zoom
    EndIf
    If $aMouse_Pos[1] < (@DesktopHeight - 120 -100/$zoom) Then
        $iY = $aMouse_Pos[1] + 100/$zoom
    Else
        $iY = $aMouse_Pos[1] - 100 -100/$zoom
    EndIf
    WinMove($hMag_GUI, "", $iX, $iY, 100, 100)
EndFunc   ;==>Loupe

 

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