Jump to content

Right and double click on a listview.


JeromeB
 Share

Recommended Posts

Hey guys,

I found this script for the rightclick on a listview :

#include <GuiMenu.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

; ========================================================================
; Global variables
; ========================================================================

Global Enum $idOpen = 1000, $idSave, $idInfo

; ========================================================================
; Main
; ========================================================================

$hGUI = GUICreate('Context Menu Demo (Right Click)', 400, 300)
$hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 394, 268)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

; 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($hListView, $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)

GUISetState()

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

Func ListView_RClick()
    Local $aHit

    $aHit = _GUICtrlListView_SubItemHitTest($hListView)
    If ($aHit[0] <> -1) Then
        ; Create a standard popup menu
        ; -------------------- To Do --------------------
        $hMenu = _GUICtrlMenu_CreatePopup()
        _GUICtrlMenu_AddMenuItem($hMenu, "Open", $idOpen)
        _GUICtrlMenu_AddMenuItem($hMenu, "Save", $idSave)
        _GUICtrlMenu_AddMenuItem($hMenu, "Info", $idInfo)
        ; ========================================================================
        ; Shows how to capture the context menu selections
        ; ========================================================================
        Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $hListView, -1, -1, 1, 1, 2)
            Case $idOpen
                _DebugPrint("Open: " & StringFormat("Item, SubItem [%d, %d]", $aHit[0], $aHit[1]))
            Case $idSave
                _DebugPrint("Save: " & StringFormat("Item, SubItem [%d, %d]", $aHit[0], $aHit[1]))
            Case $idInfo
                _DebugPrint("Info: " & StringFormat("Item, SubItem [%d, %d]", $aHit[0], $aHit[1]))
        EndSwitch
        _GUICtrlMenu_DestroyMenu($hMenu)
    EndIf
EndFunc   ;==>ListView_RClick


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    ;$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    ListView_RClick()
                    Return 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

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

And this one for the double :

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
#include <Array.au3>

#Region ### START Koda GUI section ### Form=

