maniootek Posted April 13, 2016 Share Posted April 13, 2016 (edited) What would be a best method to reduce CPU/memory usage to read index of clicked item from ListView? I have modified example script from help file and my current code is: expandcollapse popup#include <GUIConstantsEx.au3> ;$GUI_EVENT_CLOSE #include <GuiListView.au3> #include <WindowsConstants.au3> ;$WM_NOTIFY Global $g_hListView Example() Func Example() Local $hGUI, $hImage $hGUI = GUICreate("(UDF Created) ListView Create", 400, 300) $g_hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 394, 268) _GUICtrlListView_SetExtendedListViewStyle($g_hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; Add columns _GUICtrlListView_InsertColumn($g_hListView, 0, "Column 1", 100) _GUICtrlListView_InsertColumn($g_hListView, 1, "Column 2", 100) _GUICtrlListView_InsertColumn($g_hListView, 2, "Column 3", 100) ; Add items _GUICtrlListView_AddItem($g_hListView, "Row 1: Col 1") _GUICtrlListView_AddSubItem($g_hListView, 0, "Row 1: Col 2", 1) _GUICtrlListView_AddSubItem($g_hListView, 0, "Row 1: Col 3", 2) _GUICtrlListView_AddItem($g_hListView, "Row 2: Col 1") _GUICtrlListView_AddSubItem($g_hListView, 1, "Row 2: Col 2", 1) _GUICtrlListView_AddItem($g_hListView, "Row 3: Col 1") ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo ; Local $tBuffer $hWndListView = $g_hListView If Not IsHWnd($g_hListView) Then $hWndListView = GUICtrlGetHandle($g_hListView) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) $index = DllStructGetData($tInfo, "Index") MsgBox(0,0,$index) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY other method is to check in a loop if new item was selected via _GUICtrlListView_GetItemSelected() expandcollapse popup#include <GUIConstantsEx.au3> ;$GUI_EVENT_CLOSE #include <GuiListView.au3> Example() Func Example() Local $idListview Local $last_selected_item_index = -1 GUICreate("ListView Get Item Selected", 400, 300) $idListview = GUICtrlCreateListView("", 2, 2, 394, 268) GUISetState(@SW_SHOW) ; Add columns _GUICtrlListView_AddColumn($idListview, "Items", 100) ; Add items _GUICtrlListView_AddItem($idListview, "Item 1") _GUICtrlListView_AddItem($idListview, "Item 2") _GUICtrlListView_AddItem($idListview, "Item 3") ; Loop until the user exits. Do $iCount = _GUICtrlListView_GetItemCount($idListview) For $i = 0 To $iCount - 1 If _GUICtrlListView_GetItemSelected($idListview, $i) Then $now_selected_item_index = $i If $last_selected_item_index <> $now_selected_item_index Then MsgBox(0, 0, $now_selected_item_index) $last_selected_item_index = $now_selected_item_index ContinueLoop EndIf EndIf Next Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example which one is better? Edited April 13, 2016 by maniootek Link to comment Share on other sites More sharing options...
AutoBert Posted April 13, 2016 Share Posted April 13, 2016 The first one. Link to comment Share on other sites More sharing options...
maniootek Posted April 13, 2016 Author Share Posted April 13, 2016 (edited) Ok thanks for answer. Anyway, I have tried to add _GUITreeViewEx_RegMsg() from @Melba23 TreeViewEx UDF together with my first example byt unfortunatelly they don't work together (only one which was defined in code as the last one). I am new with this type of "GUIRegisterMsg" and I don't know why only one working at time. Is there some limitation to use only one RegisterMsg? First example also crash my _ArrayDisplay function so I am staying away of this solution. Second example cause no erorrs. Edited April 13, 2016 by maniootek Link to comment Share on other sites More sharing options...
spudw2k Posted April 13, 2016 Share Posted April 13, 2016 (edited) 13 hours ago, maniootek said: Is there some limitation to use only one RegisterMsg? AFAIK you can only register a MSG ID to a single function...however you could write a notify function that would handle all of the controls/events you need. How I might approach it would be to copy the notification function from the GUITreeViewEX UDF (_GUITreeViewEx_WM_NOTIFY_Handler) to a new Notify function (i.e. _WM_NOTIFY), register the event yourself and add the functionality you need to it. Just for an example, in this script I made I use a custom _WM_NOTIFY function to handle multiple controls on different GUIs. Edited April 13, 2016 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
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