Shinies Posted August 22, 2012 Share Posted August 22, 2012 Hey, I have recently returned to AutoIt after a few years, and am re-learning a lot of things. I have run into a problem that has me stumped. The main window in my program works great. What im trying to do is open up a child window that takes focus from the main window where the user can view/edit some info gathered from a UDF listview control. The user will then be able to either save or cancel once done editing the values in the controls. Gathering the data from the listview and displaying it in the child window works fine, however once the new GUI gets to the loop stage checking GUIGetMsg() it seems to be becoming unresponsive (need to force close the window). I have a few msgbox's in my script just for pinpointing where the script is hanging, so dont worry about those, and its pretty commented so shouldnt be too hard to follow. Ill include the function which contains child GUI window as well as the full script minus functions. Function calling creation of new GUI: expandcollapse popupFunc _EditMember($mem) Local $f, $lc, $i, $line ;Create Edit Member Window $WinEditMem = GUICreate($mem, 595, 227, 384, 145, Default, Default, $WinMain) $LabEditMemName = GUICtrlCreateLabel($mem, 112, 32, 32, 17) $LabEditMemScore = GUICtrlCreateLabel("Score:", 16, 80, 35, 17) $LabEditMemTc = GUICtrlCreateLabel("Troop Count:", 16, 112, 66, 17) $LabEditMemCoord = GUICtrlCreateLabel("Coords", 16, 144, 37, 17) $InputEditMemScore = GUICtrlCreateInput("-", 88, 80, 201, 21) $InputEditMemTc = GUICtrlCreateInput("-", 88, 112, 201, 21) $InputEditMemCoord = GUICtrlCreateInput("-", 88, 144, 201, 21) $EditEditMemNote = GUICtrlCreateEdit("Notes...", 296, 8, 289, 161) $ButtonEditMemSave = GUICtrlCreateButton("Save", 200, 184, 83, 25) $ButtonEditMemCancel = GUICtrlCreateButton("Cancel", 296, 184, 83, 25) GUISetState(@SW_SHOW, $WinEditMem) ;Get member data and display $f = FileOpen($ResDir & "\" & $allypointer & $MemDatatxt) $lc = _FileCountLines($ResDir & "\" & $allypointer & $MemDatatxt) ;Cycle through memdat.txt For $i = 1 to $lc $line = FileReadLine($f, $i) $line = StringSplit($line, "|") If $line[1] = $mem Then ;If the name of the member = name passed to function ;Update controls with member data GUICtrlSetData($InputEditMemTc, $line[2]) GUICtrlSetData($InputEditMemScore, $line[3]) GUICtrlSetData($InputEditMemCoord, $line[4]) ;GUICtrlSetData($InputEditMemCoord, NOTES placeholder) ExitLoop EndIf Next MsgBox(0, "", "1") ;Window events While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE MsgBox(0, "", "3") ExitLoop Case $ButtonEditMemCancel MsgBox(0, "", "4") ExitLoop EndSwitch WEnd ;Delete window on way out of function MsgBox(0, "", "7") FileClose($f) GUIDelete($WinEditMem) EndFunc Main program: expandcollapse popup;========================================================================================== ;Includes #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <File.au3> #include <Array.au3> #include <String.au3> #include <Date.au3> #include <IE.au3> #include <GuiStatusBar.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GuiTab.au3> ;========================================================================================== ;========================================================================================== ;Constant variables Global $WinMainTitle = "King's Empire Alliance Manager" Global $ProgVersion = "v1.00" Global $LastUpdate = "2012/05/02" Global $IsConnect = "Searching..." Global $IsUpToDate = "Searching..." ;Directory paths Global $ResDir = @ScriptDir & "\Resources" ;File names Global $SavedBoardtxt = "\SavedBoard.txt" Global $MsgBoardtxt = "\MsgBoard.html" Global $PrevMemDatatxt = "\PrevMemData.txt" Global $MemDatatxt = "\MemData.txt" Global $Indextxt = "\Index.txt" Global $AllyLogojpg = "\logo.jpg" ;Global varliables Global $totstr = "0" Global $totscore = "0" Global $prevtotscore = "0" Global $prevtotstr = "0" ;Initial allaince to load $f = FileOpen($ResDir & $Indextxt) Global $allypointer = FileReadLine($f, 1) FileClose($f) ;Tab globals Global $tabcur Global $tabprev = "0" ;========================================================================================== ;Declare onexit function OnAutoItExitRegister( "_OnExit") $WinMain = GUICreate($WinMainTitle, 750, 675) ;Tabs $TabMain = _GUICtrlTab_Create($WinMain, 16, 95, 721, 20) ;Status bar Local $vPartEdge[2] = [500, 600] Local $vPartText[2] = [@Tab & _NowDate(), @TAB & $IsConnect] $StatusBarMain = _GUICtrlStatusBar_Create($WinMain, $vPartEdge, $vPartText) Global $AllyPic = GUICtrlCreatePic($ResDir & "\" & $allypointer & $AllyLogojpg, 16, 15, 400, 100) $LabelMainLastUpdate = GUICtrlCreateLabel("Last Updated:", 428, 25, 70, 17) $LabLastUpdate = GUICtrlCreateLabel($LastUpdate, 503, 25, 80, 17) $LabIsUpToDate = GUICtrlCreateLabel($IsUpToDate, 473, 45, 80, 17) $LabMainProgVersion = GUICtrlCreateLabel($ProgVersion, 712, 5, 31, 17) $ButtonMainConnect = GUICtrlCreateButton("Connect", 430, 85, 147, 17) $ButtonMainSync = GUICtrlCreateButton("Sync", 592, 24, 147, 17) $ButtonMainWiki = GUICtrlCreateButton("WiKi", 592, 48, 147, 17) $ButtonMainMaps = GUICtrlCreateButton("Maps", 592, 72, 147, 17) $ButtonMainChat = GUICtrlCreateButton("Chat", 592, 96, 147, 17) ;Group alliance $GroupMainAlly = GUICtrlCreateGroup("Alliance:-", 16, 120, 721, 115) $LabMainAllyStr = GUICtrlCreateLabel("Total Strength:", 120, 183, 74, 17) $LabMainAllyScore = GUICtrlCreateLabel("Total Score:", 120, 208, 62, 17) $AllyStr = GUICtrlCreateLabel("-", 200, 183, 75, 17) $AllyScore = GUICtrlCreateLabel("-", 200, 208, 75, 17) $ProgressMainAllyStr = GUICtrlCreateProgress(120, 150, 475, 25) GUICtrlSetData(-1, 73) $LabMainStrAllyGainD = GUICtrlCreateLabel("/day", 315, 183, 75, 17) $LabMainStrAllyGainW = GUICtrlCreateLabel("/week", 415, 183, 75, 17) $LabMainStrAllyGainM = GUICtrlCreateLabel("/month", 520, 183, 90, 17) $LabMainScoreAllyGainD = GUICtrlCreateLabel("/day", 315, 208, 75, 17) $LabMainScoreAllyGainW = GUICtrlCreateLabel("/week", 415, 208, 75, 17) $LabMainScoreAllyGainM = GUICtrlCreateLabel("/month", 520, 208, 90, 17) $LabMainAllyHealth = GUICtrlCreateLabel("Health:", 330, 132, 40, 17) ;Group members $GroupMainMembers = GUICtrlCreateGroup("Members:-", 16, 240, 721, 241) $ListViewMainMembers = _GUICtrlListView_Create($WinMain, "", 32, 264, 690, 200, BitOR($LVS_SINGLESEL, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($ListViewMainMembers, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_TWOCLICKACTIVATE, $LVS_EX_DOUBLEBUFFER)) _GUICtrlListView_AddColumn($ListViewMainMembers, "Member", 100) _GUICtrlListView_AddColumn($ListViewMainMembers, "Troops", 145) _GUICtrlListView_AddColumn($ListViewMainMembers, "Score", 145) _GUICtrlListView_AddColumn($ListViewMainMembers, "Co-ordinates", 300) Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($ListViewMainMembers)] ;Group message board $GroupMainMsgBoard = GUICtrlCreateGroup("Message Board:-", 16, 488, 721, 153) $oMainIE = _IECreateEmbedded() $MainIEControl = GUICtrlCreateObj($oMainIE, 27, 505, 700, 125) GUISetState(@SW_SHOW, $WinMain) ;Register interactions with the tab GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") _StartUpOperations() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Let me know if you guys need any more of the script or any other info! Hope this is all clear... Thanks for any help Smerk Link to comment Share on other sites More sharing options...
Andreik Posted August 22, 2012 Share Posted August 22, 2012 What windows become unresponsive: main or child windows?? For me both works well. Maybe I missed something. Link to comment Share on other sites More sharing options...
Shinies Posted August 22, 2012 Author Share Posted August 22, 2012 (edited) EDIT: Upon futher investigation it looks like the script actually runs okay when its not in the same directory as the files it is meant to parse... When it IS in the same directory it gets all the info and displays them in the inputs fine but when it gets to the while loop it becomes unresponsive... so confused... The script itself becomes unresponsive, leading to both windows freezing. When run separately they both work fine. The problem arises when the function _EditMember() is called from within the main script. I was trying to make it easier by excluding a bunch of code that is irrelevant but ill post the entire program: expandcollapse popup;========================================================================================== ;Includes #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include ;========================================================================================== ;========================================================================================== ;Constant variables Global $WinMainTitle = "King's Empire Alliance Manager" Global $ProgVersion = "v1.00" Global $LastUpdate = "2012/05/02" Global $IsConnect = "Searching..." Global $IsUpToDate = "Searching..." ;Directory paths Global $ResDir = @ScriptDir & "Resources" ;File names Global $SavedBoardtxt = "SavedBoard.txt" Global $MsgBoardtxt = "MsgBoard.html" Global $PrevMemDatatxt = "PrevMemData.txt" Global $MemDatatxt = "MemData.txt" Global $Indextxt = "Index.txt" Global $AllyLogojpg = "logo.jpg" ;Global varliables Global $totstr = "0" Global $totscore = "0" Global $prevtotscore = "0" Global $prevtotstr = "0" ;Initial allaince to load $f = FileOpen($ResDir & $Indextxt) Global $allypointer = FileReadLine($f, 1) FileClose($f) ;Tab globals Global $tabcur Global $tabprev = "0" ;========================================================================================== ;Declare onexit function OnAutoItExitRegister( "_OnExit") $WinMain = GUICreate($WinMainTitle, 750, 675) ;Tabs $TabMain = _GUICtrlTab_Create($WinMain, 16, 95, 721, 20) ;Status bar Local $vPartEdge[2] = [500, 600] Local $vPartText[2] = [@Tab & _NowDate(), @TAB & $IsConnect] $StatusBarMain = _GUICtrlStatusBar_Create($WinMain, $vPartEdge, $vPartText) Global $AllyPic = GUICtrlCreatePic($ResDir & "" & $allypointer & $AllyLogojpg, 16, 15, 400, 100) $LabelMainLastUpdate = GUICtrlCreateLabel("Last Updated:", 428, 25, 70, 17) $LabLastUpdate = GUICtrlCreateLabel($LastUpdate, 503, 25, 80, 17) $LabIsUpToDate = GUICtrlCreateLabel($IsUpToDate, 473, 45, 80, 17) $LabMainProgVersion = GUICtrlCreateLabel($ProgVersion, 712, 5, 31, 17) $ButtonMainConnect = GUICtrlCreateButton("Connect", 430, 85, 147, 17) $ButtonMainSync = GUICtrlCreateButton("Sync", 592, 24, 147, 17) $ButtonMainWiki = GUICtrlCreateButton("WiKi", 592, 48, 147, 17) $ButtonMainMaps = GUICtrlCreateButton("Maps", 592, 72, 147, 17) $ButtonMainChat = GUICtrlCreateButton("Chat", 592, 96, 147, 17) ;Group alliance $GroupMainAlly = GUICtrlCreateGroup("Alliance:-", 16, 120, 721, 115) $LabMainAllyStr = GUICtrlCreateLabel("Total Strength:", 120, 183, 74, 17) $LabMainAllyScore = GUICtrlCreateLabel("Total Score:", 120, 208, 62, 17) $AllyStr = GUICtrlCreateLabel("-", 200, 183, 75, 17) $AllyScore = GUICtrlCreateLabel("-", 200, 208, 75, 17) $ProgressMainAllyStr = GUICtrlCreateProgress(120, 150, 475, 25) GUICtrlSetData(-1, 73) $LabMainStrAllyGainD = GUICtrlCreateLabel("/day", 315, 183, 75, 17) $LabMainStrAllyGainW = GUICtrlCreateLabel("/week", 415, 183, 75, 17) $LabMainStrAllyGainM = GUICtrlCreateLabel("/month", 520, 183, 90, 17) $LabMainScoreAllyGainD = GUICtrlCreateLabel("/day", 315, 208, 75, 17) $LabMainScoreAllyGainW = GUICtrlCreateLabel("/week", 415, 208, 75, 17) $LabMainScoreAllyGainM = GUICtrlCreateLabel("/month", 520, 208, 90, 17) $LabMainAllyHealth = GUICtrlCreateLabel("Health:", 330, 132, 40, 17) ;Group members $GroupMainMembers = GUICtrlCreateGroup("Members:-", 16, 240, 721, 241) $ListViewMainMembers = _GUICtrlListView_Create($WinMain, "", 32, 264, 690, 200, BitOR($LVS_SINGLESEL, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($ListViewMainMembers, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_TWOCLICKACTIVATE, $LVS_EX_DOUBLEBUFFER)) _GUICtrlListView_AddColumn($ListViewMainMembers, "Member", 100) _GUICtrlListView_AddColumn($ListViewMainMembers, "Troops", 145) _GUICtrlListView_AddColumn($ListViewMainMembers, "Score", 145) _GUICtrlListView_AddColumn($ListViewMainMembers, "Co-ordinates", 300) Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($ListViewMainMembers)] ;Group message board $GroupMainMsgBoard = GUICtrlCreateGroup("Message Board:-", 16, 488, 721, 153) $oMainIE = _IECreateEmbedded() $MainIEControl = GUICtrlCreateObj($oMainIE, 27, 505, 700, 125) GUISetState(@SW_SHOW, $WinMain) ;Register interactions with the tab GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") _StartUpOperations() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _StartUpOperations() _ReadMemData() _CalcAllyTotals() _CalcAllyRates() _StartMessageBoard() _StartTabs() EndFunc Func _OnExit() ;Destroy controls to free memory _GUICtrlListView_Destroy($ListViewMainMembers) _GUICtrlStatusBar_Destroy($StatusBarMain) _GUICtrlTab_Destroy($TabMain) EndFunc Func _ReadMemData() ;============================================ ; Update members list ;============================================ Local $f, $lc, $line, $i, $memdat ;Delete any previous items _GUICtrlListView_DeleteAllItems($ListViewMainMembers) $f = FileOpen($ResDir & "" & $allypointer & $MemDatatxt) $lc = _FileCountLines($ResDir & "" & $allypointer & $MemDatatxt) ;Loop through and parse data from file For $i = 1 To $lc $line = FileReadLine($f, $i) If $line = "~" Then ExitLoop EndIf $memdat = StringSplit($line, "|") ;Add data to listview _GUICtrlListView_AddItem($ListViewMainMembers, $memdat[1]) _GUICtrlListView_AddSubItem($ListViewMainMembers, ($i - 1), $memdat[2], 1) _GUICtrlListView_AddSubItem($ListViewMainMembers, ($i - 1), $memdat[3], 2) _GUICtrlListView_AddSubItem($ListViewMainMembers, ($i - 1), $memdat[4], 3) Next FileClose($f) EndFunc ;==>_ReadMemData Func _CalcAllyTotals() ;============================================ ; Calculate alliance totals ;============================================ Local $ic, $i, $tcval ;Delete any previous totals $totstr = "0" $totscore = "0" $ic = _GUICtrlListView_GetItemCount($ListViewMainMembers) ;Loop through and gather data from listview For $i = 1 To $ic $tcval = _GUICtrlListView_GetItemText($ListViewMainMembers, ($i - 1), 1) $tcval = StringReplace($tcval, ",", "") $sval = _GUICtrlListView_GetItemText($ListViewMainMembers, ($i - 1), 2) $sval = StringReplace($sval, ",", "") $totstr = $totstr + $tcval $totscore = $totscore + $sval Next ;Display data GUICtrlSetData($AllyStr, $totstr) GUICtrlSetData($AllyScore, Int(($totscore/1000))) EndFunc ;==>_CalcAllyTotals Func _CalcAllyRates() ;============================================ ; Calculate gains per day/week/month ;============================================ Local $f, $lc, $line, $memdat, $tcval, $sval, $scorepd, $strpd ;Delete any previous totals $prevtotstr = "0" $prevtotscore = "0" $f = FileOpen($ResDir & "" & $allypointer & $PrevMemDatatxt) $lc = _FileCountLines($ResDir & "" & $allypointer & $PrevMemDatatxt) ;Loop through and parse data from file For $i = 1 To $lc $line = FileReadLine($f, $i) If $line = "~" Then ExitLoop EndIf $memdat = StringSplit($line, "|") $tcval = $memdat[2] $tcval = StringReplace($tcval, ",", "") $sval = $memdat[3] $sval = StringReplace($sval, ",", "") $prevtotstr = $prevtotstr + $tcval $prevtotscore = $prevtotscore + $sval Next ;Convert data $scorepd = (($totscore - $prevtotscore) / _DateDiff("D", $LastUpdate, _NowCalcDate())) $strpd = (($totstr - $prevtotstr) / _DateDiff("D", $LastUpdate, _NowCalcDate())) ;Display data GUICtrlSetData($LabMainScoreAllyGainD, Int($scorepd/1000) & "/Day") GUICtrlSetData($LabMainScoreAllyGainW, (Int($scorepd*7/1000)) & "/Week") GUICtrlSetData($LabMainScoreAllyGainM, (Int($scorepd*30/1000)) & "/Month") GUICtrlSetData($LabMainStrAllyGainD, Int($strpd) & "/Day") GUICtrlSetData($LabMainStrAllyGainW, (Int($strpd*7)) & "/Week") GUICtrlSetData($LabMainStrAllyGainM, (Int($strpd*30)) & "/Month") FileClose($f) EndFunc ;==>_CalcAllyRates Func _StartMessageBoard() Local $body, $f, $lc, $line, $i, $crisscross ;Navigate to messageboard page _IENavigate($oMainIE, $ResDir & $MsgBoardtxt) $body = _IETagNameGetCollection($oMainIE, "body", 0) ;Loop through saved boards.txt and collect entries $f = FileOpen($ResDir & $SavedBoardtxt) $lc = _FileCountLines($ResDir & $SavedBoardtxt) For $i = 1 to $lc ;Check if even or odd number for table color If Mod($i, 2) = 0 Then $crisscross = "b0b0b0" Else $crisscross = "d0d0d0" EndIf $line = FileReadLine($f, $i) $line = StringSplit($line, "|") ;Display entries _IEDocInsertHTML($body, ' [i]' & $line[1] & "[/i] [b]" & $line[2] & ":[/b] " & $line[3] & ' ', "afterbegin") Next FileClose($f) EndFunc Func _StartTabs() Local $f, $lc, $line, $i ;Open file and count how many alliances $f = FileOpen($ResDir & $Indextxt) $lc = _FileCountLines($ResDir & $Indextxt) ;For every allaince loop through and create a tab For $i = 1 to $lc $line = FileReadLine($f, $i) _GUICtrlTab_InsertItem($TabMain, ($i-1) , $line) Next FileClose($f) EndFunc ;===================================================================== ; Need to tidy this code in here! ;===================================================================== #region Native function from UDF Tabs Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTab, $hWndListView, $tInfo ;Declare which UDF controls to monitor $hWndTab = $TabMain If Not IsHWnd($TabMain) Then $hWndTab = GUICtrlGetHandle($TabMain) $hWndListView = $ListViewMainMembers If Not IsHWnd($ListViewMainMembers) Then $hWndTab = GUICtrlGetHandle($ListViewMainMembers) ;Native DLL stuff $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") ;Begin events check Switch $hWndFrom ;Events for tabmain Case $hWndTab Switch $iCode Case $NM_CLICK ;User clicks on tab control ;Check if a new tab has been selected $tabcur = _GUICtrlTab_GetCurSel($TabMain) If $tabcur <> $tabprev Then ;Tab has changed so load new tab data _TabChange() ;Set the previous tab to current tab $tabprev = $tabcur EndIf EndSwitch ;Events for listviewmain Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK ;A column is clicked $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) ;Sort items _GUICtrlListView_SimpleSort($ListViewMainMembers, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) Case $LVN_ITEMACTIVATE ;An item is double clicked ;Get member name and pass to editmember func $itemcur = _GUICtrlListView_GetSelectedIndices($ListViewMainMembers) $itemcur = _GUICtrlListView_GetItem($ListViewMainMembers, $itemcur) _EditMember($itemcur[3]) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc #endregion Func _TabChange() Local $f $f = FileOpen($ResDir & $Indextxt) ;Get alliance tab change points to $allypointer = FileReadLine($f, ($tabcur+1)) ;Update controls with new allaince data _ReadMemData() _CalcAllyTotals() _CalcAllyRates() ;Update allaince logo GUICtrlDelete($AllyPic) $AllyPic = GUICtrlCreatePic($ResDir & "" & $allypointer & $AllyLogojpg, 16, 15, 400, 100) FileClose($f) EndFunc Func _EditMember($mem) Local $f, $lc, $i, $line ;Create Edit Member Window $WinEditMem = GUICreate($mem, 595, 227, 384, 145, 0, 0, $WinMain) $LabEditMemName = GUICtrlCreateLabel($mem, 112, 32, 32, 17) $LabEditMemScore = GUICtrlCreateLabel("Score:", 16, 80, 35, 17) $LabEditMemTc = GUICtrlCreateLabel("Troop Count:", 16, 112, 66, 17) $LabEditMemCoord = GUICtrlCreateLabel("Coords", 16, 144, 37, 17) $InputEditMemScore = GUICtrlCreateInput("-", 88, 80, 201, 21) $InputEditMemTc = GUICtrlCreateInput("-", 88, 112, 201, 21) $InputEditMemCoord = GUICtrlCreateInput("-", 88, 144, 201, 21) $EditEditMemNote = GUICtrlCreateEdit("Notes...", 296, 8, 289, 161) $ButtonEditMemSave = GUICtrlCreateButton("Save", 200, 184, 83, 25) $ButtonEditMemCancel = GUICtrlCreateButton("Cancel", 296, 184, 83, 25) GUISetState(@SW_SHOW, $WinEditMem) ;Get member data and display $f = FileOpen($ResDir & "" & $allypointer & $MemDatatxt) $lc = _FileCountLines($ResDir & "" & $allypointer & $MemDatatxt) ;Cycle through memdat.txt For $i = 1 to $lc $line = FileReadLine($f, $i) $line = StringSplit($line, "|") If $line[1] = $mem Then ;If the name of the member = name passed to function ;Update controls with member data GUICtrlSetData($InputEditMemTc, $line[2]) GUICtrlSetData($InputEditMemScore, $line[3]) GUICtrlSetData($InputEditMemCoord, $line[4]) ;GUICtrlSetData($InputEditMemCoord, NOTES placeholder) ExitLoop EndIf Next MsgBox(0, "", "1") ;Window events While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE MsgBox(0, "", "3") ExitLoop Case $ButtonEditMemCancel MsgBox(0, "", "4") ExitLoop EndSwitch WEnd ;Delete window on way out of function MsgBox(0, "", "7") FileClose($f) GUIDelete($WinEditMem) EndFunc Edited August 22, 2012 by Smerk Link to comment Share on other sites More sharing options...
Andreik Posted August 22, 2012 Share Posted August 22, 2012 (edited) Can you provide some additional files to can populate the listview? It seems the function that creat child window is called when an item in listview it's double clicked. So would be nice to have something in listview. LE: actually I think I know why this happens. Because _EditMember function it's called in a callback and this is very wrong. Any callback function should run quickly and then return, in other case the application freezes or become not stable. Edited August 22, 2012 by Andreik Link to comment Share on other sites More sharing options...
Shinies Posted August 22, 2012 Author Share Posted August 22, 2012 That certainly sounds like what happening.. when you say the function is being called in a callback are you referring to it being called from the GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") callback to WM_NOTIFY? And if i move it outside of WM_NOTIFY it will no longer be unstable? again sorry i am still learning Link to comment Share on other sites More sharing options...
Andreik Posted August 22, 2012 Share Posted August 22, 2012 (edited) The solve can be a dummy control. I made some comments where I added something in your code. This should work without frezees. expandcollapse popup;========================================================================================== ;Includes ;Includes #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <File.au3> #include <Array.au3> #include <String.au3> #include <Date.au3> #include <IE.au3> #include <GuiStatusBar.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GuiTab.au3> ;========================================================================================== ;========================================================================================== ;Constant variables Global $WinMainTitle = "King's Empire Alliance Manager" Global $ProgVersion = "v1.00" Global $LastUpdate = "2012/05/02" Global $IsConnect = "Searching..." Global $IsUpToDate = "Searching..." ;Directory paths Global $ResDir = @ScriptDir & "Resources" ;File names Global $SavedBoardtxt = "SavedBoard.txt" Global $MsgBoardtxt = "MsgBoard.html" Global $PrevMemDatatxt = "PrevMemData.txt" Global $MemDatatxt = "MemData.txt" Global $Indextxt = "Index.txt" Global $AllyLogojpg = "logo.jpg" ;Global varliables Global $totstr = "0" Global $totscore = "0" Global $prevtotscore = "0" Global $prevtotstr = "0" ;Initial allaince to load $f = FileOpen($ResDir & $Indextxt) Global $allypointer = FileReadLine($f, 1) FileClose($f) ;Tab globals Global $tabcur Global $tabprev = "0" ;========================================================================================== ;Declare onexit function OnAutoItExitRegister( "_OnExit") $WinMain = GUICreate($WinMainTitle, 750, 675) ;##################################################################### Global $Dummy = GUICtrlCreateDummy() ;# ADDED A DUMMY CONTROL ;##################################################################### ;Tabs $TabMain = _GUICtrlTab_Create($WinMain, 16, 95, 721, 20) ;Status bar Local $vPartEdge[2] = [500, 600] Local $vPartText[2] = [@Tab & _NowDate(), @TAB & $IsConnect] $StatusBarMain = _GUICtrlStatusBar_Create($WinMain, $vPartEdge, $vPartText) Global $AllyPic = GUICtrlCreatePic($ResDir & "" & $allypointer & $AllyLogojpg, 16, 15, 400, 100) $LabelMainLastUpdate = GUICtrlCreateLabel("Last Updated:", 428, 25, 70, 17) $LabLastUpdate = GUICtrlCreateLabel($LastUpdate, 503, 25, 80, 17) $LabIsUpToDate = GUICtrlCreateLabel($IsUpToDate, 473, 45, 80, 17) $LabMainProgVersion = GUICtrlCreateLabel($ProgVersion, 712, 5, 31, 17) $ButtonMainConnect = GUICtrlCreateButton("Connect", 430, 85, 147, 17) $ButtonMainSync = GUICtrlCreateButton("Sync", 592, 24, 147, 17) $ButtonMainWiki = GUICtrlCreateButton("WiKi", 592, 48, 147, 17) $ButtonMainMaps = GUICtrlCreateButton("Maps", 592, 72, 147, 17) $ButtonMainChat = GUICtrlCreateButton("Chat", 592, 96, 147, 17) ;Group alliance $GroupMainAlly = GUICtrlCreateGroup("Alliance:-", 16, 120, 721, 115) $LabMainAllyStr = GUICtrlCreateLabel("Total Strength:", 120, 183, 74, 17) $LabMainAllyScore = GUICtrlCreateLabel("Total Score:", 120, 208, 62, 17) $AllyStr = GUICtrlCreateLabel("-", 200, 183, 75, 17) $AllyScore = GUICtrlCreateLabel("-", 200, 208, 75, 17) $ProgressMainAllyStr = GUICtrlCreateProgress(120, 150, 475, 25) GUICtrlSetData(-1, 73) $LabMainStrAllyGainD = GUICtrlCreateLabel("/day", 315, 183, 75, 17) $LabMainStrAllyGainW = GUICtrlCreateLabel("/week", 415, 183, 75, 17) $LabMainStrAllyGainM = GUICtrlCreateLabel("/month", 520, 183, 90, 17) $LabMainScoreAllyGainD = GUICtrlCreateLabel("/day", 315, 208, 75, 17) $LabMainScoreAllyGainW = GUICtrlCreateLabel("/week", 415, 208, 75, 17) $LabMainScoreAllyGainM = GUICtrlCreateLabel("/month", 520, 208, 90, 17) $LabMainAllyHealth = GUICtrlCreateLabel("Health:", 330, 132, 40, 17) ;Group members $GroupMainMembers = GUICtrlCreateGroup("Members:-", 16, 240, 721, 241) $ListViewMainMembers = _GUICtrlListView_Create($WinMain, "", 32, 264, 690, 200, BitOR($LVS_SINGLESEL, $LVS_REPORT)) _GUICtrlListView_SetExtendedListViewStyle($ListViewMainMembers, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_TWOCLICKACTIVATE, $LVS_EX_DOUBLEBUFFER)) _GUICtrlListView_AddColumn($ListViewMainMembers, "Member", 100) _GUICtrlListView_AddColumn($ListViewMainMembers, "Troops", 145) _GUICtrlListView_AddColumn($ListViewMainMembers, "Score", 145) _GUICtrlListView_AddColumn($ListViewMainMembers, "Co-ordinates", 300) Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($ListViewMainMembers)] ;Group message board $GroupMainMsgBoard = GUICtrlCreateGroup("Message Board:-", 16, 488, 721, 153) $oMainIE = _IECreateEmbedded() $MainIEControl = GUICtrlCreateObj($oMainIE, 27, 505, 700, 125) GUISetState(@SW_SHOW, $WinMain) ;Register interactions with the tab GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") _StartUpOperations() ;############################################################### _GUICtrlListView_InsertItem($ListViewMainMembers,"Test") ; THIS LINE IS JUST FOR TEST; TO ADD AN ITEM TO LISTVIEW ;############################################################### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit ;################################################## Case $Dummy ; # CHECK FOR DUMMY CONTROL _EditMember(GUICtrlRead($Dummy)) ; # CALL THE _EditMember function outside of callback ;################################################## EndSwitch WEnd Func _StartUpOperations() _ReadMemData() _CalcAllyTotals() _CalcAllyRates() _StartMessageBoard() _StartTabs() EndFunc Func _OnExit() ;Destroy controls to free memory _GUICtrlListView_Destroy($ListViewMainMembers) _GUICtrlStatusBar_Destroy($StatusBarMain) _GUICtrlTab_Destroy($TabMain) EndFunc Func _ReadMemData() ;============================================ ; Update members list ;============================================ Local $f, $lc, $line, $i, $memdat ;Delete any previous items _GUICtrlListView_DeleteAllItems($ListViewMainMembers) $f = FileOpen($ResDir & "" & $allypointer & $MemDatatxt) $lc = _FileCountLines($ResDir & "" & $allypointer & $MemDatatxt) ;Loop through and parse data from file For $i = 1 To $lc $line = FileReadLine($f, $i) If $line = "~" Then ExitLoop EndIf $memdat = StringSplit($line, "|") ;Add data to listview _GUICtrlListView_AddItem($ListViewMainMembers, $memdat[1]) _GUICtrlListView_AddSubItem($ListViewMainMembers, ($i - 1), $memdat[2], 1) _GUICtrlListView_AddSubItem($ListViewMainMembers, ($i - 1), $memdat[3], 2) _GUICtrlListView_AddSubItem($ListViewMainMembers, ($i - 1), $memdat[4], 3) Next FileClose($f) EndFunc ;==>_ReadMemData Func _CalcAllyTotals() ;============================================ ; Calculate alliance totals ;============================================ Local $ic, $i, $tcval ;Delete any previous totals $totstr = "0" $totscore = "0" $ic = _GUICtrlListView_GetItemCount($ListViewMainMembers) ;Loop through and gather data from listview For $i = 1 To $ic $tcval = _GUICtrlListView_GetItemText($ListViewMainMembers, ($i - 1), 1) $tcval = StringReplace($tcval, ",", "") $sval = _GUICtrlListView_GetItemText($ListViewMainMembers, ($i - 1), 2) $sval = StringReplace($sval, ",", "") $totstr = $totstr + $tcval $totscore = $totscore + $sval Next ;Display data GUICtrlSetData($AllyStr, $totstr) GUICtrlSetData($AllyScore, Int(($totscore/1000))) EndFunc ;==>_CalcAllyTotals Func _CalcAllyRates() ;============================================ ; Calculate gains per day/week/month ;============================================ Local $f, $lc, $line, $memdat, $tcval, $sval, $scorepd, $strpd ;Delete any previous totals $prevtotstr = "0" $prevtotscore = "0" $f = FileOpen($ResDir & "" & $allypointer & $PrevMemDatatxt) $lc = _FileCountLines($ResDir & "" & $allypointer & $PrevMemDatatxt) ;Loop through and parse data from file For $i = 1 To $lc $line = FileReadLine($f, $i) If $line = "~" Then ExitLoop EndIf $memdat = StringSplit($line, "|") $tcval = $memdat[2] $tcval = StringReplace($tcval, ",", "") $sval = $memdat[3] $sval = StringReplace($sval, ",", "") $prevtotstr = $prevtotstr + $tcval $prevtotscore = $prevtotscore + $sval Next ;Convert data $scorepd = (($totscore - $prevtotscore) / _DateDiff("D", $LastUpdate, _NowCalcDate())) $strpd = (($totstr - $prevtotstr) / _DateDiff("D", $LastUpdate, _NowCalcDate())) ;Display data GUICtrlSetData($LabMainScoreAllyGainD, Int($scorepd/1000) & "/Day") GUICtrlSetData($LabMainScoreAllyGainW, (Int($scorepd*7/1000)) & "/Week") GUICtrlSetData($LabMainScoreAllyGainM, (Int($scorepd*30/1000)) & "/Month") GUICtrlSetData($LabMainStrAllyGainD, Int($strpd) & "/Day") GUICtrlSetData($LabMainStrAllyGainW, (Int($strpd*7)) & "/Week") GUICtrlSetData($LabMainStrAllyGainM, (Int($strpd*30)) & "/Month") FileClose($f) EndFunc ;==>_CalcAllyRates Func _StartMessageBoard() Local $body, $f, $lc, $line, $i, $crisscross ;Navigate to messageboard page _IENavigate($oMainIE, $ResDir & $MsgBoardtxt) $body = _IETagNameGetCollection($oMainIE, "body", 0) ;Loop through saved boards.txt and collect entries $f = FileOpen($ResDir & $SavedBoardtxt) $lc = _FileCountLines($ResDir & $SavedBoardtxt) For $i = 1 to $lc ;Check if even or odd number for table color If Mod($i, 2) = 0 Then $crisscross = "b0b0b0" Else $crisscross = "d0d0d0" EndIf $line = FileReadLine($f, $i) $line = StringSplit($line, "|") ;Display entries _IEDocInsertHTML($body, ' [i]' & $line[1] & "[/i] [b]" & $line[2] & ":[/b] " & $line[3] & ' ', "afterbegin") Next FileClose($f) EndFunc Func _StartTabs() Local $f, $lc, $line, $i ;Open file and count how many alliances $f = FileOpen($ResDir & $Indextxt) $lc = _FileCountLines($ResDir & $Indextxt) ;For every allaince loop through and create a tab For $i = 1 to $lc $line = FileReadLine($f, $i) _GUICtrlTab_InsertItem($TabMain, ($i-1) , $line) Next FileClose($f) EndFunc ;===================================================================== ; Need to tidy this code in here! ;===================================================================== #region Native function from UDF Tabs Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTab, $hWndListView, $tInfo ;Declare which UDF controls to monitor $hWndTab = $TabMain If Not IsHWnd($TabMain) Then $hWndTab = GUICtrlGetHandle($TabMain) $hWndListView = $ListViewMainMembers If Not IsHWnd($ListViewMainMembers) Then $hWndTab = GUICtrlGetHandle($ListViewMainMembers) ;Native DLL stuff $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") ;Begin events check Switch $hWndFrom ;Events for tabmain Case $hWndTab Switch $iCode Case $NM_CLICK ;User clicks on tab control ;Check if a new tab has been selected $tabcur = _GUICtrlTab_GetCurSel($TabMain) If $tabcur <> $tabprev Then ;Tab has changed so load new tab data _TabChange() ;Set the previous tab to current tab $tabprev = $tabcur EndIf EndSwitch ;Events for listviewmain Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK ;A column is clicked $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) ;Sort items _GUICtrlListView_SimpleSort($ListViewMainMembers, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) Case $LVN_ITEMACTIVATE ;An item is double clicked ;Get member name and pass to editmember func $itemcur = _GUICtrlListView_GetSelectedIndices($ListViewMainMembers) $itemcur = _GUICtrlListView_GetItem($ListViewMainMembers, $itemcur) ;################################################## GUICtrlSendToDummy($Dummy,$itemcur[3]) ; # INSTEAD OF CALLING _EditMember function here in this callback we send ;################################################## a message to our dummy control, that will be processed in main loop EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc #endregion Func _TabChange() Local $f $f = FileOpen($ResDir & $Indextxt) ;Get alliance tab change points to $allypointer = FileReadLine($f, ($tabcur+1)) ;Update controls with new allaince data _ReadMemData() _CalcAllyTotals() _CalcAllyRates() ;Update allaince logo GUICtrlDelete($AllyPic) $AllyPic = GUICtrlCreatePic($ResDir & "" & $allypointer & $AllyLogojpg, 16, 15, 400, 100) FileClose($f) EndFunc Func _EditMember($mem) Local $f, $lc, $i, $line ;Create Edit Member Window $WinEditMem = GUICreate($mem, 595, 227, 384, 145, Default, Default, $WinMain) $LabEditMemName = GUICtrlCreateLabel($mem, 112, 32, 32, 17) $LabEditMemScore = GUICtrlCreateLabel("Score:", 16, 80, 35, 17) $LabEditMemTc = GUICtrlCreateLabel("Troop Count:", 16, 112, 66, 17) $LabEditMemCoord = GUICtrlCreateLabel("Coords", 16, 144, 37, 17) $InputEditMemScore = GUICtrlCreateInput("-", 88, 80, 201, 21) $InputEditMemTc = GUICtrlCreateInput("-", 88, 112, 201, 21) $InputEditMemCoord = GUICtrlCreateInput("-", 88, 144, 201, 21) $EditEditMemNote = GUICtrlCreateEdit("Notes...", 296, 8, 289, 161) $ButtonEditMemSave = GUICtrlCreateButton("Save", 200, 184, 83, 25) $ButtonEditMemCancel = GUICtrlCreateButton("Cancel", 296, 184, 83, 25) GUISetState(@SW_SHOW, $WinEditMem) ;Get member data and display $f = FileOpen($ResDir & "" & $allypointer & $MemDatatxt) $lc = _FileCountLines($ResDir & "" & $allypointer & $MemDatatxt) ;Cycle through memdat.txt For $i = 1 to $lc $line = FileReadLine($f, $i) $line = StringSplit($line, "|") If $line[1] = $mem Then ;If the name of the member = name passed to function ;Update controls with member data GUICtrlSetData($InputEditMemTc, $line[2]) GUICtrlSetData($InputEditMemScore, $line[3]) GUICtrlSetData($InputEditMemCoord, $line[4]) ;GUICtrlSetData($InputEditMemCoord, NOTES placeholder) ExitLoop EndIf Next MsgBox(0, "", "1") ;Window events While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE MsgBox(0, "", "3") ExitLoop Case $ButtonEditMemCancel MsgBox(0, "", "4") ExitLoop EndSwitch WEnd ;Delete window on way out of function MsgBox(0, "", "7") FileClose($f) GUIDelete($WinEditMem) EndFunc Edited August 22, 2012 by Andreik Shinies 1 Link to comment Share on other sites More sharing options...
Shinies Posted August 22, 2012 Author Share Posted August 22, 2012 Beautiful, i understand where i went wrong now i will have to read up on the use of Dummy controls they were unknown to me before. Thank you for your help Bishop 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