Jump to content
Sign in to follow this  
chachew

Transparent cursor image that i can click through

Recommended Posts

chachew

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

Share this post


Link to post
Share on other sites
FireFox

Try with the $WS_EX_TRANSPARENT exstyle.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
chachew

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

Share this post


Link to post
Share on other sites
FireFox

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
  • Like 1

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
chachew

Awesome that is working as expected for me!

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  

  • Similar Content

    • Sven-Seyfert
      By Sven-Seyfert
      Hi Community,

      I'm looking for a way to do a Video Overlay GUI or something like that. The idea is to create a GUI which plays a video loop (with transparency/alpha channel) in front of an other GUI. Before you asking why - because I don't believe that GDIPlus can do it out of the box. My skillset for that kind of graphical things isn't good enough to do that, but here are some specialist like @UEZ maybe who can help.

      Example alpha channel video (visualized as animated *.gif):

      I tried to do the light rays effect directly with GDIPlus, but honestly that's a bit too difficult for me. I would be very glad and grateful if there are some suggestions, ideas or recommendations.

      Code for the Video play:
       
      Example video "End.mpeg":
       
      The next challenge is that the overlay GUI should be not clickable. If I hover over the overlay area, I want to have the possibility to control the GUI or what ever, in the background. But if there is any chance to make it with GDIPlus as a Video Overlay for light rays, I would prefer that approach instead of my crazy work-around idea.

      Thanks for any suggestion - I'm grateful!
      Sven
    • aiter
      By aiter
      I am trying to get an image showing through a edit box.  I am only successful in making the edit box totally transparent
      #include-once #include <GUIConstants.au3> #include <GDIPlus.au3> #include <WinAPISys.au3> #include <colorconstants.au3> ;WS_EX_TRANSPARENT $gui = GUICreate("", 1000, 800, -1, -1, -1 , $WS_EX_LAYERED) ; use layered to get _winapi_setlay... to work $pic = GUICtrlCreatePic("c:\Program Files (x86)\AutoIt3\Examples\GUI\Merlin.gif", 0,0,1000, 800) GUICtrlSetState(-1, $GUI_DISABLE) $edit = GUICtrlCreateEdit("First line" & @CRLF, 176, 32,200,600) GUICtrlSetBkColor(-1,$COLOR_YELLOW) _WinAPI_SetLayeredWindowAttributes($gui,$COLOR_YELLOW,199) ; 199 is alpha (transparency level) GUISetState(@SW_SHOW,$gui) While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else EndSelect WEnd Exit Func Terminate() exit(0) EndFunc So I am making the edit box's background yellow then using the _WINAPI_SetLayeredWIndowAttributes command to make the yellow disappear (which it does), but the alpha level is supposed to give a bit of opaqueness to it, but its not, just making it totally transparent.  The alpha level is in fact affecting the window itself and not the edit box. I only want the edit box to be partially transparent.
      Help appreciated.
       
    • ISI360
      By ISI360
      Hi!
      I am searching for a way to display a transparent image (or Icon) over an Button. And the image should always stay on top.

      Here is what i have so far:
      At script start the picture is over the button..but if you move the mouse over the button it overlaps the image.
      And if i add $GUI_ONTOP to the picture, the transparency is gone

      Maybe someone has an idea..

      Thanks in advance!
       
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WinAPIIcons.au3> #include <WinAPIShellEx.au3> GUICreate("GUI", 300, 300) $hbutton = GUICtrlCreateButton("This is a button", 20, 40, 150, 30,$WS_CLIPSIBLINGS) $hpic = GUICtrlCreatePic("", 10, 10, 128, 128) _SetIconAlpha($hpic,"shell32.dll", 12,128,128) GUICtrlSetState(-1, $GUI_DISABLE) ;~ GUICtrlSetState(-1,$GUI_ONTOP) ;If you uncomment this..the picture is on top...but the transparency is gone :( GUISetState() While 1 $Msg = GUIGetMsg() If $Msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd Func _SetIconAlpha($hWnd, $sIcon, $iIndex, $iWidth, $iHeight) If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) If $hWnd = 0 Then Return SetError(1, 0, 0) EndIf EndIf If $iIndex <> 0 Then $iIndex = $iIndex - 1 Local $hIcon = _WinAPI_ShellExtractIcon($sIcon, $iIndex, $iWidth, $iHeight) If $hIcon = 0 Then Return SetError(1, 0, 0) EndIf Local $hBitmap, $hObj, $hDC, $hMem, $hSv $hDC = _WinAPI_GetDC($hWnd) $hMem = _WinAPI_CreateCompatibleDC($hDC) $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight) $hSv = _WinAPI_SelectObject($hMem, $hBitmap) _WinAPI_DrawIconEx($hMem, 0, 0, $hIcon, $iWidth, $iHeight, 0, 0, 2) _WinAPI_ReleaseDC($hWnd, $hDC) _WinAPI_SelectObject($hMem, $hSv) _WinAPI_DeleteDC($hMem) _WinAPI_DestroyIcon($hIcon) _WinAPI_DeleteObject(_SendMessage($hWnd, 0x0172, 0, 0)) _SendMessage($hWnd, 0x0172, 0, $hBitmap) $hObj = _SendMessage($hWnd, 0x0173) If $hObj <> $hBitmap Then _WinAPI_DeleteObject($hBitmap) EndIf Return 1 EndFunc ;==>_SetIconAlpha  
    • AndreyS
      By AndreyS
      Tell me, please, how to set / change the cursor over RichEdit (created with _GUICtrlRichEdit_Create)?
    • Skeletor
      By Skeletor
      Hi All,
      I know many newbies search for this feature.
      I decided to share this piece of code with everyone.
      Basically its a "splash screen" that has a transparent image.
      In a nutshell - Gui with a transparent gif.
      Enjoy...
      Download attachment....
       
      Splash Screen GUI.zip
×