Microsoft KB Archive/240924

= BUG: TreeView Node Tooltips Flash When Displayed from Modal Window =

Article ID: 240924

Article Last Modified on 5/12/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q240924



SYMPTOMS
When the Microsoft TreeView control has been added to a Visual Basic form, and the user places the mouse cursor over a node where the text is longer than the control's width, a tooltip should appear over that text. If the form is being displayed modally, however, the tooltip will "flash" on and off repeatedly. This behavior occurs only in the compiled version of the application and not in the Visual Basic design environment (IDE.) This problem occurs with the TreeView control from both the Comctl32.ocx and Mscomctl.ocx on all Windows platforms.



CAUSE
This behavior is a result of the TreeView's owned tooltip window becoming disabled when the TreeView's top level client window is shown modally.



RESOLUTION
The tooltip window must be re-enabled before shown, and after the TreeView's top level owner window is fully loaded.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
NOTES
 * Mscomctl.ocx is statically linked to version 5.x of Comctl32.dll, and is not affected by the version of Comctl32.dll installed on the target system.


 * The workaround provided below is insufficient when running under Windows NT 4.0 and comctl32.dll version 4.x or lower is installed. In this case implement the workaround described in the Microsoft Knowledge Base article Q241097 referred to in the REFERENCES section below.

Steps to Reproduce Behavior
 Start a new Visual Basic Standard EXE project. Form1 is created by default. On the Project menu, select Components. Check either Microsoft Windows Common Controls 5.0 or Microsoft Windows Common Controls 6.0 and click OK. Add two CommandButtons and a Label to Form1.  Add the following code to the General Declarations section of Form1: Option Explicit

Private Sub Form_Load On Error Resume Next ' Since the problem only occurs in the IDE, only disable the ' TreeView's Node tooltip window in the VB IDE. ' Since the Statement Debug.Print is removed by compiling, you can use ' it to throw an error to detect the IDE. Debug.Print 1 / 0 If Err Then Command1.Enabled = False Command2.Enabled = False Me.Caption = "Application MUST be compiled" End If  On Error GoTo 0 Command1.Caption = "Show Form2 modally" Command2.Caption = "Show Form2 non-modally" Label1.Caption = "If Form2 is shown modally and run from a compiled " _ & "executable, its TreeView Node tooltip window will repeatedly appear" _ & " and disappear, unless you enable it (remove its WS_DISABLED)."

End Sub

Private Sub Command1_Click If (Form2.Visible = False) Then Form2.Command1.Enabled = True Form2.Show vbModal End If End Sub

Private Sub Command2_Click Form2.Command1.Enabled = False Form2.Show End Sub  On the Project menu, click Add Form to add a second form to the project.</li> Add the TreeView control and a CommandButton to Form2. Resize the TreeView Control so that 35 characters of Node Text are partially obscured.</li>  Add the following code to the General Declarations section of Form2: Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hWnd As Long, ByVal wMsg As Long, _                          ByVal wParam As Long, lParam As Any) As Long

' treeview messages Private Const TV_FIRST = &H1100 Private Const TVM_GETTOOLTIPS = (TV_FIRST + 25)

Private Const GWL_STYLE = (-16) Private Const WS_DISABLED = &H8000000

Private Declare Function GetWindowLong Lib "user32" Alias _ "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long

Private Declare Function EnableWindow Lib "user32" _ (ByVal hWnd As Long, bEnable As Long) As Long

Private Sub Form_Load Dim i As Integer

' Fill up the treeview... For i = 1 To 10 Call TreeView1.Nodes.Add(Text:="item" & i & String$(30, "x")) Next Command1.Caption = "Enable TreeView Tooltips" End Sub

Private Sub Command1_Click Dim hwndTT As Long Dim dwStyle As Long ' Get the handle of the TreeView's tooltip window hwndTT = SendMessage(TreeView1.hWnd, TVM_GETTOOLTIPS, 0, 0) If hwndTT Then ' If the tooltip window is disabled, enable it. If (GetWindowLong(hwndTT, GWL_STYLE) And WS_DISABLED) Then Call EnableWindow(hwndTT, 1) End If  End If

' All done... Command1.Enabled = False End Sub </li> From the File menu, choose Make Project1.exe.</li> Run the compiled executable and display Form2 both non-modally and modally, placing the cursor over TreeView Node text.

NOTE: When displayed modally the tooltip window flashes unless the TreeView Node tooltip window is enabled by clicking the CommandButton.</li></ol>

<div class="references_section">