Jump to content

Treeview with tooltip


Recommended Posts

Hi all,

I got a treeview which load things from an ini but i'm trying to display the tooltip on the subitem only.

I have tried to merge both array but it doesn't work good.

How can I do this because it keep crashing when i'm getting over the main item.

The code :

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <Array.au3>
#include <GuiTreeView.au3>

GUICreate("Treview test with Array and ToolTip", 800, 600)

$mainT = GUICtrlCreateTreeView(150, 10, 600, 500)
$Thandle = GUICtrlGetHandle($mainT)

GUISetState()

$var = IniReadSectionNames("DB.ini")

If @error Then
    MsgBox(4096, "", "Error occurred, probably no INI file.")
    Else
    For $i = 1 to $var[0]
        $var1 = IniReadSection("DB.ini", $var[$i])
        $mainTitem = GUICtrlCreateTreeViewItem(($var[$i]), $mainT)

        For $x = 1 to $var1[0][0]
            GUICtrlCreateTreeViewItem(($var1[$x][0]), $mainTitem)
        Next

    Next
EndIf

While 1
    Switch GUIGetMsg()

        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case $GUI_EVENT_MOUSEMOVE
            SetTip()

    EndSwitch
WEnd

Func SetTip()
    If @AutoItX64 Then
        Local $tPoint = DllStructCreate('int X;int Y')
        DllStructSetData ( $tPoint, 'X', MouseGetPos(0))
        DllStructSetData ( $tPoint, 'Y', MouseGetPos(1))
        Local $tPoint64 = DllStructCreate('int64', DllStructGetPtr($tPoint))
        Local $aHwnd = DllCall('user32.dll', 'hwnd', 'WindowFromPoint', 'int64', DllStructGetData($tPoint64, 1))
    Else
        Local $aHwnd = DllCall('user32.dll', 'hwnd', 'WindowFromPoint', 'uint', MouseGetPos(0), 'uint', MouseGetPos(1))
    EndIf
    Switch $aHwnd[0]
        Case $Thandle
            $tMPos = _WinAPI_GetMousePos(True, $aHwnd[0])
            $hItem = _GUICtrlTreeView_HitTestItem($aHwnd[0], DllStructGetData($tMPos, 1), DllStructGetData($tMPos, 2))
            $sText = _GUICtrlTreeView_GetText($aHwnd[0], $hItem)
            $iIndex = _ArraySearch($var1, $sText, 0, 0, 0, 0, 1, 1)
            $sText = $var1[$iIndex][1]
            If $hItem = 0 Then
                ToolTip('')
            Else
                ToolTip($sText)
            EndIf
        Case Else
            ToolTip('')
    EndSwitch
EndFunc
Db.ini :

[[EMBED...]]
SRC=URL of resource to be embedded
WIDTH=Width of area in which to show resource
HEIGHT=Height of area in which to show resource
...
...
Thank you ! Edited by Jayson
Link to comment
Share on other sites

Change this section:

Switch $aHwnd[0]
        Case $Thandle
            $tMPos = _WinAPI_GetMousePos(True, $aHwnd[0])
            $hItem = _GUICtrlTreeView_HitTestItem($aHwnd[0], DllStructGetData($tMPos, 1), DllStructGetData($tMPos, 2))
            $sText = _GUICtrlTreeView_GetText($aHwnd[0], $hItem)
            $iIndex = _ArraySearch($var1, $sText, 0, 0, 0, 0, 1, 0)
            If @error Then Return ; <<<<<<<<<<<<<<<<<<<<<<<<<<<< Add this line
            $sText = $var1[$iIndex][1]
            If $hItem = 0 Then
                ToolTip('')
            Else
                ToolTip($sText)
            EndIf
        Case Else
            ToolTip('')
    EndSwitch

The problem was happening because when you're not over one of the treeview items, it reads the header and the header text isn't in the $var1 array so it comes back with $iIndex = -1.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I'm glad I could help, besides it's fun to try something new.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Hi again, I ran into another problem/bug?.. Well i'm not sure but i'll explain.

