Cambunctious Posted July 12, 2010 Share Posted July 12, 2010 I hope this question makes sense. Is it possible to for GuiGetMsg() to trigger for any item in a listview? In the following example, the MsgBox will only appear if the column headings are clicked, but not any of the items. (This code will probably not actually run) GUICreate("Ta Da!") $listview = GUICtrlCreateListView("Ta|Da") For $x = 1 to 10 GuiCtrlCreateListViewItem() Next GUISetState() Do $msg = GUIGetMsg() Switch $msg Case $listview MsgBox(0, "", "Ta Da!") EndSwitch Until $msg = $GUI_EVENT_CLOSE Thanks, Cameron Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted July 12, 2010 Share Posted July 12, 2010 GUIGetMsg will trigger for clicks on listview-items, yes. You just need to check for the items, not the listview. #include <GUIConstantsEx.au3> GUICreate("Ta Da!", 640, 480) $listview = GUICtrlCreateListView("Ta|Da", 0, 0, 640, 480) For $x = 1 to 10 GuiCtrlCreateListViewItem($x & "|" & Chr(Random(65, 90, 1)), $listview) Next GUISetState() Do $msg = GUIGetMsg() If $msg <> 0 Then ConsoleWrite($msg & @CRLF) Switch $msg Case $listview MsgBox(0, "", "Ta Da!") Case $listview +1 To $listview +10 MsgBox(0, "Pressed on item:", GUICtrlRead($msg)) EndSwitch Until $msg = $GUI_EVENT_CLOSE .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Cambunctious Posted July 12, 2010 Author Share Posted July 12, 2010 (edited) Case $listview +1 To $listview +10 That's a creative approach. If the listview has 1000 items will this still work? In other words, can I always assume that $listview + $n will always match with the items? Edited July 12, 2010 by Cambunctious Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted July 12, 2010 Share Posted July 12, 2010 (edited) Control id's are a internal thing to AutoIt, and when you create a new control the lowest unused one will be taken.That means that if you create all thousand in the beginning and never delete or add more it will work.So changing "For $x = 1 to 10" to "For $x = 1 to 1000" is no problem at all (just remember to change the $listview +10 too).But if you are going to be adding and removing controls, you're could get yourself in a very big mess.Depending on your situation, you may find it best to register WM_NOTIFY, and check for clicks that way.Here's a simplified example based partly of the script above, and partly of the example for _GUICtrlListView_Create (it's in the helpfile, you should check it).expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> GUICreate("Ta Da!", 640, 480) $hListView = GUICtrlCreateListView("Ta|Da", 0, 0, 640, 480) For $iX = 1 To 10 GUICtrlCreateListViewItem($iX & "|" & Chr(Random(65, 90, 1)), $hListView) Next GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam 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_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) MsgBox(0, "Pressed on item:", _GUICtrlListView_GetItemTextString($hListView, DllStructGetData($tInfo, "SubItem"))) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edited July 12, 2010 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Cambunctious Posted July 13, 2010 Author Share Posted July 13, 2010 Hmm...You're talking to a noob here. Could you explain that a little? I don't know the following commands: GUIRegisterMsg HWnd DllStructCreate I don't think _GUICtrlListView_Create is what I need in my case. It looks like that is suppose to be a GUI by itself. Also, I will be adding and removing items. Thanks for your help Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted July 13, 2010 Share Posted July 13, 2010 Errm I'm not sure what you're asking of me. The helpfile explains all those functions.I don't think _GUICtrlListView_Create is what I need in my case. It looks like that is suppose to be a GUI by itself.Not sure what you mean there either. It creates a ListView, like GUICtrlCreateListView. Did you run the example? .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface 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