Global $fDblClk = False
Global $ar_Array
$Form1 = GUICreate("Services", 633, 447, 192, 124)
$List1 = GUICtrlCreateListView("", 8, 8, 617, 383)
_GUICtrlListView_AddColumn($List1, "Servcies Name", 200)
_GUICtrlListView_AddColumn($List1, "Status", 200)
_GUICtrlListView_AddColumn($List1, "Description", 200)
$Lst_Handle = GUICtrlGetHandle(-1)
$Button1 = GUICtrlCreateButton("Lister", 144, 408, 97, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Exit", 336, 408, 97, 25, $WS_GROUP)
GUIRegisterMsg($WM_NOTIFY, "WM_ListView_DoubleClick")
GUISetState(@SW_SHOW, $Form1)

#EndRegion ### END Koda GUI section ###
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Lister()
        Case $Button2
            exit
    EndSwitch
    Sleep(10)
    If $fDblClk = True Then
        $fDblClk = False
        Lst_ValuesClick()
    EndIf
WEnd

Func Lister()
    _GUICtrlListView_DeleteAllItems($List1)
    $strComputer = "127.0.0.1"
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
    $colProcessList = $objWMIService.ExecQuery("Select * from Win32_Service")

    For $objProcess In $colProcessList
        $services = $objProcess.Caption
        $status = $objProcess.State
        $Description = $objProcess.Description
        GUICtrlCreateListViewItem($services & "|" & $status & "|" & $Description, $List1)
    Next
EndFunc

Func Lst_ValuesClick()
    msgbox("","","")
EndFunc

Func WM_ListView_DoubleClick($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam
    Local $tNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return
    If DllStructGetData($tNMHDR, 1) = $Lst_Handle Then
        If DllStructGetData($tNMHDR, 3) = $NM_DBLCLK Then $fDblClk = True
    EndIf
    $tNMHDR = 0
    Return $GUI_RUNDEFMSG
EndFunc

How can I put both of Double click and right click in the same script for the same listview ?

I got this type of problem :

GUIRegisterMsg($WM_NOTIFY, "WM_ListView_RightClick")
GUIRegisterMsg($WM_NOTIFY, "WM_ListView_DoubleClick")

Keep the last Registration.

Thx

Edited by Jerome60
Link to comment
Share on other sites

  • Moderators

Jerome60,

Just check within the same message handler for both events. :)

Assuming you are going to stick with the handler in the first example, you would then need 2 Cases within your Switch $iCode structure, one for $NM_RCLICK and one for $NM_DBLCLK - each case holding the code for the particular event. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Hey, thx for your answer, but i dont understand all of your word (sorry i'm french ;))

Can you give me an exemple (if possible with a rightclick menu when clicking on an item of the listview (cause i'm trying but dont get what i want)) ?

Thx Melba23

Edited by Jerome60
Link to comment
Share on other sites

  • Moderators

Jerome60,

C'est pourtant pas tres difficile a comprendre. ;)

Controllez pour les 2 evenements dans le meme "message handler".

Si vous gardez le handler utilise dans le premier exemple, il vous faut 2 Cases a l'interieur de votre structure Switch $iCode, le premier pour $NM_RCLICK et le deuxieme pour $NM_DBLCLK - chacun doit contenir le code pour l'evenement particulier. Le handler devient quelquechose comme:

Switch $iCode
    Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
        ListView_RClick()
        Return 0
    Case $NM_DBLCLK
        ConsoleWrite("DoubleClick" & @CRLF)
EndSwitch

If you run this, you will see that you get "Doubleclick" wriiten in the SciTE console each time you doubleclick in the control. The ListView_RClick function shows you how to work out which item/subitem was doubleclicked. :)

But remember that you need to exit the handler as fast as possible (context menus are a special case) so the best way to proceed for the doubleclick is to set a flag and deal with it in your idle loop as in the second example you posted.

All clear now - or I have I just confused you even more? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

Jerome60,

C'est pourtant pas tres difficile a comprendre. ;)

Controllez pour les 2 evenements dans le meme "message handler".

Si vous gardez le handler utilise dans le premier exemple, il vous faut 2 Cases a l'interieur de votre structure Switch $iCode, le premier pour $NM_RCLICK et le deuxieme pour $NM_DBLCLK - chacun doit contenir le code pour l'evenement particulier. Le handler devient quelquechose comme:

Switch $iCode
    Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
        ListView_RClick()
        Return 0
    Case $NM_DBLCLK
        ConsoleWrite("DoubleClick" & @CRLF)
EndSwitch

If you run this, you will see that you get "Doubleclick" wriiten in the SciTE console each time you doubleclick in the control. The ListView_RClick function shows you how to work out which item/subitem was doubleclicked. :)

But remember that you need to exit the handler as fast as possible (context menus are a special case) so the best way to proceed for the doubleclick is to set a flag and deal with it in your idle loop as in the second example you posted.

All clear now - or I have I just confused you even more? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Hey :)

Yep understood, and thx for the translation in french ;).

One more question, can you give me an exemple of rightclickmenu (as _GUICtrlMenu_CreatePopup() in my exemple) for a listview item, cause in my code (this one bellow) i can't get it...

Func _RightClick()
    $SelIndexItem2 =  _GUICtrlListView_GetSelectedIndices($List1) +0
    $SelIndex2 = _GUICtrlListView_GetItem($List1, $SelIndexItem2)

    $hMenu = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hMenu,0, "&lol", $lol)
    _GUICtrlMenu_InsertMenuItem($hMenu,1, "&Save", $lol)
    Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $List1, -1, -1, 1, 1, 2)
        Case $lol
            MsgBox("","","")
    EndSwitch


EndFunc;==> _RightClick

With this, i get the MsgBox but not the menu...

Thx for your help Melba23 ;)

Edited by Jerome60
Link to comment
Share on other sites

  • Moderators

Jerome60,

You have a working example of a "right-click menu" in the first example, so why do you need another? ;)

Just study the example and check out the functions and parameters in the Help file. That way you will learn how it works and then be able to do it yourself.

A couple of pointers:

- 1. You create a popupmenu with _GUICtrlMenu_CreatePopup, not _GUICtrlMenu_CreateMenu and you add items with _GUICtrlMenu_AddMenuItem, not _GUICtrlMenu_InsertMenuItem. ;)

- 2. You need to define some CmdIDs when adding the items for the menu to recognise. :shocked:

As I said, study the example and if you have any specific questions, please ask again. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Err, i still dont get it ;(

Sorry for _GUICtrlMenu_CreateMenu, i was trying something else.

I tried many things, from the site and the help of autoit, but no ...

My code bellow, from the exemple working is not working when i rightclick an item in my listview ... Dunno why.

Global Enum $idOpen = 1000, $idSave, $idInfo


Func _RightClick()
    ;$SelIndexItem2 =  _GUICtrlListView_GetSelectedIndices($List1) +0
    ;$SelIndex2 = _GUICtrlListView_GetItem($List1, $SelIndexItem2)
    Local $aHit

    $aHit = _GUICtrlListView_SubItemHitTest($List1)
    If ($aHit[0] <> -1) Then
        $hMenu = _GUICtrlMenu_CreatePopup()
        _GUICtrlMenu_AddMenuItem($hMenu, "Open", $idOpen)
        _GUICtrlMenu_AddMenuItem($hMenu, "Save", $idSave)
        Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $List1, -1, -1, 1, 1, 2)
            Case $idOpen
                MsgBox("","","1")
            Case $idSave
                MsgBox("","","2")
        EndSwitch
        _GUICtrlMenu_DestroyMenu($hMenu)
    EndIf
EndFunc;==> _RightClick

To get the item selected of the menu, i know how to do, but i can't get something for the rightclick menu...

:s

Edited by Jerome60
Link to comment
Share on other sites

  • Moderators

Jerome60,

When I put the function you just posted into the first example script in your original post it works perfectly (after adjusting the variable and function names) - a small popup menu appears and when you select either menu option the correct action fires.

Exactly what problem are you having - "but i can't get something for the rightclick menu" is not very clear! Explain in French if it is easier. ;)

M23

P.S. Do NOT use MsgBox or any other blocking function in a message handler or function called from with in it. You will almost certainly crash the system if you do. :)

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Hey.

I saw the rightclick on an item works in my listView with :

Func _RightClick()
    msgbox("","","")
EndFunc;==> _RightClick

So it detect the rightclick.

Now i want to put the menu when i rightclick on an item of my listview with the code bellow :

Global Enum $idOpen = 1000, $idSave, $idInfo


Func _RightClick()
    ;$SelIndexItem2 =  _GUICtrlListView_GetSelectedIndices($List1) +0
    ;$SelIndex2 = _GUICtrlListView_GetItem($List1, $SelIndexItem2)
    Local $aHit

    $aHit = _GUICtrlListView_SubItemHitTest($List1)
    If ($aHit[0] <> -1) Then
        $hMenu = _GUICtrlMenu_CreatePopup()
        _GUICtrlMenu_AddMenuItem($hMenu, "Open", $idOpen)
        _GUICtrlMenu_AddMenuItem($hMenu, "Save", $idSave)
        Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $List1, -1, -1, 1, 1, 2)
            Case $idOpen
                MsgBox("","","1")
            Case $idSave
                MsgBox("","","2")
        EndSwitch
        _GUICtrlMenu_DestroyMenu($hMenu)
    EndIf
EndFunc;==> _RightClick

This code works in the exemple (like you said) and i copied it in my own script.

Now, the problem is : In my own script, when i rightclick on an item, nothing appear. I dont get the menu :)

Thx for helping ;)

Edited by Jerome60
Link to comment
Share on other sites

  • Moderators

Jerome60,

In my own script, when i rightclick on an item, nothing appear

Then please post your code so we can find out why! ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

First, sorry for french ;)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <GUIListBox.au3>
#Include <GuiListView.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <Inet.au3>
#include <WindowsConstants.au3>
#include <Excel.au3>
#Include <Misc.au3>
#include <Constants.au3>
#include <GuiMenu.au3>

;=============================================================================================================================================
; ---------------------------------------------------------- DEFINITION VARIABLE -------------------------------------------------------------
;=============================================================================================================================================

Global $i
Global $sResult
Global $IP
Global $fDblClk = False
Global Enum $idOpen = 1000, $idSave, $idInfo

;=============================================================================================================================================
; --------------------------------------------------- FIN DEFINITION VARIABLE ----------------------------------------------------------------
;=============================================================================================================================================
; Form 1

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("By Jérôme", 616, 430, 192, 124)
Opt("GUIOnEventMode", 1)
Opt("TrayOnEventMode",1)
Opt("TrayMenuMode",1)
GUISetIcon(@ScriptDir & "\icon.ico")
TraySetIcon(@ScriptDir & "\icon.ico")
$Tab1 = GUICtrlCreateTab(0, 0, 633, 25)
GUICtrlSetOnEvent(-1, "_Tab_Switch")
GUICtrlSetResizing(-1, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)

