Need help achieving transparent overlay

14 posts in this topic

qwert 31

I'm trying to place a transparent rectangle over an external window by having a transparent GUI on top. Everything is working except the background of the rectangle itself. What am I missing? Is there a better approach?

Share this post

Link to post

Share on other sites

qwert 31

After two full days and countless searches, I now believe it's not possible to make the background color of a graphic control transparent. Here's a link to another post with basically the same question:

I'm at the point I need to move on to develop another approach. The best alternative I have now is to use GUICtrlCreatePic to put up a transparent GIF and then draw individual lines on it with DLL calls. It just seems odd that so many controls can set background transparency but graphic controls can't.

Share this post

Link to post

Share on other sites

qwert 31

jpam, thanks for the examples. I had found the one with the ellipse during my searches. What I'm looking for is to make the background of the entire area of the graphic transparent-- and then have the ellipse (with no fill) lay over whatever is underneath. The two examples below show the difference.

Also, could you comment on the "CreatePen/SelectObject/DeleteObject" sequence used in the function. Doesn't this delete the pen before it's used? And if I call the function more than once, should the delete steps be put off until exiting the scipt?

I certainly appreciate your help on this. It's opening up a new area of capability.

Share this post

Link to post

Share on other sites

jpam 2

to erase a Rectangle ,simple draw a new one over the old one with the transparent line color.

#include <GuiConstantsEx.au3>#include <WindowsConstants.au3>$Main_Gui=GUICreate("",400,400,-1,-1,-1,$WS_EX_LAYERED)GUICtrlCreateLabel("",50,0,200,50,-1,$GUI_WS_EX_PARENTDRAG)GUISetBkColor(0xABCDEF)GUICtrlSetFont(-1,14,900)$exit=GUICtrlCreateButton("Exit",200,100,80,21)DllCall("user32.dll","int","SetLayeredWindowAttributes","hwnd",$Main_Gui,"long",0xEFCDAB,"byte",255,"long",0x1+0x2)GUISetState()$hdc= GetHDC()
DrawEllipse($hdc,100,160,300,360,1,0x000000,0xEFCDAB)Sleep(2000)
DrawEllipse($hdc,100,160,300,360,1,0xEFCDAB,0xEFCDAB); draw a new shape over the old one ; with transparent line color to erase old shape from screenWhile1$msg=GUIGetMsg()If$msg=$exitThenExitIf$msg=-3ThenExitWEndFunc GetHDC()Local$S_WIN_TILLE=WinGetTitle("","")Local$S_ClientSize=WinGetClientSize($S_WIN_TILLE,"")Local$S_WIN_GETHANDLE=WinGetHandle($S_WIN_TILLE,"")Local$S_RAW_HDC=DllCall("user32.dll","ptr","GetDC","hwnd",$S_WIN_GETHANDLE)$hDC="0x"&Hex($S_RAW_HDC[0])Return$hDCEndFuncFunc DrawEllipse($S_Destination,$S_left,$S_top,$S_right,$S_bottom,$S_linewidth,$S_linecolor,$S_fillcolor)$S_hNewPen=DllCall("gdi32.dll","int","CreatePen",_; Create new pen to draw with "int",0,_"int",$S_linewidth,_"int",$S_linecolor)$S_hOldPen=DllCall("gdi32.dll","int","SelectObject",_; Select new pen into DC "int",$S_Destination,_; and save handle to old one "int",$S_hNewPen[0])$S_NewBrush=DllCall("gdi32.dll","int","CreateSolidBrush",_; Create new brush to fill shapes"int",$S_fillcolor)$S_OldBrush=DllCall("gdi32.dll","int","SelectObject",_; Select new brush into DC "int",$S_Destination,_; and save handle to old one "int",$S_NewBrush[0])DllCall("gdi32.dll","int","Rectangle",_; draw Rectangle"int",$S_Destination,_"int",$S_left,_"int",$S_top,_"int",$S_right,_"int",$S_bottom)DllCall("gdi32.dll","int","SelectObject",_; Displace New Pen from DC "int",$S_Destination,_"int",$S_hOldPen[0])DllCall("gdi32.dll","int","DeleteObject",_; delete pen to free up system resources"int",$S_hNewPen[0]); when a pen is still selected in the dc ,you can not delete itDllCall("gdi32.dll","int","SelectObject",_; Displace New brush from DC "int",$S_Destination,_; when a Brush is still selected in the dc ,you can not delete it"int",$S_OldBrush[0])DllCall("gdi32.dll","int","DeleteObject",_; delete brush to free up system resources"int",$S_NewBrush[0]); when a brush is still selected in the dc ,you can not delete itEndFunc

Share this post

Link to post

Share on other sites

qwert 31

Given the new order of the steps, it does look like the pen create and delete steps could be pulled outside of the draw function for the case where repeated calls will be made using the same settings. I'll give it a try just to know, although it works great, as is.