Jump to content
Sign in to follow this  
onedayillpay

draw a rectangle around mouse on top of all gui

Recommended Posts

onedayillpay

i almost have a working example... i found the example script online for drawing a simple square then i added MouseGetPos()

this almost works, but the rectangle changes size as your mouse moves around, im trying to keep a consistant size...

edit

_WinAPI_DrawRect($left, $top, $bottem, $right, 0x0000CC)

I hate making the post and fixing my script a few minutes later... been a few years since i played with autoit... still love it ;-)

#include
#include

Global $tRect



While 1
$fov = MouseGetPos()
$top = $fov[1] - 100
$bottem = $fov[1] + 100
$left = $fov[0] - 50
$right = $fov[0] + 50
; refresh desktop
_WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), $tRect, 0, BitOR($RDW_INVALIDATE, $RDW_ALLCHILDREN))
_WinAPI_DrawRect($left, $top, $bottem, $right, 0x0000CC)
Sleep(10)
WEnd



Func _WinAPI_DrawRect($start_x, $start_y, $iWidth, $iHeight, $iColor)
Local $hDC = _WinAPI_GetWindowDC(0) ; DC of entire screen (desktop)
$tRect = DllStructCreate($tagRECT)
DllStructSetData($tRect, 1, $start_x)
DllStructSetData($tRect, 2, $start_y)
DllStructSetData($tRect, 3, $iWidth) ; x-coordinate of the lower-right corner of the rectangle
DllStructSetData($tRect, 4, $iHeight) ; y-coordinate of the lower-right corner of the rectangle
Local $hBrush = _WinAPI_CreateSolidBrush($iColor)

_WinAPI_FrameRect($hDC, DllStructGetPtr($tRect), $hBrush)

; clear resources
_WinAPI_DeleteObject($hBrush)
_WinAPI_ReleaseDC(0, $hDC)
EndFunc ;==>_WinAPI_DrawRect
Edited by onedayillpay

Share this post


Link to post
Share on other sites
MouseSpotter

try: _WinAPI_DrawRect($left, $top, $right , $bottem , 0x0000CC)

Share this post


Link to post
Share on other sites
PhoenixXL

Do you want somewhat like this

#include <WinAPI.au3>
#include <APIConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>


Global $hWin = _GUI_Transparent_Client(-1, -1, -1, -1, 5, 0x0000CC)
Global $aPos = WinGetPos($hWin)

Do
Sleep(10)
$aMouse = MouseGetPos()
WinMove($hWin, "", $aMouse[0] - $aPos[2] / 2, $aMouse[1] - $aPos[3] / 2)

Until GUIGetMsg() = $GUI_EVENT_CLOSE


Func _GUI_Transparent_Client($iX, $iY, $iWidth, $iHeight, $iFrameWidth = 10, $iColor = 0)

$hGUI = GUICreate("", $iX, $iY, $iWidth, $iHeight, $WS_POPUP, $WS_EX_TOPMOST)
$aPos = WinGetPos($hGUI)
_GuiHole($hGUI, $iFrameWidth, $iFrameWidth, $aPos[2] - 2 * $iFrameWidth, $aPos[3] - 2 * $iFrameWidth, $aPos[2], $aPos[3])
GUISetBkColor($iColor)
GUISetState()

Return $hGUI

EndFunc ;==>_GUI_Transparent_Client

Func _GuiHole($h_win, $i_x, $i_y, $i_sizew, $i_sizeh, $width, $height)

Local $outer_rgn, $inner_rgn, $combined_rgn

$outer_rgn = _WinAPI_CreateRectRgn(0, 0, $width, $height)
$inner_rgn = _WinAPI_CreateRectRgn($i_x, $i_y, $i_x + $i_sizew, $i_y + $i_sizeh)
$combined_rgn = _WinAPI_CreateRectRgn(0, 0, 0, 0)

_WinAPI_CombineRgn($combined_rgn, $outer_rgn, $inner_rgn, $RGN_DIFF)

_WinAPI_DeleteObject($outer_rgn)
_WinAPI_DeleteObject($inner_rgn)

_WinAPI_SetWindowRgn($h_win, $combined_rgn)

EndFunc ;==>_GuiHole
If you paint on the Screen there would be obvious flickers, you can't help that. A GUI is a better choice

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
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
Sign in to follow this  

×