;=============================================================================================================================================
; ----------------------------------------------------------- ONGLET 1 -----------------------------------------------------------------------
;=============================================================================================================================================

$TabSheet1 = GUICtrlCreateTabItem("List IP")
GUISetFont(8, 400, 0, "Tahoma")
$IPAddress11 = _GUICtrlIpAddress_Create($Form1, 96, 400, 130, 21)
_GUICtrlIpAddress_Set($IPAddress11, "")
$IPAddress22 = _GUICtrlIpAddress_Create($Form1, 272, 400, 130, 21)
_GUICtrlIpAddress_Set($IPAddress22, "")
$Label1 = GUICtrlCreateLabel("De :", 48, 400, 28, 20)
GUICtrlSetFont(-1, 10, 400, 0, "Tahoma")
$Label2 = GUICtrlCreateLabel("à :", 248, 400, 20, 20)
GUICtrlSetFont(-1, 10, 400, 0, "Tahoma")
$Button1 = GUICtrlCreateButton("Start", 432, 398, 75, 25, $WS_GROUP)
GUICtrlSetOnEvent($Button1, "_ActionButton1")
$Button2 = GUICtrlCreateButton("Export", 520, 398, 75, 25, $WS_GROUP)
GUICtrlSetOnEvent($Button2, "_Excel")
GUIctrlSetState($Button2, $GUI_DISABLE)
$List1 = GUICtrlCreateListView("", 16, 32, 580, 357)
_GUICtrlListView_AddColumn($List1, "IP", 100)
_GUICtrlListView_AddColumn($List1, "Computer Name", 100)
_GUICtrlListView_AddColumn($List1, "User Actually Connected", 200)
$Lst_Handle = GUICtrlGetHandle(-1)

;=============================================================================================================================================
; -------------------------------------------------------------- FIN ONGLET 1 ----------------------------------------------------------------
;=============================================================================================================================================

;=============================================================================================================================================
; --------------------------------------------------------------- ONGLET 2 -------------------------------------------------------------------
;=============================================================================================================================================

$TabSheet2 = GUICtrlCreateTabItem("Utilitaires")
$Group1 = GUICtrlCreateGroup("IP > Poste", 8, 32, 600, 65)
$Button3 = GUICtrlCreateButton("Go", 200, 64, 59, 25, $WS_GROUP)
GUICtrlSetOnEvent($Button3, "_IPtoPC")
$Label3 = GUICtrlCreateLabel("", 292, 64, 250, 28)
GUICtrlSetFont(-1, 10, 400, 0, "Tahoma")
$IPAddress33 = _GUICtrlIpAddress_Create($Form1, 48, 64, 130, 21)
_GUICtrlIpAddress_Set($IPAddress33, "")
$Group2 = GUICtrlCreateGroup("Poste > IP", 8, 112, 600, 65)
$Input1 = GUICtrlCreateInput("", 48, 144, 121, 21)
$Button4 = GUICtrlCreateButton("Go", 200, 144, 59, 25, $WS_GROUP)
GUICtrlSetOnEvent($Button4, "_PCtoIP")
$Label4 = GUICtrlCreateLabel("", 288, 144, 220, 28)
GUICtrlSetFont(-1, 10, 400, 0, "Tahoma")
$Pic1 = GUICtrlCreatePic("", 544, 40, 60, 52)
GUICtrlSetOnEvent(-1, "_ClickImage1")
$Pic2 = GUICtrlCreatePic("", 544, 120, 60, 52)
GUICtrlSetOnEvent(-1, "_ClickImage2")
GUICtrlSetState($Pic1, $GUI_HIDE)
GUICtrlSetState($Pic2, $GUI_HIDE)

;=============================================================================================================================================
; ------------------------------------------------------------- FIN ONGLET 2 -----------------------------------------------------------------
;=============================================================================================================================================

;=============================================================================================================================================
; ------------------------------------------------------------- DEBUT STATE ------------------------------------------------------------------
;=============================================================================================================================================

