rajeshwaran Posted September 2, 2010 Posted September 2, 2010 (edited) I have four columns in my listview, I am able retrive the subitem index from the function _GUICtrlListView_SubItemHitTest(), but I have four columns, I can't figure out which column's subitem selected. So, I have used the function _GUICtrlListView_GetSelectedColumn () to retrive the column information, but it always returns -1. Please find below my script file. expandcollapse popup#include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> ;--- Global Variables -- ;-- Window properties -- Global $ID_Window Global $Window_Title = "Generator" Global $Window_Width = 700 Global $Window_Height = 500 ;-- ListView 1 properties -- Global $ID_InputDevice_Gen_Config_ListView Global $Handle_InputDevice_Gen_Config_ListView ;--- Global Variables -- Global $Array_InDev_Genrl_Config_XYWH [4] = _ [ _ 10, _ ;-- Left -- 10, _ ;-- Top -- 500, _ ;-- Width -- 300 _ ;-- Height -- ] Global $Array_InDev_Genrl_Config_Columns [6] = _ [ _ "In. Device Name", _ "Input Fs", _ "Master Clck", _ "Decoder Type", _ "Dual Mono Mode", _ "Down Mix Mode" _ ] Global $Array_InDev_Genrl_Config_Items [18][6] = _ [ _ [ "std0_01", "48k", "amclki0", "ac3", "and", "mode0" ], _ [ "std1_01", "48k", "amclki0", "ac3", "and", "mode0" ], _ [ "std2_23", "48k", "amclki0", "ac3", "and", "mode0" ], _ [ "std3_23", "48k", "amclki0", "ac3", "and", "mode0" ], _ [ "capa_01", "48k", "amclki0", "ac3", "and", "mode0" ], _ [ "capb_01", "48k", "amclki0", "ac3", "and", "mode0" ], _ [ "capc_01", "48k", "amclki0", "ac3", "and", "mode0" ], _ [ "capa_23", "48k", "amclki0", "ac3", "and", "mode0" ], _ [ "capb_23", "48k", "amclki0", "ac3", "and", "mode0" ], _ [ "capc_23", "48k", "amclki0", "ac3", "and", "mode0" ], _ [ "hdmi_01", "48k", "amclki0", "ac3", "and", "mode0" ], _ [ "hdmi_23", "48k", "amclki0", "ac3", "and", "mode0" ], _ [ "esf_01", "48k", "amclki0", "ac3", "and", "mode0" ], _ [ "esf_23", "48k", "amclki0", "ac3", "and", "mode0" ], _ [ "pcmf_01", "48k", "amclki0", "ac3", "and", "mode0" ], _ [ "pcmf_23", "48k", "amclki0", "ac3", "and", "mode0" ], _ [ "pcm_mem_01", "48k", "amclki0", "ac3", "and", "mode0" ], _ [ "pcm_mem_23", "48k", "amclki0", "ac3", "and", "mode0" ] _ ] Global $Array_InDev_InputFs_Combo_List [4] = _ [ _ "48k", _ "44.1k", _ "32k", _ "null" _ ] Global $Array_InDev_MstrClck_Combo_List [7] = _ [ _ "amclki0", _ "stc0", _ "stc1", _ "stc2", _ "hdmi", _ "sif25", _ "null" _ ] Global $Array_InDev_DecType_Combo_List [9] = _ [ _ "ac3", _ "aac", _ "bc", _ "mp3", _ "lpcm", _ "ddp", _ "wma", _ "heaac", _ "null" _ ] Global $Array_InDev_DualMode_Combo_List [5] = _ [ _ "and", _ "dmain", _ "dsub", _ "mix", _ "null" _ ] Global $Array_InDev_DwnMix_Combo_List [5] = _ [ _ "mode0", _ "mode1", _ "multi", _ "auto", _ "null" _ ] ;-- Start Main Function -- Main() Func Main() ;-- Create a window -- $ID_Window = GUICreate($Window_Title, $Window_Width, $Window_Height, -1, -1) ;-- Create ListView for input device general configuration -- Create_ListView( $ID_Window, _ $ID_InputDevice_Gen_Config_ListView, _ $Handle_InputDevice_Gen_Config_ListView, _ $Array_InDev_Genrl_Config_XYWH, _ $Array_InDev_Genrl_Config_Columns, _ $Array_InDev_Genrl_Config_Items) GUISetState(@SW_SHOW) ;-- Register message for ListView notifications -- GUIRegisterMsg($WM_NOTIFY, "ListView_EventHandler") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd EndFunc ;-- Function to create a listview and assign items specified in the input array -- Func Create_ListView( ByRef $H_Window, ByRef $ID_ListView, ByRef $Handle_ListView, ByRef $Array_XYWH, ByRef $Array_Columns, ByRef $Array_Items) Local $Array_Element Local $ListView_Width = 0 Local $Loop = 0 ;-- Create ListView -- $ID_ListView = GUICtrlCreateListView( "", _ $Array_XYWH[0], _ $Array_XYWH[1], _ $Array_XYWH[2], _ $Array_XYWH[3], _ $LVS_SINGLESEL, _ $LVS_EX_GRIDLINES ) $Handle_ListView = GUICtrlGetHandle($ID_ListView) ;-- Set event handler for list view -- GUICtrlSetOnEvent($ID_ListView, "ListView_EventHandler") ;-- Add columns for ListView -- For $Array_Element In $Array_Columns _GUICtrlListView_AddColumn($Handle_ListView, $Array_Element) Next ;-- Add items for ListView -- _GUICtrlListView_AddArray($Handle_ListView, $Array_Items) ;-- Determine the column width -- For $Loop = 0 To UBound($Array_Columns) Step 1 Determine_ColumnWidth($Handle_ListView, $Loop) Next ;-- Center justify all columns -- For $Loop = 0 To UBound($Array_Columns) Step 1 _GUICtrlListView_JustifyColumn($Handle_ListView, $Loop + 1, 2) Next EndFunc Func Determine_ColumnWidth($Handle_ListView, $Column_Index = 0) Local $TotalNumberOfColumns = 0 Local $AutoWidth_Of_DataItems = 0 Local $AutoWidth_Of_Columns = 0 ;-- Get column count Local $TotalNumberOfColumns = _GUICtrlListView_GetColumnCount($Handle_ListView) ;-- If column index passed by user is greater than total number of columns then do needful-- If $Column_Index > $TotalNumberOfColumns Then $Column_Index = $TotalNumberOfColumns ;-- Set auto width for data items -- _GUICtrlListView_SetColumnWidth($Handle_ListView, $Column_Index, $LVSCW_AUTOSIZE) ;-- Get auto width assigned by AutoIt (for later comparision) -- $AutoWidth_Of_DataItems = _GUICtrlListView_GetColumn($Handle_ListView, $Column_Index) ;-- Set auto width for Columns Headers -- _GUICtrlListView_SetColumnWidth($Handle_ListView, $Column_Index, $LVSCW_AUTOSIZE_USEHEADER) ;-- Get auto width assigned by AutoIt (for later comparision) -- $AutoWidth_Of_Columns = _GUICtrlListView_GetColumn($Handle_ListView, $Column_Index) ;-- Compare and apply the suitable auto width to that column -- If $AutoWidth_Of_DataItems[4] < $AutoWidth_Of_Columns[4] Then _GUICtrlListView_SetColumnWidth($Handle_ListView, $Column_Index, $LVSCW_AUTOSIZE_USEHEADER) If $AutoWidth_Of_DataItems[4] > $AutoWidth_Of_Columns[4] Then _GUICtrlListView_SetColumnWidth($Handle_ListView, $Column_Index, $LVSCW_AUTOSIZE) EndFunc Func ListView_EventHandler($hWnd, $Msg, $wParam, $lParam) Local $tNotificationMessage Local $Handle_Control Local $Event_Occured ;-- From $lParam form the system structure $tagNMHDR -- $tNotification_Message = DllStructCreate($tagNMHDR, $lParam) ;-- From the above structure formed, retrive the handle of the control and event occured -- $Handle_Control = DllStructGetData($tNotification_Message, "hWndFrom") $Event_Occured = DllStructGetData($tNotification_Message, "Code") ;-- Classification of controls -- Switch $Handle_Control ;-- Check notification for ListView control (General config for input device) -- Case $Handle_InputDevice_Gen_Config_ListView ;-- Classification of events -- Switch $Event_Occured ;-- Check for mouse single click event -- Case $NM_CLICK Local $tLV_NotificationMessage ;-- From $lParam form the system structure $tagNMLISTVIEW -- $tLV_NotificationMessage = DllStructCreate($tagNMLISTVIEW, $lParam) ;-- From the above structure formed, retrive the notification message -- ;-- and confirm the event occured for "SubItem" -- If DllStructGetData($tLV_NotificationMessage, "SubItem") <> 0 Then ListView_Handle_SubItem_Event($Handle_InputDevice_Gen_Config_ListView) EndIf EndSwitch ;-- End switch for Classification of events -- EndSwitch ;-- End switch for Classification of controls -- Return $GUI_RUNDEFMSG EndFunc Func ListView_Handle_SubItem_Event(ByRef $Handle_ListView) Local $Array_HitInfo Local $Column_Selected $Column_Selected = _GUICtrlListView_GetSelectedColumn($ID_InputDevice_Gen_Config_ListView) $Array_HitInfo = _GUICtrlListView_SubItemHitTest($Handle_ListView) ;-- If True, position is in control's client window but not on an item -- If $Array_HitInfo[1] = -1 Then Return False ;-- For debug -- ConsoleWrite("Column Selected = " & $Column_Selected & " SubItem selected = " & $Array_HitInfo[0] & @LF) EndFunc Edited September 2, 2010 by rajeshwaran
rajeshwaran Posted September 2, 2010 Author Posted September 2, 2010 One alternate way I have found.The below is a concept: In multiple columns, each subitem is differentiated by it's item index. To uniquely identify a subitem we have to use "$tagNMITEMACTIVATE", we can retrive the below information from this structure.Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) _DebugPrint("$NM_CLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode & @LF & _ "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _ "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _ "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _ "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _ "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _ "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _ "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _ "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _ "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))For more details, refer the help: "_GUICtrlListView_HitTest" Morrison 1
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