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.
'The drawing can be the display of an image, if you choose. Use LoadImage()
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
Global hDlg,hLst,hBMP,hBMPDC 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, bm As Bitmap
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
hBmp = LoadImage ( %NULL, "cowgirl.bmp", %IMAGE_BITMAP, 0, 0, %LR_LOADFROMFILE)
hBmpDC = CreateCompatibleDC(Cb.WParam)
SelectObject hBmpDC, hBmp
GetObject (hBmp, SizeOf(bm),bm)
' BitBlt (Cb.WParam,0,0,bm.bmWidth,bm.bmHeight,hBMPDC,0,0, %SRCCOPY)
StretchBlt Cb.WParam, 0,0,w,40,hBMPDC,0,0,bm.bmWidth,bm.bmHeight, %SRCCopy
'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_01124
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm