by Buddhika Fernando. (6 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Thu 15th June 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Set Any Picture Or Colour To Toolbar Background.
API Declarations
ByVal hWnd1 As Long, ByVal hWnd2 As Long, _
ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SetClassLong Lib "user32" Alias "SetClassLongA" ( _
ByVal hwnd As Long, ByVal nindex As Long, ByVal dwnewlong As Long) As Long
Private Declare Function InvalidateRect Lib "user32" _
(ByVal hwnd As Long, lpRect As Long, ByVal bErase As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function CreatePatternBrush Lib "gdi32" (ByVal hBitmap As Long) As Long
Private Enum enuTBType
enuTB_FLAT = 1
enuTB_STANDARD = 2
End Enum
Private Const GCL_HBRBACKGROUND = (-10)
Dim lTBWnd As Long
Select Case pType
Case enuTB_FLAT
DeleteObject SetClassLong(TB.hwnd, GCL_HBRBACKGROUND, PNewBack)
Case enuTB_STANDARD
lTBWnd = FindWindowEx(TB.hwnd, 0, "msvb_lib_toolbar", vbNullString)
DeleteObject SetClassLong(lTBWnd, GCL_HBRBACKGROUND, PNewBack)
End Select
End Sub
Private Sub ApplyChanges(ByVal Pic_ As PictureBox, ByVal ToolBar As ToolBar)
Dim LngNew As Long
LngNew = CreatePatternBrush(Pic_.Picture.Handle)
ChangeTBBack ToolBar, LngNew, enuTB_FLAT
InvalidateRect 0&, 0&, False
End Sub
Private Sub Form_Load()
Call ApplyChanges(Picture1, Toolbar1)
End Sub