| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 570 人关注过本帖
标题:如何改变TooBar的背景色?
只看楼主 加入收藏
小靓仔仔
Rank: 1
等 级:新手上路
帖 子:17
专家分:3
注 册:2010-3-7
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
如何改变TooBar的背景色?
请问如何用API改变TooBar的背景色.
搜索更多相关主题的帖子: TooBar 
2010-04-08 12:33
不说也罢
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:39
帖 子:1481
专家分:4989
注 册:2007-10-7
收藏
得分:20 
程序代码:
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,不然代码运行没有效果的
      

===================================================
讨厌C#的行尾的小尾巴;和一对大括号{ }
===================================================
2010-04-09 12:57
小靓仔仔
Rank: 1
等 级:新手上路
帖 子:17
专家分:3
注 册:2010-3-7
收藏
得分:0 
谢谢!!
2010-04-11 19:52
快速回复:如何改变TooBar的背景色?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.039164 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved