Scriptonize Posted August 5, 2011 Share Posted August 5, 2011 (edited) Hi, While updating a script written in AutoIT V3.2.8.1 for AutoIT V3.3.6.1 I have run into a problem. When I use the GUICtrlSetOnEvent function for a listview it always fails (returns 0), while using the same function for a button or a system event, it works as expected. The problem doesn't occur within AutoIT 3.2.8.1. What am I doing wrong? I've attached an example script that demonstrates my problem. Console output: GUICtrlSetOnEvent($h_lstvwWrkCodes,lstViewWrkCodesClicked) returns: 0 GUICtrlSetOnEvent($h_btnDel,DelClicked) returns: 1 GUICtrlSetOnEvent($h_btnAdd,AddClicked) returns: 1 GUICtrlSetOnEvent($h_btnCancel,CancelClicked) returns: 1 GUICtrlSetOnEvent($h_btnExit,ExitClicked) returns: 1 GUISetOnEvent($GUI_EVENT_CLOSE, CancelClicked) returns: 1 expandcollapse popupGlobal $h_btnAdd ; handle to Add button Global $h_btnCancel ; handle to Cancel button Global $h_btnDel ; handle to Delete button Global $h_btnExit ; handle to Exit button Global $h_frmWrkCodes ; handle to main form WrkCodes Global $h_lblWrkCode ; handle to label lblWrkCode Global $h_lblWrkCodeRemark ; handle to label lblWrkCodeRemark Global $h_inpWrkCode ; handle to input box inpWrkCode Global $h_inpWrkCodeRemark ; handle to input box inpwrkCodeRemark Global $h_lstvwWrkCodes ; handle to listview lstvwWrkCodes Global $bln_DbgMode = 1 ; boolean var used to indicate if we are running in debuging mode #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #Include <Array.au3> #include <Misc.au3> AutoItSetOption("MustDeclareVars", 1) AutoItSetOption("GUIOnEventMode", 1) ShowFrm() While 1 Sleep(10) WEnd Exit Func ShowFrm() Local $var_Style, $var_ExStyle, $var_EvntRetval Local $int_Left, $int_Top, $int_Width, $int_Height ;Main form $int_Width = 589 $int_Height = 423 $int_Left = -1 $int_Top = -1 $h_frmWrkCodes = GUICreate("Work Codes", $int_Width, $int_Height, $int_Left, $int_Top) ;Label CodeRemark $int_Left = 66 $int_Top = 31 $int_Width = 35 $int_Height = 35 $h_lblWrkCode = GUICtrlCreateLabel("Code: ", $int_Left, $int_Top, $int_Width, $int_Height, $SS_RIGHT) ;Label CodeRemark $int_Left = 55 $int_Top = 52 $int_Width = 47 $int_Height = 17 $h_lblWrkCodeRemark = GUICtrlCreateLabel("Remark: ", $int_Left, $int_Top, $int_Width, $int_Height, $SS_RIGHT) ;Inputbox Code $int_Left = 108 $int_Top = 27 $int_Width = 247 $int_Height = 21 $h_inpWrkCode = GUICtrlCreateInput("", $int_Left, $int_Top, $int_Width, $int_Height) ;Inputbox CodeRemark $int_Left = 108 $int_Top = 49 $int_Width = 460 $int_Height = 21 $h_inpWrkCodeRemark = GUICtrlCreateInput("", $int_Left, $int_Top, $int_Width, $int_Height, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN)) ;ListView $var_Style = BitOR($LVS_EDITLABELS,$LVS_ALIGNLEFT,$LVS_REPORT,$LVS_SINGLESEL,$LVS_SORTASCENDING) $var_ExStyle = BitOR($LVS_EX_DOUBLEBUFFER,$LVS_EX_FULLROWSELECT,$LVS_EX_GRIDLINES,$LVS_EX_HEADERDRAGDROP,$LVS_EX_ONECLICKACTIVATE,$LVS_EX_TWOCLICKACTIVATE) $int_Left = 111 $int_Top = 117 $int_Width = 460 $int_Height = 217 $h_lstvwWrkCodes = _GUICtrlListView_Create($h_frmWrkCodes,"Code|Remark",$int_Left, $int_Top, $int_Width, $int_Height,$var_Style) _GUICtrlListView_SetExtendedListViewStyle($h_lstvwWrkCodes,$var_ExStyle) _GUICtrlListView_SetColumnWidth($h_lstvwWrkCodes,0,104) _GUICtrlListView_SetColumnWidth($h_lstvwWrkCodes,1,356) $var_EvntRetval = GUICtrlSetOnEvent($h_lstvwWrkCodes,"lstViewWrkCodesClicked") If $bln_DbgMode = 1 Then ConsoleWrite("GUICtrlSetOnEvent($h_lstvwWrkCodes,lstViewWrkCodesClicked) returns: " & $var_EvntRetval & @CR) ;Button: Delete/Remove $int_Left = 270 $int_Top = 377 $int_Width = 75 $int_Height = 25 $h_btnDel = GUICtrlCreateButton("&Remove", $int_Left, $int_Top, $int_Width, $int_Height, $WS_GROUP) $var_EvntRetval = GUICtrlSetOnEvent($h_btnDel,"DelClicked") If $bln_DbgMode = 1 Then ConsoleWrite("GUICtrlSetOnEvent($h_btnDel,DelClicked) returns: " & $var_EvntRetval & @CR) ;Button: Add $int_Left = $int_Left + $int_Width ;287 $h_btnAdd = GUICtrlCreateButton("&Add", $int_Left, $int_Top, $int_Width, $int_Height, $WS_GROUP) $var_EvntRetval = GUICtrlSetOnEvent($h_btnAdd,"AddClicked") If $bln_DbgMode = 1 Then ConsoleWrite("GUICtrlSetOnEvent($h_btnAdd,AddClicked) returns: " & $var_EvntRetval & @CR) ;Button: Cancel $int_Left = $int_Left + $int_Width $h_btnCancel = GUICtrlCreateButton("&Cancel", $int_Left, $int_Top, $int_Width, $int_Height, $WS_GROUP) $var_EvntRetval = GUICtrlSetOnEvent($h_btnCancel,"CancelClicked") If $bln_DbgMode = 1 Then ConsoleWrite("GUICtrlSetOnEvent($h_btnCancel,CancelClicked) returns: " & $var_EvntRetval & @CR) ;Button: Exit $int_Left = $int_Left + $int_Width $h_btnExit = GUICtrlCreateButton("Save and E&xit", $int_Left, $int_Top, $int_Width, $int_Height, $WS_GROUP) $var_EvntRetval = GUICtrlSetOnEvent($h_btnExit,"ExitClicked") If $bln_DbgMode = 1 Then ConsoleWrite("GUICtrlSetOnEvent($h_btnExit,ExitClicked) returns: " & $var_EvntRetval & @CR) ;User closes form with 'X' $var_EvntRetval = GUISetOnEvent($GUI_EVENT_CLOSE, "CancelClicked") If $bln_DbgMode = 1 Then ConsoleWrite("GUISetOnEvent($GUI_EVENT_CLOSE, CancelClicked) returns: " & $var_EvntRetval & @CR) GUISetState(@SW_SHOW) ;$var_EvntRetval = GUISetOnEvent($GUI_EVENT_SECONDARYUP,"lstViewWrkCodesClicked",$h_lstvwWrkCodes) ;If $bln_DbgMode = 1 Then ConsoleWrite("GUISetOnEvent($GUI_EVENT_SECONDARYUP,lstViewWrkCodesClicked,$h_lstvwWrkCodes) returns: " & $var_EvntRetval & @CR) EndFunc Func CancelClicked() MsgBox(0,"Info","Cancel Clicked") EndFunc Func AddClicked() MsgBox(0,"Info","Add Clicked") EndFunc Func DelClicked() MsgBox(0,"Info","Remove Clicked") EndFunc Func ExitClicked() MsgBox(0,"Info","'Save and Exit' Clicked, App will close") Exit EndFunc Func lstViewWrkCodesClicked() MsgBox(0,"Info","listView Clicked") EndFunc Edited August 5, 2011 by Scriptonize If you learn from It, it's not a mistake Link to comment Share on other sites More sharing options...
Scriptonize Posted August 5, 2011 Author Share Posted August 5, 2011 (edited) It seems that the problem is caused by the UDF "_GUICtrlListView_Create" When I make use of "GUICtrlCreateListView" the event is registered successfully. I'm running on XP with SP3. Can somebody confirm this? I know it is not recommended to mix UDF's and build in functions, but in this case I seem to have no choice. Is it safe to do so, despite all recommendations? Edited August 5, 2011 by Scriptonize If you learn from It, it's not a mistake Link to comment Share on other sites More sharing options...
BitByteBit Posted August 5, 2011 Share Posted August 5, 2011 You want to use CtrlSetOnEvent with your List View Items rather then the List View control itself. I personally use an array to hold all my control handles. Hope the code below helps. Opt('GuiOnEventMode', 1) Global $hGui, $hList, $hListItems[3] $hGui = GUICreate("Listview.", 515, 262, 192, 125) $hList = GUICtrlCreateListView("1", 0, 0, 420, 210) For $i = 0 To 2 $hListItems[$i] = GUICtrlCreateListViewItem("Item " & $i, $hList) GUICtrlSetOnEvent($hListItems[$i], '_ListViewEvent') Next GUISetOnEvent(-3, '_Exit') GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd Func _ListViewEvent() For $i = 0 To $hListItems[0] If @GUI_CtrlId = $hListItems[$i] Then ExitLoop Next ConsoleWrite('List view item clicked - ' & GUICtrlRead($hListItems[$i]) & @CRLF) EndFunc ;==>_ListViewEvent Func _Exit() Exit EndFunc ;==>_Exit Link to comment Share on other sites More sharing options...
Scriptonize Posted August 5, 2011 Author Share Posted August 5, 2011 Thank you for your reply BitByteBit.A really appreciate it.Your solution is not the part I'm having the problem with.It's about the combination of using the "_GUICtrlListView_Create" UDF with GuiCtrlsetOnEvent Function.Using it in that combination doesn't seem to work.Perhaps I'm doing something wrong, perhaps the UDF doesn't work as expected.That's what my question is about. If you learn from It, it's not a mistake Link to comment Share on other sites More sharing options...
GEOSoft Posted August 5, 2011 Share Posted August 5, 2011 As far as I can see from your code you are not doing anything that can't be done when you use the standard ListView control. _GUICtrlListView_SetColumnWidth() certainly works with the standard control and you probably don't need the _GUICtrlListView_SetExtendedStyle() since you should be able to set it directly when the control is created and even at that _GUICtrlListview_setextendedstyle from the UDF may work. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Scriptonize Posted August 5, 2011 Author Share Posted August 5, 2011 (edited) As far as I can see from your code you are not doing anything that can't be done when you use the standard ListView control._GUICtrlListView_SetColumnWidth() certainly works with the standard control and you probably don't need the _GUICtrlListView_SetExtendedStyle() since you should be able to set it directly when the control is created and even at that _GUICtrlListview_setextendedstyle from the UDF may work.Hi GEOSoft.Thank you for looking into my little problem.Indeed, in my example there are no exended styles used that couldn't also be done with the standard function.My code is just a small example (demonstrating the error) , not the actual code.I guess that the method I'm trying to use is not supported by the _GUICtrlListView_Create UDF.I'm going to use the standard function in combination with some UDF functions.When I receive errors or see strange behavior, I have a good clue what might be the cause. Edited August 5, 2011 by Scriptonize If you learn from It, it's not a mistake 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