The information in this article applies to:
- Standard, Professional, and Enterprise Editions of Microsoft
Visual Basic, 32-bit only, for Windows, version 4.0
SUMMARY
The Microsoft Windows Common Controls ocx (comctl32.ocx) contains, among
others, controls for Toolbar and StatusBar. With this ocx, the Toolbar and
StatusBar can easily be added to a Visual Basic 4.0 application. However,
there is no easy way for the text of the StatusBar to be in sync with the
text of the ToolTip from the Toolbar.
This article describes how to implement this behavior in Visual Basic 4.0
with a few APIs and the Timer control.
MORE INFORMATION
Some of the more popular software, such as Word, Excel, PowerPoint, etc.,
will not only display the ToolTip, but will also display text in the
StatusBar to give users a more detailed description of what the Toolbar
button will do.
Although this feature is not built into the Toolbar and StatusBar controls,
there are ways to mimic its effect in a Visual Basic 4.0 application.
Step-by-Step Example
- Add the StatusBar, Toolbar, and Timer control to a form.
- On the Toolbar, insert two Buttons.
- On the first Button, set the ToolTipText property to "New," and the
Tag property to "Creates a new xxx."
- On the second Button, set the ToolTipText property to "Open," and the
Tag property to "Opens an existing xxx."
- On the StatusBar, set the AutoSize property of the first Panel to 1.
This will widen the Panel to the width of the StatusBar.
- On the Timer, set the Interval property to 100. This will trigger the
Timer event every 100 milliseconds.
- Add the following code to the Declarations section of this Form:
'API Declarations
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal pClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias _
"GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, _
ByVal cch As Long) As Long
- Add the following code to the Timer event of the Timer control:
Private Sub Timer1_Timer()
Dim class_name As String
Dim window_handle As Long
Dim window_text As String * 100
Dim window_text_len As Long
Dim tooltip_text As String
Dim button_index As Integer
Dim statusbar_text As String
'Define the class name.
class_name = "tooltips_class32"
'Find and get the window handle.
window_handle = FindWindow(class_name, vbNullString)
If window_handle <> 0 Then
'Get the window text
window_text_len = GetWindowText(window_handle, window_text, 100)
tooltip_text = Left$(window_text, window_text_len)
If tooltip_text = "" Then
'Mouse not over a Toolbar Button.
statusbar_text = ""
Else
'Iterate through the Buttons collection and find the Button.
'When found, retrieve text (Button.Tag) for the Statusbar.
For button_index = 1 To Toolbar1.Buttons.Count
If Toolbar1.Buttons(button_index).ToolTipText = _
tooltip_text Then
statusbar_text = Toolbar1.Buttons(button_index).Tag
Exit For
End If
Next
End If
'Check whether Statusbar already contains this text
'(without this, the Statusbar will flicker from frequent and
'unnecessary updates). If it doesn't, update the Statusbar
'with new text.
If StatusBar1.Panels(1).Text <> statusbar_text Then
StatusBar1.Panels(1).Text = statusbar_text
End If
End If
End Sub
- Finally, run this application and place the pointer over each of
the two Toolbar Buttons. The text of the StatusBar will reflect the
purpose of the Button that is currently under the pointer.
Keywords : PrgCtrlsCus PrgCtrlsStd vb432 VB4WIN kbusage kbhowto
Version : 4.0
Platform : NT WINDOWS
|