Date: 02-16-2022
Return to Index
created by gbSnippets
'To create a transparent toolbar, one that lets the parent dialog color be visible,
'use the TBStyle_Flat and %TBStyle_Transparent styles.
'In addition to setting the Dialog background color, you can also draw directly on the dialog
'and see the resulting drawing through a transparent toolbar.
'If you draw only under the transparent toolbar using WM_EraseBkgnd you must also draw the
'entire dialog surface.
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg,hLst As Dword 'main dialog handle
Function PBMain()
'create dialog
Dialog New Pixels, 0, "Toolbar Test",,, 200,150, %WS_OverlappedWindow, To hDlg
Dialog Set Color hDlg, %Black, %rgb_LightBlue
'add toolbar
Control Add Toolbar, hDlg, 500,"", 0,0,0,0, %TbStyle_Flat Or %TbStyle_Transparent
'create imagelist
ImageList New Icon 16,16,24,10 To hLst
ImageList Add Icon hLst, LoadImage(%Null, Exe.Path$ + "print.ico", %Image_Icon, 24,24, %LR_LoadFromFile)
ImageList Add Icon hLst, LoadImage(%Null, Exe.Path$ + "help.ico", %Image_Icon, 24,24, %LR_LoadFromFile)
Toolbar Set ImageList hDlg, 500, hLst, 0 'attach imagelist
'create buttons
Toolbar Add Button hDlg, 500, 1, 200, %TbStyle_Button, "Print"
Toolbar Add Button hDlg, 500, 2, 201, %TbStyle_Button, "Help"
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local w,h,origpen,origbrush As Long, gRect As Gradient_Rect
Dim V(1) As TriVertex
Select Case Cb.Msg
Case %WM_EraseBkgnd 'cb.wParam is the DC of the dialog
Dialog Get Client hDlg To w,h
V(0).x = 0
V(0).y = 0
V(0).Red = Mak(Word,0,255)
V(0).Green = 0
V(0).Blue = 0
V(1).x = w '<--- not w-1
V(1).y = 40 '<--- not h-1
V(1).Red = 0
V(1).Green = 0
V(1).Blue = Mak(Word,0,255)
gRect.UpperLeft = 0
gRect.LowerRight = 1
GradientFill Cb.WParam, V(0), 2, gRect, 1, %Gradient_Fill_Rect_H
'DC_Pen / DC_Brush allows changing the color
SelectObject(Cb.WParam, GetStockObject(%DC_Brush))
SelectObject(Cb.WParam, GetStockObject(%DC_Pen))
SetDCPenColor(Cb.WParam, %rgb_Salmon)
SetDCBrushColor(Cb.WParam, %rgb_Salmon)
Rectangle Cb.WParam, 0,40,w,h
SelectObject(Cb.WParam,origPen)
SelectObject(Cb.WParam,origBrush)
Function = %True
End Select
End Function
'gbs_01123
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm