Trolleule

Show ToolTip when hovering over listview group

4 posts in this topic

#1 ·  Posted (edited)

Hi,

i want to display a tooltip when i hover over the listview group. It sounds not difficult but i couldn't find a solution and i searched for autoit as well as for c# :/

So i came up with a not so pretty solution:

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <GuiToolTip.au3>
#include <WinAPI.au3>

Global $idListview, $hWndListView
Global $hToolTip = _GUIToolTip_Create(0, BitOR($_TT_ghTTDefaultStyle, $TTS_BALLOON)); balloon style tooltip
Global Const $LVN_GROUPINFO = ($LVN_FIRST - 88)
Global Const $tagNMLVGROUP = $tagNMHDR & ";int iGroupId;uint iNewState;uint iOldState"
;                                                            $LVGS_flags    $LVGS_flags

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
  #forceref $hWnd, $iMsg, $wParam
  Local $tInfo, $tNMHDR = DllStructCreate($tagNMHDR, $lParam), $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
  Local $iIDFrom = DllStructGetData($tNMHDR, "IDFrom"), $iCode = DllStructGetData($tNMHDR, "Code")
  Switch $hWndFrom
    Case $hWndListView
      Switch $iCode

        ; Case $of?????? ; A Group was clicked       <---- I need help with this
          Case $LVN_GROUPINFO
              ConsoleWrite("hier" & @CRLF)
          $tInfo = DllStructCreate($tagNMLVGROUP, $lParam)
          _DebugPrint("$LVN_GROUPINFO" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
            "-->Code:" & @TAB & $iCode & @CRLF & _
            "-->GroupId:" & @TAB & DllStructGetData($tInfo, "iGroupId") & @CRLF & _
            "-->NewState:" & @TAB & DllStructGetData($tInfo, "iNewState") & @CRLF & _
            "-->OldState:" & @TAB & DllStructGetData($tInfo, "iOldState"))

        Case $LVN_COLUMNCLICK ; A column was clicked
          $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
          _DebugPrint("$LVN_COLUMNCLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
            "-->Code:" & @TAB & $iCode & @CRLF & _
            "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @CRLF & _
            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
            "-->Param:" & @TAB & DllStructGetData($tInfo, "Param"))
          ; No return value

        Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
          $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
          _DebugPrint("$NM_CLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
            "-->Code:" & @TAB & $iCode & @CRLF & _
            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _
            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _
            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
          ; No return value

      EndSwitch
  EndSwitch
  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @CRLF & _
            "+======================================================" & @CRLF & _
            "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
            "+======================================================" & @CRLF)
EndFunc   ;==>_DebugPrint

If Not StringInStr($CmdLineRaw, "/ErrorStdOut") Then Exit MsgBox($MB_TOPMOST, @ScriptName, 'please run from the editor, thanks', 10)

Example()

Func Example()
    Local $aInfo, $hImage, $idListview

    $ghui = GUICreate("ListView Group COLLAPSIBLE", 400, 300)

    $idListview = GUICtrlCreateListView("", 30, 20, 354, 218);, BitOR($LVS_SHOWSELALWAYS, $LVS_SINGLESEL, $LVS_REPORT, $WS_CLIPSIBLINGS))
    $hWndListView = GUICtrlGetHandle($idListview)

    ; Load images
    $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, 0xFF0000, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, 0x00FF00, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, 0x0000FF, 16, 16))
    _GUICtrlListView_SetImageList($idListview, $hImage, 1)

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Column 1", 100)
    _GUICtrlListView_AddColumn($idListview, "Column 2", 100)
    _GUICtrlListView_AddColumn($idListview, "Column 3", 100)

    ; Add items
    _GUICtrlListView_AddItem($idListview, "Row 1: Col 1", 0)
    _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 2", 1)
    _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 3", 2)
    _GUICtrlListView_AddItem($idListview, "Row 2: Col 1", 1)
    _GUICtrlListView_AddSubItem($idListview, 1, "Row 2: Col 2", 1)
    _GUICtrlListView_AddItem($idListview, "Row 3: Col 1", 2)

    ; Build groups
    _GUICtrlListView_EnableGroupView($idListview)
    _GUICtrlListView_InsertGroup($idListview, -1, 1, "Group 1", 1)
;~     _GUICtrlListView_SetGroupInfo($idListview, 1, "Group 1", 0, $LVGS_COLLAPSIBLE + $LVGS_COLLAPSED) ; <---
    _GUICtrlListView_InsertGroup($idListview, -1, 2, "Group 2")
;~     _GUICtrlListView_SetGroupInfo($idListview, 2, "Group 2", 0, $LVGS_COLLAPSIBLE + $LVGS_COLLAPSED) ; <---
    _GUICtrlListView_SetItemGroupID($idListview, 0, 1)
    _GUICtrlListView_SetItemGroupID($idListview, 1, 2)
    _GUICtrlListView_SetItemGroupID($idListview, 2, 2)

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    Local $apos = _GUICtrlListView_GetGroupRect($idListview, 2, $LVGGR_LABEL)


    Local $test = GUICtrlCreateLabel("a", 2, 2, 10, 17)
    Local $val = _WinAPI_GetWindowLong(GUICtrlGetHandle($test), $GWL_STYLE)
    Local $valex = _WinAPI_GetWindowLong(GUICtrlGetHandle($test), $GWL_EXSTYLE)
    Local $aha = _WinAPI_CreateWindowEx($valex+$WS_EX_LAYERED, "static", "blabla", $val, $apos[0], $apos[1], 50, 20, $hWndListView)
    
    _GUIToolTip_AddTool($hToolTip, $hWndListView, "This is a ToolTip3", $aha)
    

    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    GUIDelete()
EndFunc   ;==>Example

Short description: I only created a label with CreateWindowEx which i can append to the listview control and layered it with the $WS_EX_Layered flag so it looks like it's transparent. Then i only added a tooltip tool to that created label.

Hover over the Group 2 text and the Tooltip will be displayed. My question is: does someone know another perhaps much prettier solution?

Thanks in advance

Edited by Trolleule

Share this post


Link to post
Share on other sites



Like this? (I think I found it sometime ago in a forum post..... but forget where I found it once.....so I'm not the genius that help me out some time ago)

I added this stuff to your sample, without removing any call from your so a diff will show you the added code lines)

Take a look at :

in WM_NOTIFY: Case $LVN_HOTTRACK

And follow the trace to ListView_HOTTRACK and _ToolTipMouseExit

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <GuiToolTip.au3>
#include <WinAPI.au3>

Global $idListview, $hWndListView
Global $hToolTip = _GUIToolTip_Create(0, BitOR($_TT_ghTTDefaultStyle, $TTS_BALLOON)); balloon style tooltip
Global Const $LVN_GROUPINFO = ($LVN_FIRST - 88)
Global Const $tagNMLVGROUP = $tagNMHDR & ";int iGroupId;uint iNewState;uint iOldState"
;                                                            $LVGS_flags    $LVGS_flags

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
  #forceref $hWnd, $iMsg, $wParam
  Local $tInfo, $tNMHDR = DllStructCreate($tagNMHDR, $lParam), $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
  Local $iIDFrom = DllStructGetData($tNMHDR, "IDFrom"), $iCode = DllStructGetData($tNMHDR, "Code")
  Switch $hWndFrom
    Case $hWndListView
      Switch $iCode

        ; Case $of?????? ; A Group was clicked       <---- I need help with this
          Case $LVN_GROUPINFO
              ConsoleWrite("hier" & @CRLF)
          $tInfo = DllStructCreate($tagNMLVGROUP, $lParam)
          _DebugPrint("$LVN_GROUPINFO" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
            "-->Code:" & @TAB & $iCode & @CRLF & _
            "-->GroupId:" & @TAB & DllStructGetData($tInfo, "iGroupId") & @CRLF & _
            "-->NewState:" & @TAB & DllStructGetData($tInfo, "iNewState") & @CRLF & _
            "-->OldState:" & @TAB & DllStructGetData($tInfo, "iOldState"))

        Case $LVN_COLUMNCLICK ; A column was clicked
          $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
          _DebugPrint("$LVN_COLUMNCLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
            "-->Code:" & @TAB & $iCode & @CRLF & _
            "-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @CRLF & _
            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
            "-->Param:" & @TAB & DllStructGetData($tInfo, "Param"))
          ; No return value

        Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
          $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
          _DebugPrint("$NM_CLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
            "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
            "-->Code:" & @TAB & $iCode & @CRLF & _
            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _
            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _
            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
          ; No return value
          Case $LVN_HOTTRACK ; Sent by a list-view control when the user moves the mouse over an item
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                    ListView_HOTTRACK(DllStructGetData($tInfo, "SubItem"))
      EndSwitch
  EndSwitch
  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY


Func ListView_HOTTRACK($iSubItem)
    Local $HotItem = _GUICtrlListView_GetHotItem($hWndListView)
    If $HotItem <> -1 Then _ToolTipMouseExit("Mouse over item: " & $HotItem & " SubItem: " & $iSubItem & @CRLF & _
                                'Content: ' & _GUICtrlListView_GetItemText($hWndListView, $HotItem, $iSubItem), 1500)
EndFunc   ;==>ListView_HOTTRACK

Func _ToolTipMouseExit($TEXT, $TIME=-1, $x=-1, $y=-1, $TITLE='', $ICON=0, $OPT='')
    If $TIME = -1 Then $TIME = 3000
    Local $start = TimerInit(), $pos0 = MouseGetPos()
    If ($x = -1) Or ($y = -1) Then
        ToolTip($TEXT, $pos0[0], $pos0[1], $TITLE, $ICON, $OPT)
    Else
        ToolTip($TEXT, $x, $y, $TITLE, $ICON, $OPT)
    EndIf
    Do
        Sleep(50)
        $pos = MouseGetPos()
    Until (TimerDiff($start) > $TIME) Or _
        (Abs($pos[0] - $pos0[0]) > 10 Or _
         Abs($pos[1] - $pos0[1]) > 10)
    ToolTip('')
EndFunc ;_ToolTipMouseExit


Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @CRLF & _
            "+======================================================" & @CRLF & _
            "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
            "+======================================================" & @CRLF)
EndFunc   ;==>_DebugPrint

If Not StringInStr($CmdLineRaw, "/ErrorStdOut") Then Exit MsgBox($MB_TOPMOST, @ScriptName, 'please run from the editor, thanks', 10)

Example()

Func Example()
    Local $aInfo, $hImage, $idListview

    $ghui = GUICreate("ListView Group COLLAPSIBLE", 400, 300)

    $idListview = GUICtrlCreateListView("", 30, 20, 354, 218);, BitOR($LVS_SHOWSELALWAYS, $LVS_SINGLESEL, $LVS_REPORT, $WS_CLIPSIBLINGS))
    $hWndListView = GUICtrlGetHandle($idListview)

    ; Load images
    $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, 0xFF0000, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, 0x00FF00, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, 0x0000FF, 16, 16))
    _GUICtrlListView_SetImageList($idListview, $hImage, 1)

    ; Add columns
    _GUICtrlListView_AddColumn($idListview, "Column 1", 100)
    _GUICtrlListView_AddColumn($idListview, "Column 2", 100)
    _GUICtrlListView_AddColumn($idListview, "Column 3", 100)

    ; Add items
    _GUICtrlListView_AddItem($idListview, "Row 1: Col 1", 0)
    _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 2", 1)
    _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 3", 2)
    _GUICtrlListView_AddItem($idListview, "Row 2: Col 1", 1)
    _GUICtrlListView_AddSubItem($idListview, 1, "Row 2: Col 2", 1)
    _GUICtrlListView_AddItem($idListview, "Row 3: Col 1", 2)

    ; Build groups
    _GUICtrlListView_EnableGroupView($idListview)
    _GUICtrlListView_InsertGroup($idListview, -1, 1, "Group 1", 1)
