VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 建立Office97样工具条
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:8716, 日期:2001-04-11
Creating Office 97 Toolbars

Internet Explorer 3.0 and Office 97 brought in a revolution in toolbars. The now extremely popular 注释:popup button注释: toolbars are taking over almost any new application which has toolbars - and I can see why. I mean, it注释:s got style, a simple look and adds an attractive side to your application. Visual Basic 5.0 didn注释:t bring these controls in as a part of its new control set, but you can do it yourself with the old Common Controls Toolbar, and an API call.

Create a new project, and add the Common Controls ActiveX control to it.
Draw the Toolbar onto a form. Add your buttons.
Place the following code into a new module:
Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function FindWindowEx Lib "user32" _
Alias "FindWindowExA" (ByVal hWndParent As _
Long, ByVal hWndChildWindow As Long, ByVal _
lpClassName As String, ByVal lpsWindowName _
As String) As Long

Public Const GWL_STYLE = &HFFF0

Public Const TBSTYLE_FLAT = &H800

Public Sub TBar97(TBar As Toolbar)

Dim lTBarStyle As Long, lTBarHwnd As Long

If Not TypeOf TBar Is Toolbar Then Exit Sub

lTBarHwnd = FindWindowEx(TBar.hwnd, 0&, "ToolbarWindow32", vbNullString)
lTBarStyle = GetWindowLong(lTBarHwnd, GWL_STYLE)
lTBarStyle = lTBarStyle Or TBSTYLE_FLAT
lTBarStyle = SetWindowLong(lTBarHwnd, GWL_STYLE, lTBarStyle)
TBar.Refresh
End SubNow, in the Form注释:s load event, call TBar97 to make your ToolBar into a CoolBar!

TBar97 ToolBar1Thanks a lot to Alex Shulgin for this improved tip. However, this tip will only work for VB4 and VB5 toolbars. If you want the same effect in VB6, use the toolbar注释:s style property, and set it to tbrFlat.