用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技巧专区 (7092篇文章)
- VB+Access设计图书管理系统 (104238次浏览)
- VB设计有语音报时和报警功能的闹钟 (13528次浏览)
- 用VB制作一个简单的MP3播放器 (8172次浏览)
- DataGrid 控件的使用 (5010次浏览)
- 用VB编写记事本 (4443次浏览)
- IP地址与子网掩码(二) (4152次浏览)
- IP地址与子网掩码(三) (3708次浏览)
- 掌握VB中的ADO数据对象编程 (3504次浏览)
- 在VB下设计开发实时的数据采集曲线 (3403次浏览)
- VB中使用WinSock控件编写网络程序 (3400次浏览)