;~     _GUICtrlListView_SetGroupInfo($idListview, 1, "Group 1", 0, $LVGS_COLLAPSIBLE + $LVGS_COLLAPSED) ; <---
    _GUICtrlListView_InsertGroup($idListview, -1, 2, "Group 2")
;~     _GUICtrlListView_SetGroupInfo($idListview, 2, "Group 2", 0, $LVGS_COLLAPSIBLE + $LVGS_COLLAPSED) ; <---
    _GUICtrlListView_SetItemGroupID($idListview, 0, 1)
    _GUICtrlListView_SetItemGroupID($idListview, 1, 2)
    _GUICtrlListView_SetItemGroupID($idListview, 2, 2)

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    Local $apos = _GUICtrlListView_GetGroupRect($idListview, 2, $LVGGR_LABEL)


    Local $test = GUICtrlCreateLabel("a", 2, 2, 10, 17)
    Local $val = _WinAPI_GetWindowLong(GUICtrlGetHandle($test), $GWL_STYLE)
    Local $valex = _WinAPI_GetWindowLong(GUICtrlGetHandle($test), $GWL_EXSTYLE)
    Local $aha = _WinAPI_CreateWindowEx($valex+$WS_EX_LAYERED, "static", "blabla", $val, $apos[0], $apos[1], 50, 20, $hWndListView)

    _GUIToolTip_AddTool($hToolTip, $hWndListView, "This is a ToolTip3", $aha)


    GUISetState(@SW_SHOW)

    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    GUIDelete()
EndFunc   ;==>Example

 

Share this post


Link to post
Share on other sites

You missed the goal...

Quote

i want to display a tooltip when i hover over the listview group.

Your solution tooltips the items, not a group.

Share this post


Link to post
Share on other sites

Hello. You can do something like this.

 

#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <WinAPI.au3>
#include <GuiToolTip.au3>
#include <WindowsConstants.au3>


Global $idListview = 0
Global $hListView = 0
Global $hGUI = 0
Global $hToolTip = 0

Example()


Func Example()
    Local $hImage

    $hGUI = GUICreate("ListView Enable Group View", 400, 300)
    $idListview = GUICtrlCreateListView("", 2, 2, 394, 268)
    $hListView = GUICtrlGetHandle($idListview)
    $hToolTip = _GUIToolTip_Create(0, BitOR($_TT_ghTTDefaultStyle, $TTS_BALLOON)); balloon style tooltip
    _GUIToolTip_AddTool($hToolTip, 0, "Tooltip for the GUI", $hListView)
    _GUIToolTip_Deactivate($hToolTip)


    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    GUISetState(@SW_SHOW)


    ; Load images
    $hImage = _GUIImageList_Create()
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 16, 16))
    _GUICtrlListView_SetImageList($idListview, $hImage, 1)

    ; Add columns
    _GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
    _GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
    _GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)

    ; Add items
    _GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
    _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1)
    _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2)
    _GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1)
    _GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1)
    _GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2)
    _GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1)
    _GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1)
    _GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2)

    ; Build groups
    _GUICtrlListView_EnableGroupView($hListView)
    _GUICtrlListView_InsertGroup($hListView, -1, 1, "AutoIt Rocks", 1)
    _GUICtrlListView_InsertGroup($hListView, -1, 2, "Danyfirex Rocks")
    _GUICtrlListView_InsertGroup($hListView, -1, 3, "Trolleule Rocks", 2)
    _GUICtrlListView_SetItemGroupID($hListView, 0, 1)
    _GUICtrlListView_SetItemGroupID($hListView, 1, 2)
    _GUICtrlListView_SetItemGroupID($hListView, 2, 2)
    _GUICtrlListView_SetItemGroupID($hListView, 3, 3)
    ; Loop until the user exits.
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example



Func _ShowToolTip()

    Local $aHit = _GUICtrlListView_HitTestEx($hListView)

    If IsArray($aHit) Then
        If $aHit[0] And $aHit[10] Then
            $iGroupID = $aHit[0]
            Local $iX = 0
            Local $iY = 0
            $aPos = ControlGetPos($hGUI, "", $hListView)
            Local $tPoint = DllStructCreate("int X;int Y")
            DllStructSetData($tPoint, "X", $aPos[0])
            DllStructSetData($tPoint, "Y", $aPos[1])
            _WinAPI_ClientToScreen($hGUI, $tPoint)
            $iX = $tPoint.X
            $iY = $tPoint.Y
            Local $aGroupInfo = _GUICtrlListView_GetGroupInfo($hListView, $iGroupID)
            Local $sGroupText = $aGroupInfo[0]
            Local $iGroupAlign = $aGroupInfo[1]
            Local $aGroupHeaderRec = _GUICtrlListView_GetGroupRect($hListView, $iGroupID, $LVGGR_GROUP)
            Local $aGroupLabelRec = _GUICtrlListView_GetGroupRect($hListView, $iGroupID, $LVGGR_LABEL)


            ;0 - Left 1 - Center 2 - Right
            Switch $iGroupAlign
                Case 0
                    $iX += $aGroupHeaderRec[0] + $aGroupLabelRec[2] + 8
                    $iY += $aGroupHeaderRec[1] + 5
                Case 1
                    $iX += ($aGroupHeaderRec[2] / 2) + ($aGroupLabelRec[2] / 2)
                    $iY += $aGroupHeaderRec[1] + 5
                Case 2
                    $iX += ($aGroupHeaderRec[2]) - 8
                    $iY += $aGroupHeaderRec[1] + 5

            EndSwitch


            Local $Xul = $iX - $aGroupLabelRec[2]
            Local $Xur = $iX
            Local $Xdl = $iX - $aGroupLabelRec[2]
            Local $Yul = $iY
            Local $Ydr = $iY + ($aGroupLabelRec[3] - $aGroupLabelRec[1])



            Local $aPos = MouseGetPos()
            Local $iXm = $aPos[0]
            Local $iYm = $aPos[1]

            If ($iXm > $Xul And $iXm < $Xur And $iYm > $Yul And $iYm < $Ydr) Then
                _GUIToolTip_UpdateTipText($hToolTip, 0, $hListView, $sGroupText)
                _GUIToolTip_Activate($hToolTip)
                _GUIToolTip_PopUp($hToolTip)
            EndIf

        Else
            _GUIToolTip_Pop($hToolTip)
            _GUIToolTip_Deactivate($hToolTip)
        EndIf
    EndIf

EndFunc   ;==>_ShowToolTip

Func WM_NOTIFY($hWnd, $IMsg, $iwParam, $ilParam)
    #forceref $hWnd, $IMsg, $iwParam
    Local $hwndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hwndFrom = HWnd(DllStructGetData($tNMHDR, "hwndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "idFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hwndFrom
        Case $hListView
            Switch $iCode
                Case $LVN_HOTTRACK
                    _ShowToolTip()
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY




;Simple Modification of _GUICtrlListView_HitTest to handle listivew Groups
;~     [0] - 0-based index of the item at the specified position, or GroupID
;~     [1] - If True, position is in control's client window but not on an item
;~     [2] - If True, position is over item icon
;~     [3] - If True, position is over item text
;~     [4] - If True, position is over item state image
;~     [5] - If True, position is somewhere on the item
;~     [6] - If True, position is above the control's client area
;~     [7] - If True, position is below the control's client area
;~     [8] - If True, position is to the left of the client area
;~     [9] - If True, position is to the right of the client area
;~     [10]- If True, position is over the group header

Func _GUICtrlListView_HitTestEx($hWnd, $iX = -1, $iY = -1)
    Local $aTest[11]

    Local $iMode = Opt("MouseCoordMode", 1)
    Local $aPos = MouseGetPos()
    Opt("MouseCoordMode", $iMode)
    Local $tPoint = DllStructCreate($tagPOINT)
    DllStructSetData($tPoint, "X", $aPos[0])
    DllStructSetData($tPoint, "Y", $aPos[1])
    Local $aResult = DllCall("user32.dll", "bool", "ScreenToClient", "hwnd", $hWnd, "struct*", $tPoint)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] = 0 Then Return 0

    If $iX = -1 Then $iX = DllStructGetData($tPoint, "X")
    If $iY = -1 Then $iY = DllStructGetData($tPoint, "Y")

    Local $tTest = DllStructCreate($tagLVHITTESTINFO)
    DllStructSetData($tTest, "X", $iX)
    DllStructSetData($tTest, "Y", $iY)
    If IsHWnd($hWnd) Then
        If _WinAPI_InProcess($hWnd, $__g_hLVLastWnd) Then
            $aTest[0] = _SendMessage($hWnd, $LVM_HITTEST, -1, $tTest, 0, "wparam", "struct*")
        Else
            Local $iTest = DllStructGetSize($tTest)
            Local $tMemMap
            Local $pMemory = _MemInit($hWnd, $iTest, $tMemMap)
            _MemWrite($tMemMap, $tTest, $pMemory, $iTest)
            $aTest[0] = _SendMessage($hWnd, $LVM_HITTEST, 0, $pMemory, 0, "wparam", "ptr")
            _MemRead($tMemMap, $pMemory, $tTest, $iTest)
            _MemFree($tMemMap)
        EndIf
    Else
        $aTest[0] = GUICtrlSendMsg($hWnd, $LVM_HITTEST, 0, DllStructGetPtr($tTest))
    EndIf
    Local $iFlags = DllStructGetData($tTest, "Flags")
    $aTest[1] = BitAND($iFlags, $LVHT_NOWHERE) <> 0
    $aTest[2] = BitAND($iFlags, $LVHT_ONITEMICON) <> 0
    $aTest[3] = BitAND($iFlags, $LVHT_ONITEMLABEL) <> 0
    $aTest[4] = BitAND($iFlags, $LVHT_ONITEMSTATEICON) <> 0
    $aTest[5] = BitAND($iFlags, $LVHT_ONITEM) <> 0
    $aTest[6] = BitAND($iFlags, $LVHT_ABOVE) <> 0
    $aTest[7] = BitAND($iFlags, $LVHT_BELOW) <> 0
    $aTest[8] = BitAND($iFlags, $LVHT_TOLEFT) <> 0
    $aTest[9] = BitAND($iFlags, $LVHT_TORIGHT) <> 0
    $aTest[10] = BitAND($iFlags, $LVHT_EX_GROUP_HEADER) <> 0
    Return $aTest
EndFunc   ;==>_GUICtrlListView_HitTestEx

 

Saludos

Share this post


Link to post
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

  • Similar Content

    • 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?
    • AndyS19
      By AndyS19
      I have a listview with 3 columns and I want to set the 3rd column's color based on the item's 'Param' value, but even though I set up for the 3rd column, the entire row always gets the color.
      My test code is below, but here is the pertinent code:
      Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Local $hWndFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $iDrawStage, $tCustDraw $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam) $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage') Switch $iDrawStage Case BitOR(0, $CDDS_ITEMPREPAINT) ;, $CDDS_SUBITEM) setItemColor($tCustDraw, $hWndFrom) Return $CDRF_NOTIFYSUBITEMDRAW EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func setItemColor($tCustDraw, $hWnd) Local $iIndex, $color, $iSubitem $iIndex = DllStructGetData($tCustDraw, 'dwItemSpec') ; item number $color = _GUICtrlListView_GetItemParam($hWnd, $iIndex) $iSubitem = DllStructGetData($tCustDraw, 'iSubItem') ; Here, I want to only change the color of the 3rd col, and not the 1st and 2nd cols DllStructSetData($tCustDraw, 'iSubItem', 2) ; always use the 3rd column (the 'sample' col) logmsg("+++: setItemColor($tCustDraw, 0x" & Hex($hWnd) & ") entered ... " _ & ", $iIndex = " & $iIndex & ", $iSubItem = " & $iSubitem & ", $color = " & Hex($color)) DllStructSetData($tCustDraw, 'clrText', $color) ; set the Text color DllStructSetData($tCustDraw, 'clrTextBk', bitnot($color)) ; set the background color EndFunc ;==>setItemColor Func logmsg($msg, $lnum = @ScriptLineNumber) ConsoleWrite("+++:" & $lnum & ": " & $msg & @CRLF) EndFunc ;==>logmsg
      Here is the full test code:
      #include-once ;#cs #NoTrayIcon #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #AutoIt3Wrapper_UseX64=N Opt("GUICloseOnESC", 1) ; ESC closes GUI? (0 = no, 1 = yes) Opt("GUIOnEventMode", 1) ; Change to OnEvent mode Opt('MustDeclareVars', 1) OnAutoItExitRegister("_test_exit") Opt("GUIEventOptions", 1) ;0=default, 1=just notification, 2=GuiCtrlRead tab index Opt("WinTitleMatchMode", -2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase #include <GuiListBox.au3> #include <ListViewConstants.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <ColorConstants.au3> Global $__MCP_obj, $__MCP_GUI_hWnd, $idListView, $hListView Global $hMainWin test() Exit Func test() $hMainWin = GUICreate("Test window", 120, 100, @DesktopWidth / 2, -1) GUICtrlCreateButton("Hwnd", 10, 10, 40, 20) GUICtrlSetOnEvent(-1, "handle_1stTEST_btn") GUICtrlCreateButton("ID", 50, 10, 40, 20) GUICtrlSetOnEvent(-1, "handle_2ndTEST_btn") GUISetOnEvent($GUI_EVENT_CLOSE, "_test_exit") GUISetState(@SW_SHOW) While (1) Sleep(17) WEnd EndFunc ;==>test Func _myColorPicker($obj) logmsg("+++: $obj = 0x" & Hex($obj) & @CRLF) Local $flags = 0 Local $ww, $wh, $x, $y, $w, $h $__MCP_obj = $obj $ww = 350 $wh = 500 $x = 200 $y = 150 $__MCP_GUI_hWnd = GUICreate("myColorPicker", $ww, $wh, $x, $y, $flags) $x = 10 $y = 10 $w = 150 $h = 20 GUICtrlCreateButton("Set caller's color", $x, $y, $w, $h) GUICtrlSetOnEvent(-1, "__MCP_handle_SetColor_btn") $y += $h + 5 $w = $ww - 25 $h = $wh - 100 $idListView = GUICtrlCreateListView("", $x, $y, $w, $h, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) $hListView = GUICtrlGetHandle($idListView) $x = $ww / 2 - 50 $y = $wh - 60 $w = 100 $h = 25 GUICtrlCreateButton("Quit Popup", $x, $y, $w, $h) GUICtrlSetOnEvent(-1, "__MCP_handle_QUIT_btn") GUICtrlSetFont($idListView, 8.5, -1, -1, "courier new") _GUICtrlListView_AddColumn($idListView, "Name", 100) _GUICtrlListView_AddColumn($idListView, "Value", 100) _GUICtrlListView_AddColumn($idListView, "Sample", 100) _GUICtrlListView_SetColumnWidth($idListView, 0, 100) _GUICtrlListView_SetColumnWidth($idListView, 1, 80) logmsg("+++: $idListView = " & $idListView) logmsg("+++: $hListView = 0x" & Hex($hListView)) __MCP_populateListView($hListView) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW, $__MCP_GUI_hWnd) EndFunc ;==>_myColorPicker Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Local $hWndFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $iDrawStage, $tCustDraw $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam) $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage') Switch $iDrawStage Case BitOR(0, $CDDS_ITEMPREPAINT) ;, $CDDS_SUBITEM) setItemColor($tCustDraw, $hWndFrom) Return $CDRF_NOTIFYSUBITEMDRAW EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func setItemColor($tCustDraw, $hWnd) Local $iIndex, $color, $iSubitem $iIndex = DllStructGetData($tCustDraw, 'dwItemSpec') ; item number $color = _GUICtrlListView_GetItemParam($hWnd, $iIndex) $iSubitem = DllStructGetData($tCustDraw, 'iSubItem') ; Here, I want to only change the color of the 3rd col, and not the 1st and 2nd cols DllStructSetData($tCustDraw, 'iSubItem', 2) ; always use the 3rd column (the 'sample' col) logmsg("+++: setItemColor($tCustDraw, 0x" & Hex($hWnd) & ") entered ... " _ & ", $iIndex = " & $iIndex & ", $iSubItem = " & $iSubitem & ", $color = " & Hex($color)) DllStructSetData($tCustDraw, 'clrText', $color) ; set the Text color DllStructSetData($tCustDraw, 'clrTextBk', bitnot($color)) ; set the background color EndFunc ;==>setItemColor Func logmsg($msg, $lnum = @ScriptLineNumber) ConsoleWrite("+++:" & $lnum & ": " & $msg & @CRLF) EndFunc ;==>logmsg Func __MCP_exit() GUIDelete($__MCP_GUI_hWnd) EndFunc ;==>__MCP_exit Func __MCP_handle_SetColor_btn() If (IsHWnd($__MCP_obj)) Then GUISetBkColor($COLOR_BLUE, $__MCP_obj) Else GUICtrlSetBkColor($__MCP_obj, $COLOR_BLUE) EndIf EndFunc ;==>__MCP_handle_SetColor_btn Func __MCP_populateListView($hWnd) Local $text, $parts, $iIndex Local Static $aItems[] = [ _ "BLACK | " & $CLR_BLACK & "|" & "", _ "BLUE | " & $CLR_BLUE & "|" & "", _ "RED | " & $CLR_RED & "|" & "", _ "WHITE | " & $CLR_WHITE & "|" & "", _ "YELLOW | " & $CLR_YELLOW & "|" & "" _ ] _GUICtrlListView_BeginUpdate($hWnd) _GUICtrlListView_DeleteAllItems($hWnd) For $ndx = 0 To UBound($aItems) - 1 $text = $aItems[$ndx] $parts = StringSplit($text, "|", 2) $parts[0] = StringStripWS($parts[0], 3) $parts[2] = StringStripWS($parts[2], 3) $iIndex = _GUICtrlListView_AddItem($hWnd, $parts[0], -1, $parts[1]) _GUICtrlListView_AddSubItem($hWnd, $iIndex, Hex($parts[1]), 1) _GUICtrlListView_AddSubItem($hWnd, $iIndex, $parts[0], 2) Next _GUICtrlListView_EndUpdate($hWnd) EndFunc ;==>__MCP_populateListView Func __MCP_handle_QUIT_btn() GUIDelete($__MCP_GUI_hWnd) EndFunc ;==>__MCP_handle_QUIT_btn Func handle_1stTEST_btn() _myColorPicker($hMainWin) EndFunc ;==>handle_1stTEST_btn Func handle_2ndTEST_btn() _myColorPicker(@GUI_CtrlId) EndFunc ;==>handle_2ndTEST_btn Func _test_exit() Exit EndFunc ;==>_test_exit  
    • nacerbaaziz
      By nacerbaaziz
      Hello guys
      Today I'll give you three functions to manage the list View items
      These functions will help you to do some works in your list view items
      1. list view Read
      To get the selected item text  
      2. listView_checke
      To checke an item
      3. isListViewChecked
      To see if the item is checked
      All of these functions will be illustrated by the following example
      You can download the include file from the link below
      Now with the example
      #include <easy_listView_functions.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> Example() Func Example()  Local $idListview  GUICreate("ListView Get Item Checked State", 1000, 700)  $idListview = GUICtrlCreateListView("", 50, 30, 250, 120, 50)  _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES)) ; Add items $item1 = GUICtrlCreateListViewItem("item1", $idListview) $item2 = GUICtrlCreateListViewItem("item2", $idListview) _listview_Checke($idListview, "item1") $btn = GUICtrlCreateButton("&read", 100, 150, 50, 50) $btn2 = GUICtrlCreateButton("&if checked", 100, 200, 100, 50)  GUISetState(@SW_SHOW) while 1 switch GUIGetMSG() case $GUI_EVENT_CLOSE  GUIDelete() exit case $btn $read = _ListView_read($idListView) if $read then msgBox(0, "read listview", $read) else msgBox(0, "read listview", "no text ditected") endIf case $btn2 if _isListviewChecked($idListView, "item1") then msgBox(0, "get", "the item is checked") else msgBox(0, "get", "the item isn't checked") endIf endSwitch wend EndFunc   ;==>Example
       
      easy_listView_functions.au3
    • astrionn
      By astrionn
      So I had this Idea of creating a tooltip which shows me my ping.
      That itself was made quickly and I thought too add a couple features.
      I want the tooltip background to be a different color depending on the ping. (good ping is green, medium ping is yellow,...)
      So how do I color in a tooltip? google brought me to this: 
       
      where in the comments I found this:
      $s = "LOW" ToolTip($s, 0, 0, "Battery Information");, $icon) $H_TOOLTIP1 = WinGetHandle($s) DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $H_TOOLTIP1, "wstr", "", "wstr", "") DllCall("user32.dll", "int", "SendMessage", "hwnd", $H_TOOLTIP1, "int", 1043, "int", 2552550, "int", 0) Sleep(1000) Which I then used in my code with different color codes... Trial and Error brought me these that I wanted to use:
       
      The Problem is if I loop through my code it only sets the color for the 1st loop and then sticks to it.
      The real problem is tho that I don't exactly understand the dllcalls... And I guess that's why it isn't working
      So if someone would be so awesome to explain to me how they work, or at least can give me a list of these parameters then I would really appreciate that and learn something new
      Obviously a solution to my problem is awesome aswell ^^
      I run this under Windows 8.1
      There is my code in a paste.
      https://pastebin.com/q525f7mS
    • dascondor
      By dascondor
      So I having issues with this GUI/Listview. My main GUI works like it needs to but the ListView GUIs don't. The exit buttons do not work on them and om have a hard time getting them to work. And I'm trying to make the  listview GUI resizeable. But I'm not sure how to fix either of these issues any thoughts.
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <ScreenCapture.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <ListviewConstants.au3> #include 'MultiPing.au3' Opt("GUIOnEventMode", 1) #Region ;Declares ; Reads text file for the base list of IP's Global $aBase_IPlist = _FileReadToArray_mod(".\IP_List.txt") Global $replace2 = "Second" Global $replace3 = "Thrid" ;Global $userdata1 = GUICtrlRead($data1) ;Global $userdata2 = GUICtrlRead($data2) Global $savefolder = "C:\Users\" Global $paths = "\Desktop\PingChecks" Global $1stpaths = "\~~~Store" Global $2ndpaths = "~~~" Global $results = FileExists($savefolder & @UserName & $paths) ;Global $foldercheck = FileExists($savefolder & @UserName & $paths & $1stpaths & $userdata1 & $userdata2 & $2ndpaths) ;Global $savefile = "C:\Users\" & @UserName & "\Desktop\PingChecks\~~~Store" & $userdata1 & $userdata2 & "~~~\" #EndRegion ;Declares #Region ### START Koda GUI section ### Form= $IPMonkey = GUICreate("IP Monkey", 573, 254, -1, -1) GUISetIcon("C:\Users\Dlex\Pictures\monkeyicon.ico", -1) GUISetFont(16, 800, 0, "Arial") GUISetBkColor(0xFFFFFF) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") $data1 = GUICtrlCreateInput("1", 184, 120, 89, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetColor(-1, 0x000000) $data2 = GUICtrlCreateInput("23", 280, 120, 89, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetColor(-1, 0x000000) $GOButton = GUICtrlCreateButton("GO", 80, 192, 75, 25) GUICtrlSetFont(-1, 10, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0x00FF00) GUICtrlSetTip(-1, "Runs A Live Continuous Ping" & @CRLF & _ "Until Told Other Wise") GUICtrlSetOnEvent(-1, "GOButtonClick") $quickscan = GUICtrlCreateButton("Quick Scan", 224, 192, 107, 25) GUICtrlSetFont(-1, 12, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFFFF00) GUICtrlSetOnEvent(-1, "quickscanClick") GUICtrlSetTip(-1, "Quickly Scans, Then Saves" & @CRLF & _ "Results In Your 'PingChecks' " & @CRLF & _ "Folder Under Your Store Number Folder") Global $exitbutton = GUICtrlCreateButton("Exit", 416, 192, 75, 25) GUICtrlSetFont(-1, 12, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFF0000) GUICtrlSetTip(-1, "What Do You Think This Button Does?") GUICtrlSetOnEvent(-1, "exitbuttonClick") $titlebar = GUICtrlCreateLabel("IP Monkey", 16, 120, 107, 28) GUICtrlSetColor(-1, 0x000000) $Pic1 = GUICtrlCreatePic("C:\Users\Dlex\Pictures\monkeyicon-0.jpg", 16, 16, 100, 100) GUICtrlSetOnEvent(-1, "Pic1Click") $infobutton = GUICtrlCreateButton("?", 536, 8, 27, 25) GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFF8000) GUICtrlSetTip(-1, "Unsure what to do?" & @CRLF & _ "This will get give you " & @CRLF & _ "the help for IP Monkey") GUICtrlSetOnEvent(-1, "infobuttonClick") $Whatstorelabel = GUICtrlCreateLabel("What Store?", 208, 56, 130, 28) GUICtrlSetColor(-1, 0x000000) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #Region ;ping gui ; ------ pinger GUI ------------------- Global $StopPing = 0 Local $Win_X = 1200, $Win_Y = 880 ; dimension of window Global $PingGui = GUICreate("IP Monkey", $Win_X, $Win_Y, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") Global $listview = GUICtrlCreateListView("", 10, 10, $Win_X - 20, $Win_Y - 40) GUICtrlSetFont(-1, 8) $button1 = GUICtrlCreateLabel("Hit Exit To Quit", 10, $Win_Y - 25, $Win_X - 20, 20, -1,$ES_CENTER) GUICtrlSetFont(-1, 10, 800) GUICtrlSetTip(-1, "exit") GUICtrlSetOnEvent(-1, 'SpecialEvents') GUICtrlSetStyle($listview, $LVS_ICON) ; + $LVS_NOLABELWRAP) GUISetState(@SW_HIDE) ; hidden at startup ; --------- end of pinger gui ------------- #EndRegion ;ping gui ; Generate colored square images $hImage = _GUIImageList_Create(30, 30) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFFFF00, 30, 30)) ; yellow _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 30, 30)) ; red _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 30, 30)) ; green _GUICtrlListView_SetImageList($listview, $hImage, 0) While 1 Sleep(100) WEnd Func exitbuttonClick() MsgBox(0,'0','0') Exit EndFunc ;==>exitbuttonClick Func GOButtonClick() $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) ; pass the wanted new octet replace_And_Go($userdata1, $userdata2) ; generate a list of new IP and Go EndFunc ;==>GOButtonClick Func infobuttonClick() EndFunc ;==>infobuttonClick Func Pic1Click() EndFunc ;==>Pic1Click Func quickscanClick() $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) replace_And_Go2($userdata1, $userdata2) EndFunc ;==>quickscanClick Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE _button1() Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE Case @GUI_CtrlId = $GUI_EVENT_RESTORE Case @GUI_CtrlId = $GUI_EVENT_MAXIMIZE EndSelect EndFunc ;==>SpecialEvents #Region ; Main_GO/Replace_and_GO #cs ############################## second script ############################################# ; this is to ping continuously a list of IP addresses, get and display ping result "live" ; it simulates the dos "ping -t" command but performed simultaneously on many IP ; presenting the results in a ListView highlighting not responding devices with a red box #ce Func replace_And_Go($s_2, $s_3) ; Create a new array wit a new list of IP according to passed second and third octet Local $aNew_IPlist = $aBase_IPlist For $i = 0 To UBound($aNew_IPlist) - 1 $aNew_IPlist[$i][1] = StringReplace(StringReplace($aBase_IPlist[$i][1], $replace2, $s_2), $replace3, $s_3) Next GUISetState(@SW_HIDE, $IPMonkey) GUISetState(@SW_SHOW, $PingGui) ; pass the new list to the pinger Main_GO($aNew_IPlist) GUISetState(@SW_HIDE, $PingGui) GUISetState(@SW_SHOW, $IPMonkey) EndFunc ;==>replace_And_Go Func Main_GO($IPlist) HotKeySet("{esc}", "exitbuttonClick") $StopPing = 0 ; $IPlist = _FileReadToArray_mod(".\IP_List.txt") ; Reads text file for list of IP's ; ; the above command, it loads in the $IPlist array the values contained in the file IP_List.txt ; values in the file should be separated by a semicolon, something like in the following example: ; ; hostname1;192.168.0.1 ; hostname2;192.168.0.5 ; hostnameX;10.59.7.200 ; etc.... ; ; if values in the file are not separated by a semicolon, but another char is used, for example a comma, ; then just pass it as second parameter of the function: $IPlist = _FileReadToArray_mod(".\IP_List.txt", ",") ; _GUICtrlListView_BeginUpdate($listview) _GUICtrlListView_DeleteAllItems($listview) _GUICtrlListView_AddArray($listview, $IPlist) ; fill ListView _GUICtrlListView_EndUpdate($listview) While Not $StopPing ; 1 ; continuously ping addresses of the previously loaded file (IP_List.txt) Sleep(10) ; ; $IPlist is the array loaded with all the IP to be pinged (a 2d array in this case) ; | ; | 1 means the IP are in the second column of the $IPlist array (first colun is nr. 0) ; | | ; | | +--> 0 means return back an array loaded with results from all pinged addresses (responding and not responding) ; | | | if you use 1 then only responding addresses are loaded in the returned array [default] ; | | | if you use 2 then only NOT responding addresses are loaded in the returned array ; | | | In this case we do not need an array to be returned, we only need to perform all pings and pass results ; | | | directly (on the fly) to the "_refresh" callback function that will refresh the listview ; | | | ; | | | 0 means NO lookup name resolution must be performed ; | | | | ; | | | | +--> this is the callback function to be called for each pinged address each time the ping has finished ; | | | | | (see the MultiPing.au3 file for info on all passed params) ; | | | | | 6 parameters are passed to this function, but only 2 are used by the called function in this case: ; | | | | | [4] roundtrip of the responding ping or -1 if IP is down ; | | | | | [5] Index (position) of this IP within the caller's passed array ; | | | | | ; v v v v v _nPing($IPlist, 1, 0, 0, "_refresh") WEnd EndFunc ;==>Main_GO #EndRegion ; Main_GO/Replace_and_GO #Region ; QuickScan/Replace_and_GO2 Func replace_And_Go2($s_2, $s_3) ; Create a new array wit a new list of IP according to passed second and third octet Local $aNew_IPlist = $aBase_IPlist For $i = 0 To UBound($aNew_IPlist) - 1 $aNew_IPlist[$i][1] = StringReplace(StringReplace($aBase_IPlist[$i][1], $replace2, $s_2), $replace3, $s_3) Next GUISetState(@SW_HIDE, $IPMonkey) GUISetState(@SW_SHOW, $PingGui) ; pass the new list to the pinger QuickRun($aNew_IPlist) GUISetState(@SW_HIDE, $PingGui) GUISetState(@SW_SHOW, $IPMonkey) EndFunc ;==>replace_And_Go2 Func QuickRun($IPlist) $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) HotKeySet("{esc}", "_button1") Local $Win_X = 1200, $Win_Y = 880 ; dimension of window $PingGui = GUICreate("IP Monkey" & "~~~" & @UserName & "~~~" & "Store" & $userdata1 & $userdata2 & "~~~" & @MON & "." & @MDAY & "." & @YEAR & "~~~" & @HOUR & "." & @MIN, $Win_X, $Win_Y, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "_button1", $PingGui) $listview = GUICtrlCreateListView("", 10, 10, $Win_X - 20, $Win_Y - 40) GUICtrlSetFont(-1, 8) GUICtrlSetStyle($listview, $LVS_ICON) ; + $LVS_NOLABELWRAP) ; Generate colored square images $hImage = _GUIImageList_Create(30, 30) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFFFF00, 30, 30)) ; yellow _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 30, 30)) ; red _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 30, 30)) ; green _GUICtrlListView_SetImageList($listview, $hImage, 0) $button1 = GUICtrlCreateButton("Exit", 10, $Win_Y - 25, $Win_X - 20, 20) GUICtrlSetTip(-1, "End of program") GUICtrlSetOnEvent(-1, "exitbuttonClick") GUISetState(@SW_SHOW) ;~ $IPlist = _FileReadToArray_mod(".\IP_List.txt") ; Reads text file for list of IP's _GUICtrlListView_BeginUpdate($listview) _GUICtrlListView_AddArray($listview, $IPlist) ; fill ListView _GUICtrlListView_EndUpdate($listview) ;While 1 ; perform Pings and update ListView by the "_refresh" callback function $aFinalResult = _nPing($IPlist, 1, 0, 0, "_refresh") ;~ _ArrayDisplay($aFinalResult) ;DirCheck() EndFunc ;==>QuickRun #EndRegion ; QuickScan/Replace_and_GO2 #Region ; Misc Funcs (network) Func _refresh($Params) ; this receive ping results and displays them in the ListView _GUICtrlListView_SetItemImage($listview, $Params[5], 0) ; set colour to Yellow Sleep(50) ; a little wait If $Params[4] = -1 Then ; Device not responding to ping _GUICtrlListView_SetItemImage($listview, $Params[5], 1) ; set colour to RED _GUICtrlListView_EnsureVisible($listview, $Params[5]) ; Position view to this item Else ; Device responds to ping _GUICtrlListView_SetItemImage($listview, $Params[5], 2) ; set colour to GREEN EndIf EndFunc ;==>_refresh Func _button1() ; Button 1 clicked ;~ $StopPing = 1 Exit EndFunc ;==>_button1 #EndRegion ; Misc Funcs (network)  
      MultiPing.au3
      IP_List.txt