Microsoft KB Archive/241102

= BUG: Node Tooltips Fail to Appear When TreeView Is Sited on UserControl =

Article ID: 241102

Article Last Modified on 9/27/2004

-

APPLIES TO

 Microsoft Visual Basic 5.0 Learning Edition, when used with:  Microsoft Windows NT 4.0

 Microsoft Windows 95

 Microsoft Windows 98 Standard Edition

 Microsoft Windows Millennium Edition</li></ul> </li> Microsoft Visual Basic 6.0 Learning Edition, when used with:  Microsoft Windows NT 4.0</li></ul>

 Microsoft Windows 95</li></ul>

 Microsoft Windows 98 Standard Edition</li></ul>

 Microsoft Windows Millennium Edition</li></ul> </li> Microsoft Visual Basic 5.0 Professional Edition, when used with:  Microsoft Windows NT 4.0</li></ul>

 Microsoft Windows 95</li></ul>

 Microsoft Windows 98 Standard Edition</li></ul>

<ul> <li>Microsoft Windows Millennium Edition</li></ul> </li> <li>Microsoft Visual Basic 6.0 Professional Edition, when used with: <ul> <li>Microsoft Windows NT 4.0</li></ul>

<ul> <li>Microsoft Windows 95</li></ul>

<ul> <li>Microsoft Windows 98 Standard Edition</li></ul>

<ul> <li>Microsoft Windows Millennium Edition</li></ul> </li> <li>Microsoft Visual Basic 5.0 Enterprise Edition, when used with: <ul> <li>Microsoft Windows NT 4.0</li></ul>

<ul> <li>Microsoft Windows 95</li></ul>

<ul> <li>Microsoft Windows 98 Standard Edition</li></ul>

<ul> <li>Microsoft Windows Millennium Edition</li></ul> </li> <li>Microsoft Visual Basic 6.0 Enterprise Edition, when used with: <ul> <li>Microsoft Windows NT 4.0</li></ul>

<ul> <li>Microsoft Windows 95</li></ul>

<ul> <li>Microsoft Windows 98 Standard Edition</li></ul>

<ul> <li>Microsoft Windows Millennium Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q241102

<div class="symptoms_section">

SYMPTOMS
A TreeView control from either Comctl32.ocx or Mscomctl.ocx is sited on a UserControl. The TreeView's Node tooltip (item tip) fails to appear when the mouse cursor is positioned over a Node whose text is obscured by the TreeView's right client window edge.

<div class="resolution_section">

RESOLUTION
After the TreeView control is sited on the UserControl, remove the tooltips from the TreeView by setting its TVS_NOTOOLTIPS style bit. Then add tooltips back to the TreeView by removing the style bit. The tooltip window's parent window is now, correctly, the top level application window in which the UserControl is sited. This operation can be performed in either the UserControl's Show event, or after the Form's Load event, where you are certain that the TreeView control is sited on the UserControl.

<div class="status_section">

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

<div class="moreinformation_section">

MORE INFORMATION
NOTE: This workaround is not effective when running under Windows NT 4.0 and the installed version of Comctl32.dll is 4.x or lower. Under these circumstances, implement the workaround described in Microsoft Knowledge Base article Q241097 shown in the "References" section below.

Steps to Reproduce Problem
<ol> <li>Start a new Visual Basic Standard EXE project. Form1 is created by default.</li> <li>On the Project menu, click Add UserControl to add a UserControl to Project1.</li> <li>On the Project menu, click Components. Check either Microsoft Windows Common Controls 5.0 or 6.0 and click OK.</li> <li>Add a CommandButton, TreeView, and Label control to UserControl11. Resize the Label so that it is large enough to contain four lines of 50 characters each, and the TreeView control is narrow enough to obscure part of the 35 characters of Node Text. Position the TreeView control on the right-hand edge of UserControl1.</li> <li> Add the following code to the General Declarations section of UserControl1: Option Explicit

' TreeView window style specifying that the TreeView control does ' not have an item tip tooltip window. An IE3 or later definition. Private Const TVS_NOTOOLTIPS = &H80

Private Const GWL_STYLE = (-16)

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

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _ (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Private Sub UserControl_Initialize Dim i As Integer Label1.WordWrap = True Label1.Caption = "The TreeView's tooltip window will " _ & "not appear in front of the TreeView unless it is higher in the " _ & "z-order than the TreeView. Run the project, and before clicking " _ & "the button below, notice that the TreeView's item tip tooltip " _ & "appears behind the form." Command1.Caption = "Fix TreeView Tooltip" ' Fill up the TreeView... For i = 1 To 10 Call TreeView1.Nodes.Add(Text:="item" & i & String$(30, "x")) Next i End Sub

' Correctly set the TreeView item tip tooltip window's parent window to ' that of the top level client app window, by first telling the TreeView ' to remove (and destroy) its tooltip window, then add a new tooltip ' window back. ' Can either be called in UserControl_Show, or after Form_Load.

Private Sub Command1_Click Dim dwStyle As Long

' Get the TreeView's window style dwStyle = GetWindowLong(TreeView1.hWnd, GWL_STYLE)

' If the TreeView does not have the TVS_NOTOOLTIPS bit set, ' set it, removing and destroying the TreeView's tooltip window. If (dwStyle And TVS_NOTOOLTIPS) = False Then Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, _                        dwStyle Or TVS_NOTOOLTIPS) End If

' Tell the TreeView to create a new tooltip window, whose parent ' window will now become the top level client app window Call SetWindowLong(TreeView1.hWnd, GWL_STYLE, _                     dwStyle And Not TVS_NOTOOLTIPS) ' Done... Command1.Enabled = False End Sub </li> <li>Close all of the windows for the UserControl Project, and site UserControl1 on Form1. Position UserControl11 at the right-hand edge of Form1.</li> <li>Run the project, and place the cursor over a Node item. Note that the tooltip is obscured by the form.</li> <li>Click the CommandButton, and repeat the previous step. The tooltip is now displayed properly.</li></ol>

<div class="references_section">