Realm Posted June 29, 2011 Share Posted June 29, 2011 (edited) Ok, I am officially stumped and very tired, but I assume I'm overlooking something very simple. In this small test script, 'TestFuncA' continously runs without a call until an actual control has been pressed/called. Can anyone see where I have gone wrong? expandcollapse popup#include <Array.au3> #include <GUIConstants.au3> Opt('WinTitleMatchMode', 2) Global $aWindow, $gui, $bDim, $bWindow, $bReset ;App Globals Global $globalConfig = @ScriptDir & '\Global.config' Global $cardloc, $appActive = 0, $bRunApp, $bTestA, $appH = 40, $appW = 0, $gDepth EmulateWindows() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $bReset EmulateWindows() Case $msg = $bRunApp If $appActive Then $appActive = 0 Else $appActive = 1 EndIf CreateNewGUI() Case $msg = $bTestA _WinWaitActivate(RegRead('HKEY_CURRENT_USER\Software\Window Organizer','Last Window')) TestFuncA() EndSelect For $x = 1 to UBound($aWindow)-1 If $msg = $bWindow[$x] Then _WinWaitActivate($aWindow[$x][1]) RegWrite('HKEY_CURRENT_USER\Software\Window Organizer','Last Window','REG_SZ',$aWindow[$x][1]) Next WEnd Func EmulateWindows() $aWindow = WinList('Notepad') For $i = 1 To UBound($aWindow)-1 If $aWindow[$i][0]='Notepad' Then _WinWaitActivate($aWindow[$i][1]) Local $sName = InputBox('Create Nickame','Create a Nickname for identifying windows') If not @error Then WinSetTitle($aWindow[$i][1], '',$sName & ' - Notepad') $aWindow[$i][0] = $sName & ' - Notepad' EndIf EndIf Next CreateNewGUI() EndFunc Func CreateNewGUI() If WinExists($gui) Then GUIDelete($gui) Local $depth = (UBound($aWindow)-1)*30, $addH = 0, $addW = 0 $bDim = UBound($aWindow) If IsArray($bWindow) Then ReDim $bWindow[$bDim] Else Dim $bWindow[$bDim] EndIf If $appActive Then $addH = $appH + 30 $addW = $appW EndIf $gui = GUICreate('Window Organizer',170+$addW,40+$depth+$addH,0,0) $bReset = GUICtrlCreateButton('Reconfigure', 10, 10, 70, 20) $bRunApp = GUICtrlCreateButton('Run App', 90, 10, 70, 20) If $appActive Then GUICtrlSetData(-1,'Close App') $gDepth = 40 For $i = 1 To $bDim-1 $bWindow[$i] = GUICtrlCreateButton(StringTrimRight($aWindow[$i][0],15), 10, $gDepth, 150, 20) $gDepth += 30 Next If $appActive Then GUICtrlCreateLabel('Testing Functions:',10, $gDepth) $gDepth +=30 $bTestA = GUICtrlCreateButton('Test Func A',10,$gDepth,100,20) EndIf GUISetState() EndFunc Func _WinWaitActivate($title,$text="",$timeout=0) WinWait($title,$text,$timeout) If Not WinActive($title,$text) Then WinActivate($title,$text) WinWaitActive($title,$text,$timeout) Return WinGetHandle($title,$text) Sleep(250) EndFunc Func TestFuncA() MsgBox(0,'Test','') EndFunc Edited June 29, 2011 by Realm My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 29, 2011 Share Posted June 29, 2011 When there is no event on the GUI, GuiGetMsg() returns 0. Since your $bTestA is not initialized with a value the "Case $msg = $bTestA" is continuously true. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Realm Posted June 29, 2011 Author Share Posted June 29, 2011 Ok, So I attempt to initialize a dummy value by declaring it 'empty' in the Global statement Global $cardloc, $appActive = 0, $bRunApp, $bTestA = 'empty', $appH = 40, $appW = 0, $gDepth However, I'm still receiving the same result. My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. Link to comment Share on other sites More sharing options...
Realm Posted June 29, 2011 Author Share Posted June 29, 2011 Thanks for pointing that out Psalty. I made a work around by creating a check for $appActive before checking to see if $bTestA was the current message and works great now! While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $bReset EmulateWindows() Case $msg = $bRunApp If $appActive Then $appActive = 0 Else $appActive = 1 EndIf CreateNewGUI() ;~ Case $msg = $bTestA ;~ _WinWaitActivate(RegRead('HKEY_CURRENT_USER\Software\Window Organizer','Last Window')) ;~ TestFuncA() EndSelect For $x = 1 to UBound($aWindow)-1 If $msg = $bWindow[$x] Then _WinWaitActivate($aWindow[$x][1]) RegWrite('HKEY_CURRENT_USER\Software\Window Organizer','Last Window','REG_SZ',$aWindow[$x][1]) Next If $appActive And $msg = $bTestA Then _WinWaitActivate(RegRead('HKEY_CURRENT_USER\Software\Window Organizer','Last Window')) TestFuncA() EndIf WEnd My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 29, 2011 Share Posted June 29, 2011 Ok, So I attempt to initialize a dummy value by declaring it 'empty' in the Global statement Global $cardloc, $appActive = 0, $bRunApp, $bTestA = 'empty', $appH = 40, $appW = 0, $gDepth However, I'm still receiving the same result. This doesn't work because you compare a integer type to a string, so the string is automatically passed to the equivalent of Number() before the compare. Since 'empty' is not a valid numeric string, is converts to 0 and you are right back where you started. It might have worked if you had used the case sensitive compare "Case $msg == $bTestA". Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Realm Posted June 30, 2011 Author Share Posted June 30, 2011 That all makes more sense now. I ended up having more problems with other similar issues last night, and decided to take another more fluid approach to my script last night. PsaltyDS, Thanks for your insightful help. Realm My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 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