频道直达 - 专题 - 新闻 - 技巧 - 组网 - 开发 - 安全 - web编程 - 图像 - 操作系统 - 数据库 - 教育 - 旅游 - 健康 - 时尚 - 驱动 - 软件 - 游戏 - 多媒体 - ERP - 讨论组

Office或IE4风格的ToolBar

来源:天涯风铃 作者:- 出处:巧巧读书 2006-02-12 进入讨论组

  用API可以轻松改变ToolBar的风格。需要4.70或其以上版本的comctl32.dll支持。

  声明:

Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Integer, ByVal lParam As Any) As Long
Private Declare Function FindWindowEx Lib "user32" Alias _
"FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 _
As Long, ByVal lpsz1 As String, ByVal lpsz2 As _
String) As Long
Private Const WM_USER = &H400
Private Const TB_SETSTYLE = WM_USER + 56
Private Const TB_GETSTYLE = WM_USER + 57
Private Const TBSTYLE_FLAT = &H800
Private Const TBSTYLE_LIST = &H1000
函数:
tlbToolbarStyle :
1 为 Office97 风格
2 为 IE4 风格
Public Sub ToolbarStyle(tlb As Toolbar, _
tlbToolbarStyle As Long)
Dim lngStyle As Long
Dim lngResult As Long
Dim lngHWND As Long
Find child window and get style bits
lngHWND = FindWindowEx(tlb.hwnd, 0&, _
"ToolbarWindow32", vbNullString)
lngStyle = SendMessage(lngHWND, _
TB_GETSTYLE, 0&, 0&)
Use a case statement to get the effect
Select Case tlbToolbarStyle
Case 1:
Creates an Office 97 like toolbar
lngStyle = lngStyle Or TBSTYLE_FLAT
Case 2:
Creates an Explorer 4.0 like toolbar,
with text to the right
of the picture. You must provide text
in order to get the effect.
lngStyle = lngStyle Or TBSTYLE_FLAT _
Or TBSTYLE_LIST
Case Else
lngStyle = lngStyle Or TBSTYLE_FLAT
End Select
Use the API call to change the toolbar
lngResult = SendMessage(lngHWND, _
TB_SETSTYLE, 0, lngStyle)
 
Show the effects
tlb.Refresh
End Sub
在 Form 装入时调用:
Private Sub Form_Load()
Call ToolbarStyle(Me.Toolbar1, 2)

End SubPrivate Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, Val wMsg As Long, _
ByVal wParam As Integer, ByVal lParam As Any) As Long
Private Declare Function FindWindowEx Lib "user32" Alias _
"FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 _
As Long, ByVal lpsz1 As String, ByVal lpsz2 As _
String) As Long
Private Const WM_USER = &H400
Private Const TB_SETSTYLE = WM_USER + 56
Private Const TB_GETSTYLE = WM_USER + 57
Private Const TBSTYLE_FLAT = &H800
Private Const TBSTYLE_LIST = &H1000
函数:
tlbToolbarStyle :
1 为 Office97 风格
2 为 IE4 风格
Public Sub ToolbarStyle(tlb As Toolbar, _
tlbToolbarStyle As Long)
Dim lngStyle As Long
Dim lngResult As Long
Dim lngHWND As Long
Find child window and get style bits
lngHWND = FindWindowEx(tlb.hwnd, 0&, _
"ToolbarWindow32", vbNullString)
lngStyle = SendMessage(lngHWND, _
TB_GETSTYLE, 0&, 0&)
Use a case statement to get the effect
Select Case tlbToolbarStyle
Case 1:
Creates an Office 97 like toolbar
lngStyle = lngStyle Or TBSTYLE_FLAT
Case 2:
Creates an Explorer 4.0 like toolbar,
with text to the right
of the picture. You must provide text
in order to get the effect.
lngStyle = lngStyle Or TBSTYLE_FLAT _
Or TBSTYLE_LIST
Case Else
lngStyle = lngStyle Or TBSTYLE_FLAT
End Select
Use the API call to change the toolbar
lngResult = SendMessage(lngHWND, _
TB_SETSTYLE, 0, lngStyle)
 
Show the effects
tlb.Refresh
End Sub
在 Form 装入时调用:
Private Sub Form_Load()
Call ToolbarStyle(Me.Toolbar1, 2)

End Sub

  关于ToolBar风格的说明:

  Office风格的Toolbar是指在鼠标移动到ICON后,会出现边框。如我们在VB5中用的一样。而comctl的ToolBar是没有该效果的。

  IE4风格的Toolbar可以在ICON下面出现文字,如同IE4中的Toolbar一样。(可能是反一下……)

保留地址 http://www.qqread.com/vb/b712353100.html 更多文章 更多内容请看Office技巧专区专题,或进入讨论组讨论。
收藏此文】【 】【打印】【关闭
较早的文章:用VB设计MSN信息群发软件

较新的文章:VB中检测是否连网
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
巧巧读书宗旨
相关专题
讨论组问题推荐
站内各频道最新更新文档
站内最新制作专题
热门关键字导读
Photoshop教 程照片处理 照片制作 PS快捷键 抠图
计 算 机 故 障XP系统修复
艺 术 与 设 计设计 流媒体 设计欣赏 边框
计 算 机 安 全ARP
站内频道文章精选
巧巧电脑频道编辑信箱  告诉我们您想看的专题或文章