WinSetState($IPAddress33, "", @SW_HIDE)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quitter")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "_Minimize")
GUIRegisterMsg($WM_NOTIFY, "_Action_Click")
GUISetState(@SW_SHOW)
$restore = TrayCreateItem("Restore")
TrayItemSetOnEvent(-1,"_Restore")
$exit = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,"_Quitter")
TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE,"_SpecialEvent")
TraySetState()
Opt("TrayIconHide", 1)
#EndRegion ### END Koda GUI section ###
$iLastTab = 0

;=============================================================================================================================================
; ----------------------------------------------------------FIN DEBUT STATE ------------------------------------------------------------------
;=============================================================================================================================================

While 1
    sleep(100)
    If _IsPressed("0D") And WinActive("By Jérôme") And GUICtrlRead($Tab1) = 0 And ControlGetFocus("By Jérôme") = "Edit5" Then
        _ActionButton1()
    EndIf
    If _IsPressed("0D") And WinActive("By Jérôme") And GUICtrlRead($Tab1) = 1 And ControlGetFocus("By Jérôme") = "Edit9" Then
        _IPtoPC()
    EndIf
    If _IsPressed("0D") And WinActive("By Jérôme") And GUICtrlRead($Tab1) = 1 And ControlGetFocus("By Jérôme") = "Edit13" Then
        _PCtoIP()
    EndIf
    If $fDblClk = True Then
        $fDblClk = False
        _DoubleClick()
    EndIf
WEnd

;=============================================================================================================================================
; --------------------------------------------------FONCTIONS POUR GERER LES TABLES ----------------------------------------------------------
;=============================================================================================================================================

Func _Tab_Switch()
    Local $iCurrTab = GUICtrlRead($Tab1)
    If $iCurrTab <> $iLastTab Then
        Switch $iCurrTab
            Case 0
                WinSetState($IPAddress11, "", @SW_SHOW)
                WinSetState($IPAddress22, "", @SW_SHOW)
                WinSetState($IPAddress33, "", @SW_HIDE)
            Case 1
                WinSetState($IPAddress11, "", @SW_HIDE)
                WinSetState($IPAddress22, "", @SW_HIDE)
                WinSetState($IPAddress33, "", @SW_SHOW)
        EndSwitch
        $iLastTab = $iCurrTab
    EndIf
EndFunc ;==>_Tab_Switch

;=============================================================================================================================================
; ----------------------------------------------FIN FONCTIONS POUR GERER LES TABLES ----------------------------------------------------------
;=============================================================================================================================================

;=============================================================================================================================================
; ------------------------------------------------------ FONCTION TAB 1 ----------------------------------------------------------------------
;=============================================================================================================================================

Func _ActionButton1()
    $IPAddress1 = StringSplit(_GUICtrlIpAddress_Get($IPAddress11), ".")
    $IPAddress2 = StringSplit(_GUICtrlIpAddress_Get($IPAddress22), ".")
    GUIctrlSetState($Button1, $GUI_DISABLE)
    GUIctrlSetState($Button2, $GUI_DISABLE)
    Global $avArray[255][3], $j
    $j = 0
    _GUICtrlListView_DeleteAllItems($List1)
    TCPStartup()
    If @error Then Return GUICtrlCreateListViewItem('Aucun résultats',$List1)
    For $i = $IPAddress1[4] To $IPAddress2[4]
        If Ping($IPAddress1[1] & "." & $IPAddress1[2] & "." &$IPAddress1[3] & "." & $i, 50) > 0 Then
            $IpList = $IPAddress1[1] & "." & $IPAddress1[2] & "." &$IPAddress1[3] & "." & $i
            $sResult = _TCPIpToName($IpList, 0)
            $j = $j + 1
            If $sResult = "" Then
                $sResult = "No Name"
            EndIf
            $string = "local"
            If StringRight($sResult, 5) = $string Then
                $sResult = stringTrimRight($sResult, 5)
            EndIf
            If $sResult = "No Name" Then
                $user = "Nobody"
            Else
                $objWMIService = ObjGet("winmgmts:" _
                & "{impersonationLevel=impersonate}!\\" _
                & $IpList & "\root\cimv2")
                If @error Then
                    $user = "Nobody"
                Else
                    $colComputers = $objWMIService.ExecQuery _
                    ("Select * from Win32_ComputerSystem")
                    For $objComputer in $colComputers
                        $user = $objComputer.UserName
                    Next
                EndIf
            EndIf
            GUICtrlCreateListViewItem($IpList & "|" & $sResult & "|" & $user, $List1)
            $avArray[$j][0] = $IpList
            $avArray[$j][1] = $sResult
            $avArray[$j][2] = $user
        EndIf
    Next
