Jump to content

Draw a circle around the mouse


Bam
 Share

Recommended Posts

ive done some searching and last night i came acrost this, its the closest thing ive found to try to make a filled in circle orbit or circle around ur mouse, im sure u can do this with cos and sin while adding mousepos, but i dont realy understand how to modify this or to fill in the circle also never worked with dll calls befor

so my question is, is thier a simplier way to do this or know how to make sense of this :)

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

HotKeySet("{ESC}", "_Bye")

$iCircleR = 20; <=== Edit this for different circle radius (in pixels)
$iCircleD = $iCircleR * 2
$pt = MouseGetPos()
$GUI = GUICreate("test", $iCircleD, $iCircleD, $pt[0] - $iCircleR, $pt[1] - $iCircleR, $WS_POPUP, $WS_EX_TOPMOST)
GUISetBkColor(0xFF0000)

$a = _CreateRoundRectRgn(0, 0, $iCircleD, $iCircleD, $iCircleD, $iCircleD)
$b = _CreateRoundRectRgn(4, 4, ($iCircleD - 8), ($iCircleD - 8), ($iCircleD - 4), ($iCircleD - 4))

_CombineRgn($a, $b)
_SetWindowRgn($GUI, $a)

GUISetState()
GUISetState(@SW_DISABLE)

While 1
    Sleep(10)
    $pt = MouseGetPos()
    If Not @error Then WinMove($GUI, "", $pt[0] - $iCircleR, $pt[1] - $iCircleR)
WEnd


Func _CreateRoundRectRgn($l, $t, $w, $h, $e1, $e2)
    $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $l, "long", $t, "long", $l + $w, "long", $t + $h, "long", $e1, "long", $e2)
    Return $ret[0]
EndFunc  ;==>_CreateRoundRectRgn

Func _CombineRgn(ByRef $rgn1, ByRef $rgn2)
    DllCall("gdi32.dll", "long", "CombineRgn", "long", $rgn1, "long", $rgn1, "long", $rgn2, "int", 3)
EndFunc  ;==>_CombineRgn

Func _SetWindowRgn($h_win, $rgn)
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $rgn, "int", 1)
EndFunc  ;==>_SetWindowRgn

Func _bye()
    Exit
EndFunc  ;==>_bye
Link to comment
Share on other sites

This does what I think you want

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
Global Const $pi = 3.14159265358979
HotKeySet("{ESC}", "_Bye")

$iCircleR = 20; <=== Edit this for different circle radius (in pixels)
$iCircleD = $iCircleR * 2
Global $radius = 100;radius of movement of the blob mouse cursor to centre of circle blob
Global $angle = 0
Global $incr = 3
$pt = MouseGetPos()
$GUI = GUICreate("test", $iCircleD, $iCircleD, $pt[0] - $iCircleR, $pt[1] - $iCircleR, $WS_POPUP, $WS_EX_TOPMOST)
GUISetBkColor(0xFF0000)

$a = _CreateRoundRectRgn(0, 0, $iCircleD, $iCircleD, $iCircleD, $iCircleD)

Remove comments on next to lines to have the cirle instead of a disc
;$b = _CreateRoundRectRgn(4, 4, ($iCircleD - 8), ($iCircleD - 8), ($iCircleD - 4), ($iCircleD - 4))
;_CombineRgn($a, $b)

_SetWindowRgn($GUI, $a)

GUISetState()
GUISetState(@SW_DISABLE)
adlibenable("setangle",20)

While 1
    Sleep(10)
    $pt = MouseGetPos()
    If Not @error Then MoveBlob($pt)
WEnd


Func _CreateRoundRectRgn($l, $t, $w, $h, $e1, $e2)
    $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $l, "long", $t, "long", $l + $w, "long", $t + $h, "long", $e1, "long", $e2)
    Return $ret[0]
EndFunc ;==>_CreateRoundRectRgn

Func _CombineRgn(ByRef $rgn1, ByRef $rgn2)
    DllCall("gdi32.dll", "long", "CombineRgn", "long", $rgn1, "long", $rgn1, "long", $rgn2, "int", 3)
