如何改变TooBar的背景色?
请问如何用API改变TooBar的背景色.
程序代码:
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 OleTranslateColor Lib "oleaut32.dll" (ByVal lOleColor As Long, ByVal lHPalette As Long, ByRef lColorRef As Long) As Long Private Declare Function CreateSolidBrush Lib "gdi32.dll" (ByVal crColor As Long) As Long Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long Private Declare Function CreatePatternBrush Lib "gdi32.dll" (ByVal hBitmap As Long) As Long Private Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, lpRect As Long, ByVal bErase As Long) As Long Private Const GCL_HBRBACKGROUND As Long = -10 Private Function GDI_TranslateColor(OleClr As OLE_COLOR, Optional hPal As Integer = 0) As Long If OleTranslateColor(OleClr, hPal, GDI_TranslateColor) Then GDI_TranslateColor = &HFFFF& End Function Function GDI_CreateSoildBrush(bColor As OLE_COLOR) As Long GDI_CreateSoildBrush = CreateSolidBrush(GDI_TranslateColor(bColor)) End Function Public Sub SetToolbarBG(hwnd As Long, hBmp As Long) DeleteObject SetClassLong(hwnd, GCL_HBRBACKGROUND, CreatePatternBrush(hBmp)) InvalidateRect 0&, 0&, False End Sub Public Sub SetToolbarBK(hwnd As Long, hColor As OLE_COLOR) DeleteObject SetClassLong(hwnd, GCL_HBRBACKGROUND, GDI_CreateSoildBrush(hColor)) InvalidateRect 0&, 0&, False End Sub Private Sub Command2_Click() Call SetToolbarBK(Toolbar1.hwnd, vbYellow) End Sub Private Sub Command1_Click() Call SetToolbarBK(Toolbar1.hwnd, vbBlue) End Sub Private Sub Form_Unload(Cancel As Integer) '这段代码一定要有哦,不然回不来就别找我耶 SetToolbarBK Toolbar1.hwnd, vbButtonFace End Sub
注意:Toobar控件的Style属性一定要在设计状态下设为1,不然代码运行没有效果的