JeromeB Posted October 28, 2010 Posted October 28, 2010 (edited) Hey guys, I found this script for the rightclick on a listview : expandcollapse popup#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 : expandcollapse popup#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 October 28, 2010 by Jerome60
Moderators Melba23 Posted October 28, 2010 Moderators Posted October 28, 2010 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
JeromeB Posted October 28, 2010 Author Posted October 28, 2010 (edited) 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 October 28, 2010 by Jerome60
Moderators Melba23 Posted October 28, 2010 Moderators Posted October 28, 2010 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) EndSwitchIf 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Moderators Melba23 Posted October 28, 2010 Moderators Posted October 28, 2010 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) EndSwitchIf 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
JeromeB Posted October 28, 2010 Author Posted October 28, 2010 (edited) 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 October 28, 2010 by Jerome60
Moderators Melba23 Posted October 28, 2010 Moderators Posted October 28, 2010 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. As I said, study the example and if you have any specific questions, please ask again. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
JeromeB Posted October 28, 2010 Author Posted October 28, 2010 (edited) 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 October 28, 2010 by Jerome60
Moderators Melba23 Posted October 28, 2010 Moderators Posted October 28, 2010 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. M23P.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. 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
JeromeB Posted October 28, 2010 Author Posted October 28, 2010 (edited) 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 October 28, 2010 by Jerome60
Moderators Melba23 Posted October 28, 2010 Moderators Posted October 28, 2010 Jerome60,In my own script, when i rightclick on an item, nothing appearThen please post your code so we can find out why! M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
JeromeB Posted October 28, 2010 Author Posted October 28, 2010 (edited) First, sorry for french expandcollapse popup#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 October 28, 2010 by Jerome60
Moderators Melba23 Posted October 28, 2010 Moderators Posted October 28, 2010 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Moderators Melba23 Posted October 28, 2010 Moderators Posted October 28, 2010 (edited) 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() EndSwitchand 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 EndFuncAlors, je suis epuisé! Fini les questions pour aujourd'hui - ou les réponses au moins! M23Edit: 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! Edited October 28, 2010 by Melba23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
BrewManNH Posted October 28, 2010 Posted October 28, 2010 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 GudeHow 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
Moderators Melba23 Posted October 30, 2010 Moderators Posted October 30, 2010 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now