When I am filling the treeview by my ini loaded in array theres only 2 parts working the [A ...] & [AREA ...] subitem displaying tooltip correctly even on duplicated one.

DB.ini

[A ...]
HREF=URL you are linking to.
NAME=Name a section of the page.
TARGET=_blank | _parent | _self | _top | window name
TITLE=Suggested title for the document to be opened.
onclick=Script to run when the user clicks on this anchor.
onmouseover=When the mouse is over the link.
onmouseout=When the mouse is no longer over the link.
[ADDRESS]
address=t
[APP ...]
app=t
[APPLET ...]    
CODE=The applet to run.
CODEBASE=Path to the applet class
WIDTH=Width of the applet
HEIGHT=Height of the applet
ALIGN=LEFT | RIGHT | TOP | MIDDLE | BOTTOM | BASELINE
VSPACE=vertical space between applet and surrounding text
HSPACE=horizontal space between applet and surrounding text
BORDER=empty space surrounding the applet
NAME=name of applet for reference by other applets
ARCHIVE=a compressed collection of applet components
MAYSCRIPT=If Java can use Javascript
[AREA ...]  
HREF=URL you are linking to
ALT=alternate text if the image isn't displayed
SHAPE=RECT | CIRCLE | POLY | DEFAULT
COORDS=coordinates for the link area shape
TITLE=Short description of the area
TARGET=what frame to go to
NOHREF=this area is not a link
onclick=script action when the user clicks this area
onmouseover=t
onmouseout=t
[A ...]
HREF=URL you are linking to.
NAME=Name a section of the page.
TARGET=_blank | _parent | _self | _top | window name
TITLE=Suggested title for the document to be opened.
onclick=Script to run when the user clicks on this anchor.
onmouseover=When the mouse is over the link.
onmouseout=When the mouse is no longer over the link.
[ADDRESS]
address=t
[APP ...]
app=t
[APPLET ...]    
CODE=The applet to run.
CODEBASE=Path to the applet class
WIDTH=Width of the applet
HEIGHT=Height of the applet
ALIGN=LEFT | RIGHT | TOP | MIDDLE | BOTTOM | BASELINE
VSPACE=vertical space between applet and surrounding text
HSPACE=horizontal space between applet and surrounding text
BORDER=empty space surrounding the applet
NAME=name of applet for reference by other applets
ARCHIVE=a compressed collection of applet components
MAYSCRIPT=If Java can use Javascript
[AREA ...]  
HREF=URL you are linking to
ALT=alternate text if the image isn't displayed
SHAPE=RECT | CIRCLE | POLY | DEFAULT
COORDS=coordinates for the link area shape
TITLE=Short description of the area
TARGET=what frame to go to
NOHREF=this area is not a link
onclick=script action when the user clicks this area
onmouseover=t
onmouseout=t
[A ...]
HREF=URL you are linking to.
NAME=Name a section of the page.
TARGET=_blank | _parent | _self | _top | window name
TITLE=Suggested title for the document to be opened.
onclick=Script to run when the user clicks on this anchor.
onmouseover=When the mouse is over the link.
onmouseout=When the mouse is no longer over the link.
[ADDRESS]
address=t
[APP ...]
app=t
[APPLET ...]    
CODE=The applet to run.
CODEBASE=Path to the applet class
WIDTH=Width of the applet
HEIGHT=Height of the applet
ALIGN=LEFT | RIGHT | TOP | MIDDLE | BOTTOM | BASELINE
VSPACE=vertical space between applet and surrounding text
HSPACE=horizontal space between applet and surrounding text
BORDER=empty space surrounding the applet
NAME=name of applet for reference by other applets
ARCHIVE=a compressed collection of applet components
MAYSCRIPT=If Java can use Javascript
[AREA ...]  
HREF=URL you are linking to
ALT=alternate text if the image isn't displayed
SHAPE=RECT | CIRCLE | POLY | DEFAULT
COORDS=coordinates for the link area shape
TITLE=Short description of the area
TARGET=what frame to go to
NOHREF=this area is not a link
onclick=script action when the user clicks this area
onmouseover=t
onmouseout=t
I have not modified any code from the first post but added your line.
Link to comment
Share on other sites

