Jump to content

CreateBlankBox UDF


tip
 Share

Recommended Posts

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 by tip

[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

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

#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

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

#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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...