Sign in to follow this  
Followers 0
matwachich

ListBox - ToolTip for long items

9 posts in this topic

Hello guys!

I've got a simple question:

- Is it possible to display a ToolTip on ListBox Item?

- I want to display it when an Item is too long for the ListBox width, and a part of it is hidden (Just like a ListView does, but for a ListBox)

Thanks!

Share this post


Link to post
Share on other sites



Here is an attempt at having tool tips on the long list box items.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Example()


Func Example()
    Local $MESSAGE = "The following buttons have been clicked.|line 3."
    Local $add, $clear, $mylist, $close, $msg, $tt = 0
    Local $iListBoxWidth = 23 ; Number of characters that will fit in lost box width.
    Static $iNum = 1
    Local $hGui = GUICreate("My GUI list") ; will create a dialog box that when displayed is centered

    $add = GUICtrlCreateButton("Add", 64, 32, 75, 25)
    $clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25)
    $mylist = GUICtrlCreateList("buttons that have been clicked", 176, 32, 143, 97, BitOR($WS_BORDER, $WS_VSCROLL))
    GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling
    GUICtrlSetData(-1, $MESSAGE)
    $close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25)

    GUISetState()

    $msg = 0
    While $msg <> -3 ; $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        $aCI = GUIGetCursorInfo($hGui)
        If $tt = 1 And $aCI[4] <> $mylist Then
            $tt = 0
            ToolTip("")
        EndIf
        Select
            Case $msg = $add
                GUICtrlSetData($mylist, "Add button clicked No" & $iNum)
                $iNum += 1
            Case $msg = $clear
                GUICtrlSetData($mylist, "")
            Case $msg = $close
                MsgBox(0, "", "the closing button has been clicked", 2)
                Exit
            Case $msg = $mylist
                If StringLen(GUICtrlRead($mylist)) > $iListBoxWidth Then
                    ToolTip(GUICtrlRead($mylist))
                    $tt = 1
                Else
                    ToolTip("")
                    $tt = 0
                EndIf
        EndSelect
    WEnd
EndFunc   ;==>Example

Share this post


Link to post
Share on other sites

Thanks for the answer.

But it's not really what i'm looking for.

I want the toolTips to display when i hover the long item, because the clique event is already used.

Thanks

Share this post


Link to post
Share on other sites

Here is an example at having a tool tip appear when hovering over a long, list box item.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListBox.au3>
#include <GUIConstantsEx.au3>

Example()


Func Example()
    Local $MESSAGE = "The following buttons have been clicked.|line 3."
    Local $add, $clear, $mylist, $close, $msg

    ; --- Variables for Tool Tip Hover ---
    Local $aCI, $iIndex, $sText, $tt = 0
    Local $iListBoxWidth = 23 ; Number of characters that will fit in lost box width.
    ; -------------------------------------

    Local $iNum = 1
    Local $hGui = GUICreate("My GUI list") ; will create a dialog box that when displayed is centered

    $add = GUICtrlCreateButton("Add", 64, 32, 75, 25)
    $clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25)
    $mylist = GUICtrlCreateList("buttons that have been clicked", 176, 32, 143, 97, BitOR($WS_BORDER, $WS_VSCROLL))
    GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling
    GUICtrlSetData(-1, $MESSAGE)
    $close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25)

    GUISetState()

    $msg = 0
    While $msg <> -3 ; $GUI_EVENT_CLOSE

        ;--- Tool Tip when hover over list box item with greater than '$iListBoxWidth' characters ---
        $aCI = GUIGetCursorInfo($hGui)
        If $aCI[4] = $mylist Then
            $iIndex = _GUICtrlListBox_ItemFromPoint($mylist, $aCI[0] - 176, $aCI[1] - 32)
            $sText = _GUICtrlListBox_GetText($mylist, $iIndex)
            If StringLen($sText) > $iListBoxWidth Then
                ToolTip($sText)
                $tt = 1
            Else
                ToolTip("")
                $tt = 0
            EndIf
        EndIf
        If $tt = 1 And $aCI[4] <> $mylist Then
            $tt = 0
            ToolTip("")
        EndIf
        ; -------- End of Tool Tip Hover ---------------

        $msg = GUIGetMsg()
        Select
            Case $msg = $add
                GUICtrlSetData($mylist, "Add button clicked No" & $iNum)
                $iNum += 1
            Case $msg = $clear
                GUICtrlSetData($mylist, "")
            Case $msg = $close
                MsgBox(0, "", "the closing button has been clicked", 2)
                Exit
        EndSelect
    WEnd
