Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

CreateBlankBox UDF


  • Please log in to reply
5 replies to this topic

#1 tip

tip

    Adventurer

  • Active Members
  • PipPip
  • 103 posts

Posted 10 June 2011 - 05:29 PM

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

Attached Files


Edited by tip, 12 June 2011 - 09:38 AM.

MsgBox_Tipped: Eye candy msgboxes/inputboxes/loginboxes. | CreateBlankBox: Semi-transparent layers with borders and rounded corners.








#2 Digisoul

Digisoul

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 328 posts

Posted 11 June 2011 - 01:37 PM

Great approach Tip!
73 108 111 118 101 65 117 116 111 105 116 Posted Image

#3 UEZ

UEZ

    Never say never

  • MVPs
  • 4,492 posts

Posted 11 June 2011 - 03:39 PM

Looks nice!

Br,
UEZ

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#4 picea892

picea892

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 696 posts

Posted 11 June 2011 - 11:56 PM

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

AutoIt         
#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


#5 Digisoul

Digisoul

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 328 posts

Posted 12 June 2011 - 02:28 AM

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

AutoIt         
#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 Posted Image

#6 Beege

Beege

    Universalist

  • MVPs
  • 895 posts

Posted 12 June 2011 - 05:15 AM

Very cool! Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users