GUIctrlSetState($Button1, $GUI_ENABLE)
GUIctrlSetState($Button2, $GUI_ENABLE)
EndFunc ;==>_ActionButton1

Func _Excel()
    $oExcel = _ExcelBookNew()
    $iItems = _GUICtrlListView_GetItemCount($List1)
    For $iItem = 0 To $iItems--1
        $Zf = _GUICtrlListView_GetItemTextString($List1, $iItem)
        $Zf = StringSplit($Zf, "|", 1)
        _ExcelWriteArray($oExcel, $iItem + 1, 1, $Zf, 0, 1)
    Next
EndFunc ;==>_Excel

Func _DoubleClick()
    $SelIndexItem =  _GUICtrlListView_GetSelectedIndices($List1) +0
    $SelIndex = _GUICtrlListView_GetItem($List1, $SelIndexItem)
    msgbox("","","")
EndFunc;==> _DoubleClick

Func _RightClick()
    ;$SelIndexItem2 =  _GUICtrlListView_GetSelectedIndices($List1) +0
    ;$SelIndex2 = _GUICtrlListView_GetItem($List1, $SelIndexItem2) ;$SelIndex2[3] contient la valeur IP de la listview selectionner
    Local $aHit

    $aHit = _GUICtrlListView_SubItemHitTest($List1)
    If ($aHit[0] <> -1) Then
        $hMenu = _GUICtrlMenu_CreatePopup()
        _GUICtrlMenu_AddMenuItem($hMenu, "Open", $idOpen)
        _GUICtrlMenu_AddMenuItem($hMenu, "Save", $idSave)
        Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $List1, -1, -1, 1, 1, 2)
            Case $idOpen
                MsgBox("","","1")
            Case $idSave
                MsgBox("","","2")
        EndSwitch
        _GUICtrlMenu_DestroyMenu($hMenu)
    EndIf
EndFunc;==> _RightClick

;=============================================================================================================================================
; ------------------------------------------------------FIN FONCTION TAB 1 -------------------------------------------------------------------
;=============================================================================================================================================

;=============================================================================================================================================
; ----------------------------------------------------- FONCTION TAB 2 -----------------------------------------------------------------------
;=============================================================================================================================================

Func _IPtoPC()
    TCPStartup()
    $IPAddress3 = StringSplit(_GUICtrlIpAddress_Get($IPAddress33), ".")
    If Ping($IPAddress3[1] & "." & $IPAddress3[2] & "." & $IPAddress3[3] & "." & $IPAddress3[4], 50) > 0 Then
        $IpList = $IPAddress3[1] & "." & $IPAddress3[2] & "." &$IPAddress3[3] & "." & $IPAddress3[4]
        $sResult = _TCPIpToName($IpList, 0)
        GUICtrlSetData($Label3, $sResult)
        GUICtrlSetState($Pic1, $GUI_SHOW)
    Else
        GUICtrlSetData($Label3, "Pas de réponse")
        GUICtrlSetState($Pic1, $GUI_HIDE)
    EndIf
    TCPShutdown()
EndFunc ;==>_IPtoPC

Func _PCtoIP()
    TCPStartUp()
    $IpofComputer = Guictrlread($Input1)
    $IP = TCPNameToIP ($IpofComputer)
    If $IP = "lol" Then
        GUICtrlSetData($Label4, "Non Trouvé")
        GUICtrlSetState($Pic2, $GUI_HIDE)
    Else
        GUICtrlSetData($Label4, $IP)
        GUICtrlSetState($Pic2, $GUI_SHOW)
    EndIf
    TCPShutdown()
EndFunc ;==>_PCtoIP

Func _ClickImage1()
    msgbox("","","")
EndFunc ;==>_ClickImage1

Func _ClickImage2()
    msgbox("","","")
EndFunc ;==>_ClickImage2

;=============================================================================================================================================
; -------------------------------------------------------FIN FONCTION TAB 2 ------------------------------------------------------------------
;=============================================================================================================================================