EndFunc ;==>_CombineRgn

Func _SetWindowRgn($h_win, $rgn)
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $rgn, "int", 1)
EndFunc ;==>_SetWindowRgn

Func _bye()
    Exit
EndFunc ;==>_bye

Func Setangle()

$angle = Mod($angle + $Incr,360);degrees

EndFunc

Func MoveBlob($mousePos)
    $radAng = $angle * $pi/180
    Local $x = $mousepos[0] + $radius * Cos($radAng) - $iCircleR
    Local $y = $mousepos[1] + $radius * Sin($radAng) - $iCircleR
    WinMove($GUI, "", $x,$y)
EndFunc

With a bit of pratice you can get the blob to stay in one place while you move the mouse in a circle. (Why do I waste my time trying to do things like that?)

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

ya that was what i was looken for :) thx

but im not realy sure what this is for, (i dont understand it lol)

Func _CreateRoundRectRgn($l, $t, $w, $h, $e1, $e2)
    $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $l, "long", $t, "long", $l + $w, "long", $t + $h, "long", $e1, "long", $e2)
    Return $ret[0]
EndFunc;==>_CreateRoundRectRgn

Func _CombineRgn(ByRef $rgn1, ByRef $rgn2)
    DllCall("gdi32.dll", "long", "CombineRgn", "long", $rgn1, "long", $rgn1, "long", $rgn2, "int", 3)
EndFunc;==>_CombineRgn

Func _SetWindowRgn($h_win, $rgn)
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $rgn, "int", 1)
EndFunc;==>_SetWindowRgn
Link to comment
Share on other sites

ya that was what i was looken for :) thx

but im not realy sure what this is for, (i dont understand it lol)

Func _CreateRoundRectRgn($l, $t, $w, $h, $e1, $e2)
    $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $l, "long", $t, "long", $l + $w, "long", $t + $h, "long", $e1, "long", $e2)
    Return $ret[0]
EndFunc;==>_CreateRoundRectRgn

Func _CombineRgn(ByRef $rgn1, ByRef $rgn2)
    DllCall("gdi32.dll", "long", "CombineRgn", "long", $rgn1, "long", $rgn1, "long", $rgn2, "int", 3)
EndFunc;==>_CombineRgn

Func _SetWindowRgn($h_win, $rgn)
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $rgn, "int", 1)
EndFunc;==>_SetWindowRgn

This link might help http://msdn.microsoft.com/en-us/library/ms536688(VS.85).aspx

You can create a 'region' of a window. It's just an area. it could be just 1 pixel, a line of pixels a circle a square or any shape you like.

There are functions you can use in a dll which come with Windows. CreateRoundRectRegion is one function in the dll gdi32.dll. If you google "CreateRoundRectRegion function" you will find a link to msdn where it is explained.

This function creates a round rectangle, but by making the radius of the arc in the corners equal to half the side of the window you get a circle.

Func _CreateRoundRectRgn($l, $t, $w, $h, $e1, $e2)
    $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $l, "long", $t, "long", $l + $w, "long", $t + $h, "long", $e1, "long", $e2)
    Return $ret[0]
EndFunc;==>_CreateRoundRectRgn

The function is called again to get another circular region but smaller.

Then CombineRgn is called to combine the regions. By setting the last parameter to 3 you get only that area which is not common to both ie a ring in this case.

From windgi.h used for C,C++ programs.

#define RGN_AND  1
#define RGN_OR  2
#define RGN_XOR  3 <------------
#define RGN_DIFF  4
#define RGN_COPY  5

Func _CombineRgn(ByRef $rgn1, ByRef $rgn2)een
    DllCall("gdi32.dll", "long", "CombineRgn", "long", $rgn1, "long", $rgn1, "long", $rgn2, "int", 3)
EndFunc;==>_CombineRgn

Then you apply the region to the window. The only part of the window which will be shown after this is that part defined by the region. So although the whole gui has been made red, you only see the circular region.

Func _SetWindowRgn($h_win, $rgn)
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $rgn, "int", 1)
EndFunc;==>_SetWindowRgn
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

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