I've altered your code so that it will do as you're expecting.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <Array.au3>
#include <GuiTreeView.au3>
Global $var2[1][2] ; <<<<<<<<<<<<<<<< Added this variable
GUICreate("Treeview test with Array and ToolTip", 800, 600)

$mainT = GUICtrlCreateTreeView(150, 10, 600, 500)
$Thandle = GUICtrlGetHandle($mainT)

GUISetState()

$var = IniReadSectionNames("DB.ini")
If @error Then
    MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
    For $i = 1 To $var[0]
        $var1 = IniReadSection("DB.ini", $var[$i])
        $mainTitem = GUICtrlCreateTreeViewItem(($var[$i]), $mainT)
        For $x = 1 To $var1[0][0]
            GUICtrlCreateTreeViewItem(($var1[$x][0]), $mainTitem)
        Next
                ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Added this section of code
        $Start = UBound($var2)
        ReDim $var2[UBound($var2) + UBound($var1)][2]
        For $z = $Start To UBound($var2) - 1
            $var2[$z][0] = $var1[$z - $Start][0]
            $var2[$z][1] = $var1[$z - $Start][1]
        Next
                ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Next
EndIf
While 1
    Switch GUIGetMsg()

        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case $GUI_EVENT_MOUSEMOVE
            SetTip()

    EndSwitch
WEnd

Func SetTip()
    If @AutoItX64 Then
        Local $tPoint = DllStructCreate('int X;int Y')
        DllStructSetData($tPoint, 'X', MouseGetPos(0))
        DllStructSetData($tPoint, 'Y', MouseGetPos(1))
        Local $tPoint64 = DllStructCreate('int64', DllStructGetPtr($tPoint))
        Local $aHwnd = DllCall('user32.dll', 'hwnd', 'WindowFromPoint', 'int64', DllStructGetData($tPoint64, 1))
    Else
        Local $aHwnd = DllCall('user32.dll', 'hwnd', 'WindowFromPoint', 'uint', MouseGetPos(0), 'uint', MouseGetPos(1))
    EndIf
    Switch $aHwnd[0]
        Case $Thandle
            $tMPos = _WinAPI_GetMousePos(True, $aHwnd[0])
            $hItem = _GUICtrlTreeView_HitTestItem($aHwnd[0], DllStructGetData($tMPos, 1), DllStructGetData($tMPos, 2))
            $sText = _GUICtrlTreeView_GetText($aHwnd[0], $hItem)
            $iIndex = _ArraySearch($var2, $sText, 0, 0, 0, 0, 1, 0) ;<<<<<<<<<<<<< Changed this to use $var2 
            If @error Then Return
            $sText = $var2[$iIndex][1] ; <<<<<<<<<<<<<<< Changed this to use $var2
            If $hItem = 0 Then
                ToolTip('')
            Else
                ToolTip($sText)
            EndIf
        Case Else
            ToolTip('')
    EndSwitch
EndFunc   ;==>SetTip

Your original code was only getting the last value of $var1 when it came out of the TV building loop so that is why it wouldn't show tooltips for all of the elements in the TV. I created a new array to grab the current contents of $var1 during each loop and then added the new contents the next time through the loop until it finished. The only thing I didn't account for is if you have elements with the same names, you will get the wrong tooltips because the array search will only return the first item found. You will see that with the tooltip from the onmouseover in section A... will show up for every onmouseover element you have in the treeview, as an example.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

For the elements with the same names I might found a way but its not very efficiency. I've tested by adding a space char (ALT+0160) It does the trick but original space don't.

This way I would get the right tooltip but it will takes some time to change all of them. I'll try to crush my head to find a better way to detect duplicated names.

Thank you for taking your time to help me Posted Image

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...