您的位置:学习中国 推荐教程 VB编程 正文
原作者:kuku 添加时间:2007-06-02 原文发表:2007-06-02 人气:41 来源:互联网


用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_FLATEnd 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 一样。(可能是反一下。。。。)
本页地址
相关文章

Cool 3D 浮動按鈕的模擬作法
用VB做个漂亮的进度条
用VB设计聚焦框程序
用VB6实现动态增减控件
VB实现窗口的弹出式菜单
VB6制作Win98风格的工具栏
VB编程的必备技巧
VB程序中处理随机事件
Video/ Audio压缩数据流播放技术
怎么让窗体透明后,控件不透明?
VB 5.0中实现鼠标拖放
VB5.0下工具条的制作
VB5.0中基于桌面的屏幕技巧
VB5.0中实现字体闪烁效果
VB5实现窗口图像缩放、滚动技巧
VB6.0动态加载ActiveX控件漫谈
VB6制作Win98风格的工具栏
VB编程步步高-表单篇
VB编程常见问题
VB编程中如何锁定鼠标

相关评论


本文章所属分类:首页 推荐教程 VB编程   VB编程