tip Posted June 10, 2011 Share Posted June 10, 2011 (edited) Hi, I recently needed to place a semi transparent layer over a background image in order to make my label(text) controls more readable. Although I've tinkered with GDI+ functions, child guis etc., in the end I've come up with this. This UDF takes advantage of trancexx's GIFAnimations UDF and creates semi-transparent layer using several embeded(binary) PNG images. I think it is very easy to use and it does the job the effective way without calling/registering bunch of redraw functions etc. (thanks to GIFAnimations UDF.) An alternative function which creates the semi-transparent layer as child gui is also included. I really prefer _CreateBlankBox but it can be helpful if you are curious. I hope it will be useful. Sincerely, Tip P.S.: Example is included...CreateBlankBox.zip Edited June 12, 2011 by tip ravkr 1 [center]MsgBox_Tipped: Eye candy msgboxes/inputboxes/loginboxes. | CreateBlankBox: Semi-transparent layers with borders and rounded corners.[/center] Link to comment Share on other sites More sharing options...
Digisoul Posted June 11, 2011 Share Posted June 11, 2011 Great approach Tip! 73 108 111 118 101 65 117 116 111 105 116 Link to comment Share on other sites More sharing options...
UEZ Posted June 11, 2011 Share Posted June 11, 2011 Looks nice! Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
picea892 Posted June 11, 2011 Share Posted June 11, 2011 Very neat...very complicated....I have experimented with this off and on over the years and come up with the below. There are known repaint problems with the controltoroundedrectangle function. But otherwise it is the effect you are looking for. Picea892 expandcollapse popup#include <GUIConstantsEx.au3> #include <WINAPI.au3> #include <GDIPlus.au3> commonbck() Func commonbck() $Gui = GUICreate("", 400,300,-1,-1) $bckpic_prime= GUICtrlCreatePic("BkgPic.jpg",0,0,400,300) GuiCtrlSetState(-1,$GUI_DISABLE) $bckpic= GUICtrlCreatePic("",50,50,300, 150) GuiCtrlSetState(-1,$GUI_DISABLE) background(-1) $title=GUICtrlCreateLabel("Transparent background, only one GUI",75,55,260,120) GUICtrlSetFont(-1,20,400,1,"Verdana") GUICtrlSetColor(-1,"0x000022") GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUISetState() _ControlToRoundedRectangle($bckpic,0,0,270, 120,24) EndFunc While 1 sleep(50) $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit EndSelect WEnd func background($control) _GDIPlus_Startup () $hwd=GUICtrlGetHandle($control) ;$guiname=_WinAPI_GetParent($hwd) $width=_WinAPI_GetClientWidth($hwd) $height=_WinAPI_GetClientHeight($hwd) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwd) $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($width,$height, $hGraphic) $hImage1=_GDIPlus_ImageGetGraphicsContext($hBitmap1) _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 4) for $p = 0 to $width step 1 $hPen2=_GDIPlus_PenCreate(BitOR(0x32000000,0x000000),1) _GDIPlus_GraphicsDrawLine($hImage1,$p,1,$p,$height,$hPen2) _GDIPlus_PenDispose($hPen2) Next _GDIPlus_GraphicsSetSmoothingMode($hImage1, 2) $hBMP1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1) _WinAPI_DeleteObject(GUICtrlSendMsg($control, 0x0172, 0, $hBMP1)) _GDIPlus_GraphicsDispose($hImage1) _WinAPI_DeleteObject($hBMP1) _GDIPlus_BitmapDispose($hBitmap1) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown () EndFunc Func _ControlToRoundedRectangle($aControl,$X1,$Y1,$X2,$Y2,$X3) Local $l Local $handle = GUICtrlGetHandle($aControl) $l = DllCall("gdi32.dll","int","CreateRoundRectRgn","int",$X1,"int",$Y1,"int",$X2,"int",$Y2,"int",$X3,"int",$X3) DllCall("user32.dll","int","SetWindowRgn","hwnd",$handle,"int",$l[0],"int",True) EndFunc Func startbmp($iWidth, $iHeight) ;Create a new bitmap, this way the original opened png is left unchanged $hBitmap = _GDIPlus_GraphicsCreateFromHWND(WinGetHandle($GUI)) $hImage = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hBitmap) _WinAPI_DeleteObject($hBitmap) Return $hImage EndFunc Link to comment Share on other sites More sharing options...
Digisoul Posted June 12, 2011 Share Posted June 12, 2011 Very neat...very complicated....I have experimented with this off and on over the years and come up with the below. There are known repaint problems with the controltoroundedrectangle function. But otherwise it is the effect you are looking for. Picea892 expandcollapse popup#include <GUIConstantsEx.au3> #include <WINAPI.au3> #include <GDIPlus.au3> commonbck() Func commonbck() $Gui = GUICreate("", 400,300,-1,-1) $bckpic_prime= GUICtrlCreatePic("BkgPic.jpg",0,0,400,300) GuiCtrlSetState(-1,$GUI_DISABLE) $bckpic= GUICtrlCreatePic("",50,50,300, 150) GuiCtrlSetState(-1,$GUI_DISABLE) background(-1) $title=GUICtrlCreateLabel("Transparent background, only one GUI",75,55,260,120) GUICtrlSetFont(-1,20,400,1,"Verdana") GUICtrlSetColor(-1,"0x000022") GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUISetState() _ControlToRoundedRectangle($bckpic,0,0,270, 120,24) EndFunc While 1 sleep(50) $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit EndSelect WEnd func background($control) _GDIPlus_Startup () $hwd=GUICtrlGetHandle($control) ;$guiname=_WinAPI_GetParent($hwd) $width=_WinAPI_GetClientWidth($hwd) $height=_WinAPI_GetClientHeight($hwd) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwd) $hBitmap1 = _GDIPlus_BitmapCreateFromGraphics($width,$height, $hGraphic) $hImage1=_GDIPlus_ImageGetGraphicsContext($hBitmap1) _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 4) for $p = 0 to $width step 1 $hPen2=_GDIPlus_PenCreate(BitOR(0x32000000,0x000000),1) _GDIPlus_GraphicsDrawLine($hImage1,$p,1,$p,$height,$hPen2) _GDIPlus_PenDispose($hPen2) Next _GDIPlus_GraphicsSetSmoothingMode($hImage1, 2) $hBMP1 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap1) _WinAPI_DeleteObject(GUICtrlSendMsg($control, 0x0172, 0, $hBMP1)) _GDIPlus_GraphicsDispose($hImage1) _WinAPI_DeleteObject($hBMP1) _GDIPlus_BitmapDispose($hBitmap1) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown () EndFunc Func _ControlToRoundedRectangle($aControl,$X1,$Y1,$X2,$Y2,$X3) Local $l Local $handle = GUICtrlGetHandle($aControl) $l = DllCall("gdi32.dll","int","CreateRoundRectRgn","int",$X1,"int",$Y1,"int",$X2,"int",$Y2,"int",$X3,"int",$X3) DllCall("user32.dll","int","SetWindowRgn","hwnd",$handle,"int",$l[0],"int",True) EndFunc Func startbmp($iWidth, $iHeight) ;Create a new bitmap, this way the original opened png is left unchanged $hBitmap = _GDIPlus_GraphicsCreateFromHWND(WinGetHandle($GUI)) $hImage = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hBitmap) _WinAPI_DeleteObject($hBitmap) Return $hImage EndFunc Your example is quite simple, but what if i need the borders around the box with different colors ? 73 108 111 118 101 65 117 116 111 105 116 Link to comment Share on other sites More sharing options...
Beege Posted June 12, 2011 Share Posted June 12, 2011 Very cool! Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now