Jump to content

Transparent cursor image that i can click through


Go to solution Solved by FireFox,

Recommended Posts

Posted (edited)

I have found 2 different pieces of code that i am trying to sort of combine into one, and would like some assistance. Basically i want the yellow circle that is in the first code snippet to be transparent and able to be clicked through like the piece in the second code snippet

Snippet 1:

#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 = 0 ;radius of movement of the blob mouse cursor to centre of circle blob
Global $angle = 4
Global $incr = 3
$pt = MouseGetPos()
$GUI = GUICreate("test", $iCircleD, $iCircleD, $pt[0] - $iCircleR, $pt[1] - $iCircleR, $WS_POPUP, $WS_EX_TOPMOST)
GUISetBkColor(0xFFFF99)

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

_SetWindowRgn($GUI, $a)

GUISetState()
GUISetState(@SW_DISABLE)

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

Snippet 2:

#include <GuiEdit.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>

Opt('MustDeclareVars', 1)

Local $hGUI, $hEdit, $hChild, $hLabel

; Create GUI
$hGUI = GUICreate("", 400, 300, -1, -1)
$hChild = GUICreate("Notepad", 400, 300, -1, -1, Default, BitOR($WS_EX_MDICHILD, $WS_EX_LAYERED, $WS_EX_TOPMOST), $hGUI)
$hEdit = _GUICtrlEdit_Create($hChild, "", 2, 2, 394, 268, -1)
GUICtrlSetBkColor ($hEdit, 0xFFFFFF)
_WinAPI_SetLayeredWindowAttributes($hChild, 0xFFFFFF, 255)
$hLabel = GUICtrlCreateLabel("", 0, 0, 400, 300, -1, $GUI_WS_EX_PARENTDRAG)
GUISetState()

_GUICtrlEdit_SetText($hEdit, "This is a test" & @CRLF & "Another Lne")

; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
Edited by chachew
Posted (edited)

Well i have managed to get it kind of working

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

Global Const $pi = 3.14159265358979
HotKeySet("{ESC}", "_Bye")

$iCircleR = 20; <=== Edit this for different circle radius (in pixels)
$iCircleD = $iCircleR * 2
Global $radius = 0 ;radius of movement of the blob mouse cursor to centre of circle blob
Global $angle = 4
Global $incr = 3
$pt = MouseGetPos()
$hGUI = GUICreate("")
$hChild = GUICreate("", $iCircleD, $iCircleD, $pt[0] - $iCircleR, $pt[1] - $iCircleR, $WS_POPUP, $WS_EX_LAYERED)
$hEdit = _GUICtrlEdit_Create($hChild, "", 2, 2, 394, 268, -1)
;GUICtrlSetBkColor($hEdit, 0xFFFFFF)
_WinAPI_SetLayeredWindowAttributes($hChild, 0xFFFFFF, 125)
$hLabel = GUICtrlCreateLabel("", 0, 0, 400, 300, -1, $GUI_WS_EX_PARENTDRAG)
;$GUI = GUICreate("test", $iCircleD, $iCircleD, $pt[0] - $iCircleR, $pt[1] - $iCircleR, $WS_POPUP, $WS_EX_TOPMOST)
GUISetBkColor(0xFFFF99)

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

_SetWindowRgn($hChild, $a)

GUISetState()
;GUISetState(@SW_DISABLE)

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($hChild, "", $x,$y)
EndFunc

The problem is that the focus is inside the circle and focused on the `GUICtrlCreateLabel` section i guess. If i try to type anything then the text is entered into the yellow circle and not the the actual background item. For example Google Chrome

Edited by chachew
  • Solution
Posted (edited)

Here you go:

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Constants.au3>
 
Global Const $pi = 3.14159265358979
HotKeySet("{ESC}", "_Bye")
 
$iCircleR = 20; <=== Edit this for different circle radius (in pixels)
$iCircleD = $iCircleR * 2
Global $radius = 0 ;radius of movement of the blob mouse cursor to centre of circle blob
Global $angle = 4
Global $incr = 3
$pt = MouseGetPos()
 
;New Code
$hGUI = GUICreate("")
$hChild = GUICreate("", $iCircleD, $iCircleD, $pt[0] - $iCircleR, $pt[1] - $iCircleR, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED, $WS_EX_TRANSPARENT))
_WinAPI_SetLayeredWindowAttributes($hChild, 0xFFFFFF, 125)
GUISetBkColor(0xFFFF99)
 
$a = _CreateRoundRectRgn(0, 0, $iCircleD, $iCircleD, $iCircleD, $iCircleD)
 
_SetWindowRgn($hChild, $a)
 
GUISetState(@SW_SHOWNOACTIVATE, $hChild)
 
While 1
    Sleep(10)
 
    $pt = MouseGetPos()
    If Not @error Then MoveBlob($pt)
 
    _WinAPI_SetWindowPos($hChild, $HWND_TOPMOST, 0, 0, 0, 0, BitOR($SWP_NOACTIVATE, $SWP_NOMOVE, $SWP_NOSIZE, $SWP_NOSENDCHANGING))
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   ;==>Setangle
 
Func MoveBlob($mousePos)
    $radAng = $angle * $pi / 180
    Local $x = $mousepos[0] + $radius * Cos($radAng) - $iCircleR
    Local $y = $mousepos[1] + $radius * Sin($radAng) - $iCircleR
    WinMove($hChild, "", $x, $y)
EndFunc   ;==>MoveBlob
I removed the controls, added the TRANSPARENT exstyle to the child GUI and the SetWindowPos function in the main while to keep the window on top in case you activate a top most window (it can be improved if you use a window hook to detect when a new window is activated).

Br, FireFox.

Edited by FireFox

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
×
×
  • Create New...