EndFunc   ;==>Example

Share this post


Link to post
Share on other sites

Thank you so much Malkey! ;)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Tip in item position

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListBox.au3>

Example()

Func Example()
    Local $MESSAGE = "The following buttons have been clicked.|line 3."
    Local $add, $clear, $mylist, $close, $msg, $aRect, $tRect, $iTmpMouseY, $hListBox

    ; --- Variables for Tool Tip Hover ---
    Local $aCI, $iIndex, $sText, $tt = 0
    Local $iListBoxWidth = 23 ; Number of characters that will fit in lost box width.
    ; -------------------------------------

    Local $iNum = 1
    Local $hGui = GUICreate("My GUI list") ; will create a dialog box that when displayed is centered

    $add = GUICtrlCreateButton("Add", 64, 32, 75, 25)
    $clear = GUICtrlCreateButton("Clear", 64, 72, 75, 25)
    $mylist = GUICtrlCreateList("buttons that have been clicked", 176, 32, 143, 97, BitOR($WS_BORDER, $WS_VSCROLL))
    GUICtrlSetLimit(-1, 200) ; to limit horizontal scrolling
    GUICtrlSetData(-1, $MESSAGE)
    $hListBox = GUICtrlGetHandle(-1)
    $close = GUICtrlCreateButton("my closing button", 64, 160, 175, 25)

    GUISetState()

    While 1

        ;--- Tool Tip when hover over list box item with greater than '$iListBoxWidth' characters ---
        $aCI = GUIGetCursorInfo($hGui)
        If $aCI[4] = $mylist And $iTmpMouseY <> $aCI[1] Then
            $iTmpMouseY = $aCI[1]
            $iIndex = _GUICtrlListBox_ItemFromPoint($hListBox, $aCI[0] - 176, $aCI[1] - 32)
            $sText = _GUICtrlListBox_GetText($hListBox, $iIndex)
            If StringLen($sText) > $iListBoxWidth Then
                $aRect = _GUICtrlListBox_GetItemRect($hListBox, $iIndex)
                $tRect = _WinAPI_GetWindowRect($hListBox)
                ToolTip($sText, $aRect[0] + DllStructGetData($tRect, "Left"), $aRect[3] + 3 + DllStructGetData($tRect, "Top"))
                $tt = 1
            Else
                ToolTip("")
                $tt = 0
            EndIf
        EndIf
        If $tt = 1 And $aCI[4] <> $mylist Then
            $tt = 0
            ToolTip("")
        EndIf
        ; -------- End of Tool Tip Hover ---------------

        $msg = GUIGetMsg()
        Switch $msg
            Case $add
                GUICtrlSetData($mylist, "121221367456 Add button clicked No" & $iNum)
            Case $clear
                GUICtrlSetData($mylist, "")
            Case $close
                MsgBox(0, "", "the closing button has been clicked", 2)
                Exit
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>Example
Edited by AZJIO

Share this post


Link to post
Share on other sites

Thanks!

Share this post


Link to post
Share on other sites

First of all sorry for "necro" post!

I just do not wanted to make a new topic with nearly same question, what was solved here.

My question is the same as the original topic maker, but with TreeView. Does it posible to put a tooltip on all TreeView item? (like a short description on them) or better to make a little memo next to the TreeView and write there the description for the selected element?


