top
Loading...
Office或IE4風格的ToolBar
p>用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.zhujiangroad.com
來源:http://www.zhujiangroad.com
北斗有巢氏 有巢氏北斗