;=============================================================================================================================================
; -------------------------------------------------------DEFINITION ENVIRONNEMENT ------------------------------------------------------------
;=============================================================================================================================================

Func _Minimize()
    GUISetState(@SW_HIDE,$Form1)
    Opt("TrayIconHide", 0)
EndFunc ;==>_Minimize

Func _SpecialEvent()
    Select
        Case @TRAY_ID = $TRAY_EVENT_PRIMARYDOUBLE
            GUISetState(@SW_SHOW)
            GUISetState(@SW_RESTORE)
            Opt("TrayIconHide", 1)
    EndSelect
EndFunc ;==>_SpecialEvent

Func _Restore()
  GUISetState(@SW_SHOW)
  GUISetState(@SW_RESTORE)
  Opt("TrayIconHide", 1)
EndFunc ;==>_Restore

Func _Quitter()
    Exit
EndFunc   ;==>_quitter

Func _Action_Click($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo

    $hWndListView = $list1
    If Not IsHWnd($list1) Then $hWndListView = GUICtrlGetHandle($list1)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $iCode
        Case $NM_RCLICK
            ;_RightClick()
            Local $hMenu
            $hMenu = _GUICtrlMenu_CreatePopup ()
            _GUICtrlMenu_InsertMenuItem ($hMenu, 0, "Open", $idOpen)
            _GUICtrlMenu_InsertMenuItem ($hMenu, 1, "Save", $idSave)
            _GUICtrlMenu_InsertMenuItem ($hMenu, 3, "", 0)
            _GUICtrlMenu_InsertMenuItem ($hMenu, 3, "Info", $idInfo)
            _GUICtrlMenu_TrackPopupMenu ($hMenu, $iwParam)
            _GUICtrlMenu_DestroyMenu ($hMenu)
            Return True
        Case $NM_DBLCLK
            _DoubleClick()
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_Action_Click

;=============================================================================================================================================
; ------------------------------------------------------FIN DEFINITION ENVIRONNEMENT ---------------------------------------------------------
;=============================================================================================================================================
Edited by Jerome60
Link to comment
Share on other sites

  • Moderators

Jerome60,

You are creating the ListView with the native commands (GUICtrlCreateListView & GUICtrlCreateListViewItem) - I believe that for the rightclick code to work you must use the UDF versions (_GUICtrlListView_Create, _GUICtrlListView_AddItem and _GUICtrlListView_AddSubItem) as was the case in the example code. Try rewriting your code to use the UDF functions to create and fill the ListView. ;)

You also never call function _RightClick even though it looks as if it is coded correctly. :)

The code in function _Action_Click is completely wrong - just compare it with the code in _RightClick. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

  • Moderators

Jerome60,

Who is writing this script? You, or me? :)

You could always look for the left click in the message handler and then use _GUICtrlListView_SubItemHitTest as you do for the rightclick.

So your handler will look like this:

Switch $iCode
    Case $NM_CLICK
        ListView_Click()
    Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
        ListView_RClick()
        Return 0
    Case $NM_DBLCLK
        ListView_DblClick()
EndSwitch

and you will need a function like this:

Func ListView_Click()

    Local $aHit = _GUICtrlListView_SubItemHitTest($hListView)
    If ($aHit[0] <> -1) Then
        _DebugPrint("Click: " & StringFormat("Item, SubItem [%d, %d]", $aHit[0], $aHit[1]))
    EndIf

EndFunc

Alors, je suis epuisé! :) Fini les questions pour aujourd'hui - ou les réponses au moins! ;)

M23

Edit: Please do not delete posts and then repost. ;) It makes the thread very difficult to follow as replies have no apparent question - as is the case here! :shocked:

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Forgive my inserting myself into this, but wouldn't a context menu work a whole lot easier GUICtrlCreateContextMenu($hListView) than using Windows Messages to create one for you? Just wondering if there was some reason to use one method over another?

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

  • Moderators

BrewManNH,

As I understand it, using GUICtrlCreateContextMenu($hListView) will produce the same popup menu when you right click anywhere within the ListView control - regardless of the item clicked. By using the message handler, we are identifying the actual item on which the right click was performed and so can tailor the menu to the item rather than having a generic menu for the whole ListView. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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...