Albuquerquefx Posted December 10, 2007 Share Posted December 10, 2007 I've done quite a bit of searching, both here and in Google, to no avail. Perhaps I'm not using the right nomenclature... I've been using AutoIT for quite a while now, but I'm new to the GUI components. I have a parent window with several radio buttons, normal buttons, an input box and a listbox. If the client doesn't know what to key into the input field, there's a "Find" option that spawns a seperate child window. In that child window, there are a few more buttons, another input field, and another listbox. The user enters text to search against our SQL database. Sometimes their search will yield only a few results, sometimes their search can yield many thousands of results. They pick a single entry from the list box, press the OK button and are returned back to the parent with their selection now in the input field. Heh, I know that may sound pretty convoluted But here's my problem -- if the client does more than one search in that child window without closing it (IE they searched for "blah", but then realized that wasn't it, so they again searched for "bleh" instead) quite often the parent window goes missing a bunch of controls. The bigger problem is, my code is pretty large because of all the case handling, so I'm not immediately able to copy in an example. I'm right now working up a good example that will be easy to put into this forum without being so convoluted as to not allow people to see the problem Oh, and a few more notes: Each variable that's linked to a control is declared locally to the function, so I'm not overlapping variable names. There's a function for the parent window, and a seperate function for the child window. The parent window is set to @SW_DISABLE while the child window is functioning. I'm doing GUISwitch() to ensure I'm creating controls in the active GUI Link to comment Share on other sites More sharing options...
Albuquerquefx Posted December 10, 2007 Author Share Posted December 10, 2007 Ok, here's a prepared code snippet... All you need to do to replicate my problem is run this script, click "Find" at the main window. In the new child window, click search ONCE, select anything from the listbox below and press OK. You will be returned to the parent window without issue. But if you click the "Find" button, click search several times, and then select something and press ok -- the parent window will be missing a large section of it's controls. Why? And how do I prevent this? I know the below code does basically nothing; the data is all purely random and the input fields do very little. But it's enough to show my problem, so any help is greatly appreciated! expandcollapse popup#include <GuiConstants.au3> #NoTrayIcon MainGui() Func MainGUI() Local $MainWindow = GuiCreate("Demo Window", 420, 320,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) GUICtrlCreateGroup("Source:", 10, 20, 120, 110, $BS_GROUPBOX) Local $Radio_1 = GuiCtrlCreateRadio("Radio 1", 30, 40, 90, 20) Local $Radio_2 = GuiCtrlCreateRadio("Radio 2", 30, 60, 70, 20) Local $Radio_3 = GuiCtrlCreateRadio("Radio 3", 30, 80, 70, 20) Local $Radio_4 = GuiCtrlCreateRadio("Radio 4", 30, 100, 70, 20) GUICtrlSetState($Radio_1,$GUI_CHECKED) GUICtrlCreateGroup("",-99,-99,1,1) Local $Input_Name = GuiCtrlCreateInput("", 140, 50, 240, 20) Local $Button_Populate = GuiCtrlCreateButton("Find...", 170, 80, 80, 30) Local $Button_Preview = GuiCtrlCreateButton("Preview", 270, 80, 80, 30) Local $ListBox = GuiCtrlCreateList("", 20, 160, 390, 110) Local $Button_Next1 = GuiCtrlCreateButton("Next >>", 330, 280, 80, 30) GUICtrlSetState($Button_Next1,$GUI_DISABLE) GUICtrlSetState($Input_Name,$GUI_FOCUS) GuiSetState() While 1 $msg = GuiGetMsg() Select case $msg = $Radio_1 GUICtrlSetData($Input_Name,"") GUICtrlSetState($Input_Name,$GUI_FOCUS) GUICtrlSetState($Button_Next1,$GUI_DISABLE) case $msg = $Radio_2 GUICtrlSetData($Input_Name,"") GUICtrlSetState($Input_Name,$GUI_FOCUS) GUICtrlSetState($Button_Next1,$GUI_DISABLE) case $msg = $Radio_3 GUICtrlSetData($Input_Name,"") GUICtrlSetState($Input_Name,$GUI_FOCUS) GUICtrlSetState($Button_Next1,$GUI_DISABLE) case $msg = $Radio_4 GUICtrlSetData($Input_Name,"") GUICtrlSetState($Input_Name,$GUI_FOCUS) GUICtrlSetState($Button_Next1,$GUI_DISABLE) case $msg = $Button_Populate GUISetState(@SW_DISABLE,$MainWindow) GUICtrlSetData($Input_Name,Populate()) GUISetState(@SW_ENABLE,$MainWindow) if not $Input_Name = "" Then GuiCtrlSetState($Button_Next1,BitXOR($GUI_ENABLE,$GUI_FOCUS)) Else GuiCtrlSetState($Input_Name,$GUI_FOCUS) GUICtrlSetState($Button_Next1,$GUI_DISABLE) EndIf case $msg = $GUI_EVENT_CLOSE Exit(0) EndSelect WEnd EndFunc Func Populate() Local $SearchWindow = GuiCreate("Populate Search", 390, 330,-1,-1) GUISwitch($SearchWindow) Local $SearchField = GuiCtrlCreateInput("", 20, 50, 300, 20) Local $Button_Search = GuiCtrlCreateButton("Search", 20, 80, 80, 30) Local $Button_OK = GuiCtrlCreateButton("OK", 110, 80, 80, 30) GuiCtrlCreateLabel("Search Results:", 20, 120, 80, 20) Local $Label_Searched = GuiCtrlCreateLabel("-", 100, 120, 40, 20) Local $SearchList = GuiCtrlCreateListView("Col A | Col B ", 20, 140, 350, 160,BitOR($LVS_REPORT,$LVS_NOSORTHEADER,$LVS_SHOWSELALWAYS,$LVS_SINGLESEL)) GUICtrlSetState($Button_OK,$GUI_DISABLE) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE $ReturnValue = "" ExitLoop case $msg = $Button_Search $NumRecords = Round(Random(1,1000),0) GUICtrlSetData($SearchField,"") GUICtrlDelete($SearchList) $SearchList = GuiCtrlCreateListView("Col A | Col B ", 20, 140, 350, 160,BitOR($LVS_REPORT,$LVS_NOSORTHEADER,$LVS_SHOWSELALWAYS,$LVS_SINGLESEL)) For $i = 1 to $NumRecords GUICtrlCreateListViewItem("Item " & $i & "|Blahblahblah",$SearchList) Next GUICtrlSetData($Label_Searched,$NumRecords) case $msg > 4108 GUICtrlSetState($Button_OK,$GUI_ENABLE) GUICtrlSetData($SearchField,GUICtrlRead(GUICtrlRead($SearchList)),2) case $msg = $Button_OK $ReturnValue = GUICtrlRead($SearchField) ExitLoop EndSelect WEnd GUIDelete($SearchWindow) Return $ReturnValue EndFunc Link to comment Share on other sites More sharing options...
kjbopp Posted December 10, 2007 Share Posted December 10, 2007 Not sure if you've solved this or not but I commented out the following line: GUICtrlDelete($SearchList) ...and it seemed to leave the contents of the parent window in place. Ok, here's a prepared code snippet... All you need to do to replicate my problem is run this script, click "Find" at the main window. In the new child window, click search ONCE, select anything from the listbox below and press OK. You will be returned to the parent window without issue. But if you click the "Find" button, click search several times, and then select something and press ok -- the parent window will be missing a large section of it's controls. Why? And how do I prevent this? I know the below code does basically nothing; the data is all purely random and the input fields do very little. But it's enough to show my problem, so any help is greatly appreciated! expandcollapse popup#include <GuiConstants.au3> #NoTrayIcon MainGui() Func MainGUI() Local $MainWindow = GuiCreate("Demo Window", 420, 320,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) GUICtrlCreateGroup("Source:", 10, 20, 120, 110, $BS_GROUPBOX) Local $Radio_1 = GuiCtrlCreateRadio("Radio 1", 30, 40, 90, 20) Local $Radio_2 = GuiCtrlCreateRadio("Radio 2", 30, 60, 70, 20) Local $Radio_3 = GuiCtrlCreateRadio("Radio 3", 30, 80, 70, 20) Local $Radio_4 = GuiCtrlCreateRadio("Radio 4", 30, 100, 70, 20) GUICtrlSetState($Radio_1,$GUI_CHECKED) GUICtrlCreateGroup("",-99,-99,1,1) Local $Input_Name = GuiCtrlCreateInput("", 140, 50, 240, 20) Local $Button_Populate = GuiCtrlCreateButton("Find...", 170, 80, 80, 30) Local $Button_Preview = GuiCtrlCreateButton("Preview", 270, 80, 80, 30) Local $ListBox = GuiCtrlCreateList("", 20, 160, 390, 110) Local $Button_Next1 = GuiCtrlCreateButton("Next >>", 330, 280, 80, 30) GUICtrlSetState($Button_Next1,$GUI_DISABLE) GUICtrlSetState($Input_Name,$GUI_FOCUS) GuiSetState() While 1 $msg = GuiGetMsg() Select case $msg = $Radio_1 GUICtrlSetData($Input_Name,"") GUICtrlSetState($Input_Name,$GUI_FOCUS) GUICtrlSetState($Button_Next1,$GUI_DISABLE) case $msg = $Radio_2 GUICtrlSetData($Input_Name,"") GUICtrlSetState($Input_Name,$GUI_FOCUS) GUICtrlSetState($Button_Next1,$GUI_DISABLE) case $msg = $Radio_3 GUICtrlSetData($Input_Name,"") GUICtrlSetState($Input_Name,$GUI_FOCUS) GUICtrlSetState($Button_Next1,$GUI_DISABLE) case $msg = $Radio_4 GUICtrlSetData($Input_Name,"") GUICtrlSetState($Input_Name,$GUI_FOCUS) GUICtrlSetState($Button_Next1,$GUI_DISABLE) case $msg = $Button_Populate GUISetState(@SW_DISABLE,$MainWindow) GUICtrlSetData($Input_Name,Populate()) GUISetState(@SW_ENABLE,$MainWindow) if not $Input_Name = "" Then GuiCtrlSetState($Button_Next1,BitXOR($GUI_ENABLE,$GUI_FOCUS)) Else GuiCtrlSetState($Input_Name,$GUI_FOCUS) GUICtrlSetState($Button_Next1,$GUI_DISABLE) EndIf case $msg = $GUI_EVENT_CLOSE Exit(0) EndSelect WEnd EndFunc Func Populate() Local $SearchWindow = GuiCreate("Populate Search", 390, 330,-1,-1) GUISwitch($SearchWindow) Local $SearchField = GuiCtrlCreateInput("", 20, 50, 300, 20) Local $Button_Search = GuiCtrlCreateButton("Search", 20, 80, 80, 30) Local $Button_OK = GuiCtrlCreateButton("OK", 110, 80, 80, 30) GuiCtrlCreateLabel("Search Results:", 20, 120, 80, 20) Local $Label_Searched = GuiCtrlCreateLabel("-", 100, 120, 40, 20) Local $SearchList = GuiCtrlCreateListView("Col A | Col B ", 20, 140, 350, 160,BitOR($LVS_REPORT,$LVS_NOSORTHEADER,$LVS_SHOWSELALWAYS,$LVS_SINGLESEL)) GUICtrlSetState($Button_OK,$GUI_DISABLE) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE $ReturnValue = "" ExitLoop case $msg = $Button_Search $NumRecords = Round(Random(1,1000),0) GUICtrlSetData($SearchField,"") GUICtrlDelete($SearchList) $SearchList = GuiCtrlCreateListView("Col A | Col B ", 20, 140, 350, 160,BitOR($LVS_REPORT,$LVS_NOSORTHEADER,$LVS_SHOWSELALWAYS,$LVS_SINGLESEL)) For $i = 1 to $NumRecords GUICtrlCreateListViewItem("Item " & $i & "|Blahblahblah",$SearchList) Next GUICtrlSetData($Label_Searched,$NumRecords) case $msg > 4108 GUICtrlSetState($Button_OK,$GUI_ENABLE) GUICtrlSetData($SearchField,GUICtrlRead(GUICtrlRead($SearchList)),2) case $msg = $Button_OK $ReturnValue = GUICtrlRead($SearchField) ExitLoop EndSelect WEnd GUIDelete($SearchWindow) Return $ReturnValue EndFunc Link to comment Share on other sites More sharing options...
Albuquerquefx Posted December 10, 2007 Author Share Posted December 10, 2007 Not sure if you've solved this or not but I commented out the following line:GUICtrlDelete($SearchList)...and it seemed to leave the contents of the parent window in place.Tried your solution, and it did indeed leave the parent window intact.Problem now is, the ListBox isn't cleared between queries. Meaning the 2nd query's data is appended to the 1st query's data... I can't GUICtrlSetData($SearchList,"") to clear that puppy out, so how do I empty it if the user re-queries without deleting the object?And why would deleting and recreating the object blow away a bunch of controls on an unrelated window? Link to comment Share on other sites More sharing options...
zfisherdrums Posted December 10, 2007 Share Posted December 10, 2007 Hello Albuquerquefx, I don't have an adequate explanation of the culprit. There is a workaround for it, however. Add "#include <GuiListView.au3>". Replace the "GUICtrlDelete( $SearchList )" statement with "_GUICtrlListView_Destroy( $SearchList )". That works on my machine, albeit lightly tested. Let me know how it fares on your machine. Zach... Identify .NET controls by their design time namesLazyReader© could have read all this for you. Unit Testing for AutoItFolder WatcherWord Doc ComparisonThis here blog... Link to comment Share on other sites More sharing options...
Albuquerquefx Posted December 10, 2007 Author Share Posted December 10, 2007 Hello Albuquerquefx,I don't have an adequate explanation of the culprit. There is a workaround for it, however.Add "#include <GuiListView.au3>". Replace the "GUICtrlDelete( $SearchList )" statement with "_GUICtrlListView_Destroy( $SearchList )". That works on my machine, albeit lightly tested. Let me know how it fares on your machine.Zach...Nice.... That appears to have corrected the problem. I did quite a number of queries without any issues. Thanks for the help! 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