Yashied Posted June 5, 2009 Share Posted June 5, 2009 How to detect a change of focus highlighted item in the ListView? Thanks. expandcollapse popup#include <File.au3> #include <GUIConstantsEx.au3> #include <GUIListView.au3> #include <WindowsConstants.au3> $Form = GUICreate('', 600, 600) $ListView = GUICtrlCreateListView(' ', 10, 10, 280, 580, BitOR($LVS_NOCOLUMNHEADER, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING)) $hListView = GUICtrlGetHandle($ListView) _GUICtrlListView_SetColumnWidth($ListView, 0, 258 + 100) GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') GUISetState() $FileList = _FileListToArray('C:\WINDOWS\system32', '*.ini', 1) For $i = 1 To $FileList[0] GUICtrlCreateListViewItem($FileList[$i], $ListView) Next While 1 $Msg = GUIGetMsg() Switch $Msg Case 0 ContinueLoop Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tNMHDR = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $IDFrom = DllStructGetData($tNMHDR, 'IDFrom') Local $Index = DllStructGetData($tNMHDR, 'Index') Local $Code = DllStructGetData($tNMHDR, 'Code') Switch $IDFrom Case $ListView Switch $Code Case ??? $Item = _GUICtrlListView_GetItem($ListView, $Index) ConsoleWrite($Item[3] & @CR) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
KaFu Posted June 5, 2009 Share Posted June 5, 2009 expandcollapse popup#include <File.au3> #include <GUIConstantsEx.au3> #include <GUIListView.au3> #include <WindowsConstants.au3> $Form = GUICreate('', 600, 600) $ListView = GUICtrlCreateListView(' ', 10, 10, 280, 580, BitOR($LVS_NOCOLUMNHEADER, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING)) $hListView = GUICtrlGetHandle($ListView) _GUICtrlListView_SetColumnWidth($ListView, 0, 258 + 100) GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') GUISetState() $FileList = _FileListToArray('C:\WINDOWS\system32', '*.ini', 1) For $i = 1 To $FileList[0] GUICtrlCreateListViewItem($FileList[$i], $ListView) Next While 1 $Msg = GUIGetMsg() Switch $Msg Case 0 ContinueLoop Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tNMHDR = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $IDFrom = DllStructGetData($tNMHDR, 'IDFrom') Local $Index = DllStructGetData($tNMHDR, 'Index') Local $Code = DllStructGetData($tNMHDR, 'Code') ;ConsoleWrite($Code & @crlf) Switch $IDFrom Case $ListView Switch $Code Case -2 $aSelected = _GUICtrlListView_GetSelectedIndices($ListView, True) ;ConsoleWrite($aSelected[0] & @crlf) if $aSelected[0] > 0 then ;ConsoleWrite($aSelected[1] & @crlf) for $i = 1 to $aSelected[0] ConsoleWrite(_GUICtrlListView_GetItemText($ListView,$aSelected[$i]) & @crlf) next endif EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Â OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26)Â BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16)Â ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Yashied Posted June 5, 2009 Author Share Posted June 5, 2009 KaFu, thanks, but does not work with the keyboard. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
Zedna Posted June 5, 2009 Share Posted June 5, 2009 Another way: expandcollapse popup#include <File.au3> #include <GUIConstantsEx.au3> #include <GUIListView.au3> #include <WindowsConstants.au3> $Form = GUICreate('', 600, 600) $ListView = GUICtrlCreateListView(' ', 10, 10, 280, 580, BitOR($LVS_NOCOLUMNHEADER, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING)) $hListView = GUICtrlGetHandle($ListView) _GUICtrlListView_SetColumnWidth($ListView, 0, 258 + 100) GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') GUISetState() $FileList = _FileListToArray('C:\WINDOWS\system32', '*.ini', 1) For $i = 1 To $FileList[0] GUICtrlCreateListViewItem($FileList[$i], $ListView) Next While 1 $Msg = GUIGetMsg() Switch $Msg Case 0 ContinueLoop Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tNMHDR = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $IDFrom = DllStructGetData($tNMHDR, 'IDFrom') Local $Index = DllStructGetData($tNMHDR, 'Index') Local $Code = DllStructGetData($tNMHDR, 'Code') Switch $IDFrom Case $ListView Switch $Code Case $LVN_ITEMCHANGED $NMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam) ; if state has changed If BitAND(DllStructGetData($NMLISTVIEW, "Changed"), $LVIF_STATE) = $LVIF_STATE And _ DllStructGetData($NMLISTVIEW, "NewState") <> DllStructGetData($NMLISTVIEW, "OldState") Then ; take care of only newly selected items (not deselected ones) If BitAND(DllStructGetData($NMLISTVIEW, "NewState"), $LVIS_SELECTED) = $LVIS_SELECTED Then $Item = _GUICtrlListView_GetItem($ListView, $Index) ConsoleWrite($Item[3] & @CR) EndIf EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted June 5, 2009 Share Posted June 5, 2009 (edited) or modification for logging also deselection: Case $LVN_ITEMCHANGED $NMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam) ; if state has changed If BitAND(DllStructGetData($NMLISTVIEW, "Changed"), $LVIF_STATE) = $LVIF_STATE And _ DllStructGetData($NMLISTVIEW, "NewState") <> DllStructGetData($NMLISTVIEW, "OldState") Then $Item = _GUICtrlListView_GetItem($ListView, $Index) If BitAND(DllStructGetData($NMLISTVIEW, "NewState"), $LVIS_SELECTED) = $LVIS_SELECTED And _ BitAND(DllStructGetData($NMLISTVIEW, "OldState"), $LVIS_SELECTED) = 0 Then ConsoleWrite('selected: ' & $Item[3] & @CR) EndIf If BitAND(DllStructGetData($NMLISTVIEW, "NewState"), $LVIS_SELECTED) = 0 And _ BitAND(DllStructGetData($NMLISTVIEW, "OldState"), $LVIS_SELECTED) = $LVIS_SELECTED Then ConsoleWrite('deselected: ' & $Item[3] & @CR) EndIf EndIf EDIT: corrected: deselection was fired twice Edited July 17, 2012 by Jon Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
Yashied Posted June 5, 2009 Author Share Posted June 5, 2009 Another way: expandcollapse popup#include <File.au3> #include <GUIConstantsEx.au3> #include <GUIListView.au3> #include <WindowsConstants.au3> $Form = GUICreate('', 600, 600) $ListView = GUICtrlCreateListView(' ', 10, 10, 280, 580, BitOR($LVS_NOCOLUMNHEADER, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS, $LVS_SORTASCENDING)) $hListView = GUICtrlGetHandle($ListView) _GUICtrlListView_SetColumnWidth($ListView, 0, 258 + 100) GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') GUISetState() $FileList = _FileListToArray('C:\WINDOWS\system32', '*.ini', 1) For $i = 1 To $FileList[0] GUICtrlCreateListViewItem($FileList[$i], $ListView) Next While 1 $Msg = GUIGetMsg() Switch $Msg Case 0 ContinueLoop Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tNMHDR = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $IDFrom = DllStructGetData($tNMHDR, 'IDFrom') Local $Index = DllStructGetData($tNMHDR, 'Index') Local $Code = DllStructGetData($tNMHDR, 'Code') Switch $IDFrom Case $ListView Switch $Code Case $LVN_ITEMCHANGED $NMLISTVIEW = DllStructCreate($tagNMLISTVIEW, $lParam) ; if state has changed If BitAND(DllStructGetData($NMLISTVIEW, "Changed"), $LVIF_STATE) = $LVIF_STATE And _ DllStructGetData($NMLISTVIEW, "NewState") <> DllStructGetData($NMLISTVIEW, "OldState") Then ; take care of only newly selected items (not deselected ones) If BitAND(DllStructGetData($NMLISTVIEW, "NewState"), $LVIS_SELECTED) = $LVIS_SELECTED Then $Item = _GUICtrlListView_GetItem($ListView, $Index) ConsoleWrite($Item[3] & @CR) EndIf EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFYx8 thanks to you Zedna. That's exactly what I wanted. I never had not previously worked with the ListView. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... 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