Sry for my bad English, and double sry, but I am learning AutoIT language by myself. :)

[u]Tricky[/u]

You can't teach a man anything, you can only help him, find it within himself. (Galileo Galilei)

Share this post


Link to post
Share on other sites

TrickyDeath,

 

My question is the same as the original topic

No it is not - it is about a completely different control. So please start a new thread and do not hijack this one. :naughty:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0

  • Similar Content

    • hcI
      By hcI
      Hello
      Today I'm working on listbox but there might be something that I'm missing...
      I made a little script that allow the user to swap 2 items for the listbox. So the user select for example the 3rd item, press the button "Up" and it switch with the 2nd one, same with the "Down" button that switch with the 4th one.
      But when I select the 3rd item and switch it the item become unselected and I would like to select it again after the manipulation :
      As you can see in the comment of the script, _GUICtrlListBox_SetSel don't highlight/select them once the swap process is done..
      What am I missing ?
    • UEZ
      By UEZ
      Here a small tool I wrote to update my Sysinternal tools collection without the need to download always the whole package or visiting the site to check for updates. I know that there are several tools available (also some tools written in AutoIt) but here another one for the collection. It was good exercise for me to code it.
       
       
        
       
       
      Some files from cannot be downloaded although they are visible on the web site!
       
      Here the download link of the source code only: AutoIt Sysinternal Tools Synchronizer v0.99.1 build 2017-10-23 beta.7z  (1353 downloads previously)
      -=> Requires AutoIt version 3.3.13.20 or higher / tested on Win8.1 real machine and some VMs: Win7 / Vista / Win10
       
      Compiled exe only: @MediaFire
       
      Just select the Sysinternal Tools folder or create one and press the synchronize button to download the selected items. Click on AutoIt label (near to left upper corner) to open menu.
       
      Special thanks to LarsJ, Melba23 and mesale0077 for their help. 
       
      I've still some ideas to implement which are more gimmick related, so it is not finished yet...
      If you want to add your language please check out #Region Language. Thanks. 
       
      Please report any bug or if you have any suggestions.
       
      The language of the tool tip from each of the executable in the left list view were automatically created using Google translator and weren't checked for correctness.
       
      Br,
      UEZ
    • GordonFreeman
      By GordonFreeman
      Hi, i searched some topics but cannot found a simple way to do that:
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 615, 438, 192, 124) GUISetState(@SW_SHOW) ; I tried this but user reported that it work in 2006, not seems work actually $filemenu = GUICtrlCreateMenu ("&File") $fileitem = GUICtrlCreateMenuitem ("Open",$filemenu) GuiCtrlSetImage($fileitem, "shell32.dll", 4) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Also tried:
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 615, 438, 192, 124) GUISetState(@SW_SHOW) $filemenu = TrayCreateMenu("&File") $fileitem = TrayCreateItem("Open",$filemenu) ;GuiCtrlSetImage($fileitem, "shell32.dll", 4) ;GuiCtrlSetImage(TrayItemGetHandle($fileitem), "shell32.dll", 4) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Well.. thanks in advance!
       
      Ok. I found this working example from Yashied. If i cannot find a simple then i will go with it
      #Include <GUIConstantsEx.au3> #Include <GUIMenu.au3> #Include <Constants.au3> #Include <WinAPI.au3> #Include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Global $hMenu, $hForm, $hFile = 1000, $idNew, $idExit $hForm = GUICreate('Menu', 400, 300) $hFile = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_InsertMenuItem ($hFile, 0, ' &Favorites', $idNew) _GUICtrlMenu_InsertMenuItem ($hFile, 1, '', 0) _GUICtrlMenu_InsertMenuItem($hFile, 2, ' E&xit', $idExit) $hMenu = _GUICtrlMenu_CreateMenu() _GUICtrlMenu_InsertMenuItem($hMenu, 0, '&File', 0, $hFile) _GUICtrlMenu_SetMenu($hForm, $hMenu) _GUICtrlMenu_SetItemBmp($hFile, 0, _CreateBitmapFromIcon(_WinAPI_GetSysColor($COLOR_MENU), @SystemDir & '\shell32.dll', 43, 16, 16)) _GUICtrlMenu_SetItemBmp($hFile, 2, _CreateBitmapFromIcon(_WinAPI_GetSysColor($COLOR_MENU), @SystemDir & '\shell32.dll', 27, 16, 16)) GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func _CreateBitmapFromIcon($iBackground, $sIcon, $iIndex, $iWidth, $iHeight) Local $hDC, $hBackDC, $hBackSv, $hIcon, $hBitmap $hDC = _WinAPI_GetDC(0) $hBackDC = _WinAPI_CreateCompatibleDC($hDC) $hBitmap = _WinAPI_CreateSolidBitmap(0, $iBackground, $iWidth, $iHeight) $hBackSv = _WinAPI_SelectObject($hBackDC, $hBitmap) $hIcon = _WinAPI_PrivateExtractIcon($sIcon, $iIndex, $iWidth, $iHeight) If Not @error Then _WinAPI_DrawIconEx($hBackDC, 0, 0, $hIcon, 0, 0, 0, 0, $DI_NORMAL) _WinAPI_DestroyIcon($hIcon) EndIf _WinAPI_SelectObject($hBackDC, $hBackSv) _WinAPI_ReleaseDC(0, $hDC) _WinAPI_DeleteDC($hBackDC) Return $hBitmap EndFunc ;==>_CreateBitmapFromIcon Func _WinAPI_PrivateExtractIcon($sIcon, $iIndex, $iWidth, $iHeight) Local $hIcon, $tIcon = DllStructCreate('hwnd'), $tID = DllStructCreate('hwnd') Local $Ret = DllCall('user32.dll', 'int', 'PrivateExtractIcons', 'str', $sIcon, 'int', $iIndex, 'int', $iWidth, 'int', $iHeight, 'ptr', DllStructGetPtr($tIcon), 'ptr', DllStructGetPtr($tID), 'int', 1, 'int', 0) If (@error) Or ($Ret[0] = 0) Then Return SetError(1, 0, 0) EndIf $hIcon = DllStructGetData($tIcon, 1) If ($hIcon = Ptr(0)) Or (Not IsPtr($hIcon)) Then Return SetError(1, 0, 0) EndIf Return $hIcon EndFunc ;==>_WinAPI_PrivateExtractIcon Ok, i noticed that is a pain create submenu with _GUICtrlMenu_CreatePopup to do like in Tray, and Tray better located, then i need images/icon with Tray functions, some workaround?? 
    • Daka
      By Daka
      I know there are listbox and listview, but now I have?
      here is the video of infowindow 
      I tried to read mouse selection like for listbox:
      $listWindow = "[CLASS:TFormResearchGR]" $topicsList = "[CLASS:TMWrapper; INSTANCE:255]" WinWait($listWindow, "", 60) $hdlWindow = WinGetHandle($listWindow) $hdlList = ControlGetHandle($hdlWindow, "", $topicsList) _GUICtrlListBox_ClickItem($hdlList, 0, "left") $countOfList = _GUICtrlListBox_GetCount($hdlList) ConsoleWrite("Count of list: " & $countOfList & @LF) count of list is not working.
      I realiezed that there are difference between listbox and listview, but this is something different.
      and till now I never saw that you can go inside with infotool and also get instances.
       
      so Im confused how to get the list number and the names of selection?
    • nacerbaaziz
      By nacerbaaziz
      hello guys
      how are you؟
      I hope to be fine.
      I have a question  please
      how do I get the menu item that was pressed without that contains a variable؟
      For example I have a menu  of Favorites and I want the script recognizes the existing path in the pressed item
      i'll repeat to tell the item does not contain a variable
      Is there any solution
      if you want to explain more I could write an example of what I want.
      Greetings to all,
      thanks in advance