TimRude Posted October 16, 2022 Share Posted October 16, 2022 The code below displays the beginnings of a GUI with a ListView populated with 14 boxes (pseudo thumbnails), and the user can click and select only one icon at a time. However, I don't see an easy way to identify (from the GUIGetMsg function) when an item in my ListView has been clicked. All of the click messages just return the handle of the GUI, nowhere does it return the handle of the ListView control. What vital piece of the puzzle am I missing so that I can know when the user has clicked (anywhere) on the ListView? Since I limit the user to only selecting a single ListView item at a time, I can easily figure out which ListView item is selected if any (by using _GUICtrlListView_GetSelectedIndices) once I know the ListView has been clicked. I suppose I can maybe look at the mouse X & Y position returned in the array by the GUIGetMsg(1) call and then keep careful track of how the ListView is positioned and sized to see if the click fell inside that area, but is that really how this is normally done? Surely there has to be a better way of signaling a click on a ListView, isn't there? expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> ; Create GUI with a ListView control Global $hGUI = GUICreate("ListView", 700, 500, -1, -1, $WS_OVERLAPPEDWINDOW) Global $hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 630, 420, BitOR($LVS_ICON, $LVS_SINGLESEL, $LVS_SHOWSELALWAYS)) GUISetState(@SW_SHOW, $hGUI) ; Create and load ImageList control with psuedo thumbnails Global $SizeX = 160 ; width of each thumbnail Global $SizeY = 100 ; height of each thumbnail Global $hImgLst = _GUIImageList_Create($SizeX, $SizeY) Local $BoxColor = 0xFF0000 For $i = 0 To 13 ; create 14 pseudo thumbnails (boxes of varying colors) _GUIImageList_Add($hImgLst, _GUICtrlListView_CreateSolidBitMap($hListView, $BoxColor - ($i * 0x139d76), $SizeX, $SizeY)) Next _GUICtrlListView_SetImageList($hListView, $hImgLst, 0) ; Add the thumbnail images as items to the ListView For $i = 0 To 13 _GUICtrlListView_AddItem($hListView, "Item " & $i, $i) Next ; Process GUI messages, looping until the user exits Do Local $Msg = "" Local $aMsg = GUIGetMsg(1) Local $MsgNum = $aMsg[0] Switch $MsgNum Case 0 $Msg = "" ; $GUI_EVENT_NONE Case -3 $Msg = "$GUI_EVENT_CLOSE" Case -4 $Msg = "$GUI_EVENT_MINIMIZE" Case -5 $Msg = "$GUI_EVENT_RESTORE" Case -6 $Msg = "$GUI_EVENT_MAXIMIZE" Case -7 $Msg = "$GUI_EVENT_PRIMARYDOWN" Case -8 $Msg = "$GUI_EVENT_PRIMARYUP" Case -9 $Msg = "$GUI_EVENT_SECONDARYDOWN" Case -10 $Msg = "$GUI_EVENT_SECONDARYUP" Case -11 $Msg = "" ; $GUI_EVENT_MOUSEMOVE Case -12 $Msg = "$GUI_EVENT_RESIZED" Case -13 $Msg = "$GUI_EVENT_DROPPED" Case Else $Msg = $MsgNum EndSwitch If $Msg <> "" Then ConsoleWrite($Msg & " [" & _ArrayToString($aMsg) & "]" & @CRLF) Until $MsgNum = $GUI_EVENT_CLOSE GUIDelete() Exit Link to comment Share on other sites More sharing options...
Solution Dan_555 Posted October 16, 2022 Solution Share Posted October 16, 2022 I had a code which needed a doubleclick on the LW to work. Here is a modified code to use the single click: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> Local $test[5][2] = [['.au3', 'AutoIt'], ['.ahk', 'Auto Hotkey'], ['.txt', 'text'],['.sdlbas', 'Sdl Basic'], ['.html', 'Webpage']] $Form1 = GUICreate("Create New File", 210, 307, -1,-1, $WS_CAPTION , $WS_EX_TOOLWINDOW) $List = GUICtrlCreateListView("", 5,5, 200, 200) _GUICtrlListView_InsertColumn($List, 0, "Extension", 80) _GUICtrlListView_InsertColumn($List, 1, "Name", 130) _GUICtrlListView_AddArray($List, $test) $Button1 = GUICtrlCreateButton("Ok", 16, 214, 45, 26) $Button2 = GUICtrlCreateButton("Cancel", 140, 214, 45, 26) $cDummy = GUICtrlCreateDummy() GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $Button2 Exit Case $Button1, $cDummy local $tmptxt=StringSplit(_GUICtrlListView_GetItemTextString($List), "|")[1] if StringLen($tmptxt)>0 then MsgBox(0, "test", $tmptxt) EndIf EndSwitch WEnd ;================================================================================ Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView $hWndListView = $List If Not IsHWnd($List) Then $hWndListView = GUICtrlGetHandle($List) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_CLICK GUICtrlSendToDummy($cDummy) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc TimRude and pixelsearch 1 1 Some of my script sourcecode Link to comment Share on other sites More sharing options...
TimRude Posted October 16, 2022 Author Share Posted October 16, 2022 @Dan_555 Thanks! That WM_NOTIFY routine tossing the click back to a dummy control was the missing piece. I've extracted the necessary bits and integrated them into my code and it's working fine now. Much appreciated! 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