Casey Posted June 27, 2012 Share Posted June 27, 2012 Hello All,We have a small script designed to log what we are up. The script as it was originally written used tray items to make specific type entries whenever the person wanted to make a log entry. It also used an AdlibRegister function to trigger a reminder message box every 15 minutes.All was good until I decided to replace the reminder message box with a gui that could allow the user to select the type rather than closing it and selecting a tray item. I learned quickly that the tray items wouldn't do anything when they were selected after the gui was closed.So I am attempting a rewrite to make this possible. The code below has quite a bit incomplete and some stuff I need to trim out or change. However, I am coming to you with my current issue. Instead of waiting the 15 minute intervals the AdlibRegister function is set to, I temporarily set the "about" tray item to call the function that I am testing.Logically speaking:_gui1 is called when opening the scriptWhen _gui2 is called either from the about tray item or the AdlibRegister function the combo is populatedWhen the user selects an item from the combo, GUIOnEventMode 1 is used to detect the selectionWhen the detection is made, the _ItemSelect function is calledThe selection type value is retrievedThe gui is deletedAn input box appears to make the log entryThen I destroy the tray items because I can't figure out how to get them to do anything if I don'tI then call tray items to be created againThe loop: _gui1 -> _gui2 -> _ItemSelect -> _gui1In the end, I should have created a means of switching reading messages between the tray and the gui. This has resulted in almost exactly that. However, after _gui2 appears the second time, the GUICtrlSetOnEvent doesn't work anymore. Any suggestions as to why this is would be greatly appreciated.V/rCaseyexpandcollapse popup#NoTrayIcon #include <GUIConstantsEx.au3> #include <GuiComboBox.au3> #include <Constants.au3> #include <GuiComboBoxEx.au3> If Not FileExists(@MyDocumentsDir & "\ActivityLogs\") Then DirCreate(@MyDocumentsDir & "\ActivityLogs") EndIf AdlibRegister("_CheckTime", 500) Opt("GUIOnEventMode", 1) Global $hGUI2 = 9999, $Sel, $Item, $entryData2 _gui1() ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func _gui1() Global $entryitem, $phoneitem, $ngbitem, $genericitem, $openlogitem, $aboutitem, $exititem Opt("TrayMenuMode", 3) ; Default tray menu items (Script Paused/Exit) will not be shown. $entryitem = TrayCreateItem("New task...") $phoneitem = TrayCreateItem("New phone call...") $ngbitem = TrayCreateItem("New NGB item...") $genericitem = TrayCreateItem("New generic entry..") TrayCreateItem("") $openlogitem = TrayCreateItem("Open task log") TrayCreateItem("") $aboutitem = TrayCreateItem("About") $exititem = TrayCreateItem("Exit") TraySetState() _LogOpenClose("LAUNCH") While 1 $msg = TrayGetMsg() Select Case $msg = $aboutitem ;MsgBox(64, "About", "ABOUT ENOUGH TO DRIVE ME CRAZY.") _gui2() Case $msg = $entryitem _WriteLog("TASK") Case $msg = $phoneitem _WriteLog("PHONE") Case $msg = $ngbitem _WriteLog("NGB") Case $msg = $genericitem _WriteLog("MISC") Case $msg = $openlogitem _OpenLog() Case $msg = $exititem ExitLoop EndSelect WEnd EndFunc ;==>_gui1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func _gui2() Opt("GUIOnEventMode", 1) ; Change to OnEvent mode $hGUI2 = GUICreate("Update Your Progress", 260, 70) ; will create a dialog box that when displayed is centered GUICtrlCreateLabel("Update your calendar for " & @HOUR & ":" & @MIN, 10, 10, 200) $Item = GUICtrlCreateCombo("TASK", 10, 30) ; create first item ;MsgBox(0,"$Item",$Item) GUICtrlSetData($Item, "PHONE|NGB|MISC", "TASK") ; add other item snd set a new default _GUICtrlComboBoxEx_ShowDropDown($Item, True) $ItemCheck = GUICtrlSetOnEvent($Item, "_ItemSelect") ;MsgBox(0,"$ItemCheck",$ItemCheck) GUISetState() While 1 Sleep(100) WEnd EndFunc ;==>_gui2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func _ItemSelect() MsgBox(0, "", "_ItemSelect() Entered") $Sel = _GUICtrlComboBox_GetCurSel($Item) GUIDelete($hGUI2) ;Note: at this point @GUI_CTRLID would equal $Item position in the array Select Case $Sel = "0" $boxTitle = "Add a task to log." $boxPrompt = "Enter a task to be added to the task log:" $boxDefault = "@" & @HOUR & ":" & @MIN & " - " $type = "TASK" ;Give a name to the array position Case $Sel = "1" $boxTitle = "Add a phone call to log." $boxPrompt = "Enter a phone call to be added to the task log:" & @CRLF & @CRLF & "@Time - Caller, #, Subject" $boxDefault = "@" & @HOUR & ":" & @MIN & " - " $type = "PHONE" Case $Sel = "2" $boxTitle = "Add an NGB related item to log." $boxPrompt = "Enter an NGB-related item to be added to the task log:" & @CRLF & @CRLF & "@Time - Who, What" $boxDefault = "@" & @HOUR & ":" & @MIN & " - " $type = "NGB" Case Else $boxTitle = "Generic Entry" $boxPrompt = "Enter text to add to the log." $boxDefault = "@" & @HOUR & ":" & @MIN & " - " $type = "MISC" EndSelect Sleep(500) $entryData2 = InputBox($boxTitle, $boxPrompt, $boxDefault) If Not $entryData2 = "" Then $logFile = FileOpen(@MyDocumentsDir & "\ActivityLogs\" & @YEAR & @MON & @MDAY & ".log", 1) FileWriteLine($logFile, $type & " - " & $entryData2) FileClose($logFile) EndIf TrayItemDelete($entryitem) TrayItemDelete($phoneitem) TrayItemDelete($ngbitem) TrayItemDelete($genericitem) TrayItemDelete($openlogitem) TrayItemDelete($aboutitem) TrayItemDelete($exititem) TraySetState(2) _gui1() EndFunc ;==>_ItemSelect ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func _CheckTime() $iMin = @MIN If @SEC = 0 Then Switch $iMin Case "00" _Notify("00") Sleep(1000) Case "15" _Notify("15") Sleep(1000) Case "30" _Notify("30") Sleep(1000) Case "45" _Notify("45") Sleep(1000) Case Else Sleep(1000) EndSwitch EndIf EndFunc ;==>_CheckTime ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func _Notify($varMin) _gui2() ;_LogWindows() EndFunc ;==>_Notify ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func _LogWindows() $logFile = FileOpen(@MyDocumentsDir & "\ActivityLogs\" & @YEAR & @MON & @MDAY & ".log", 1) $var = WinList() FileWriteLine($logFile, "=========================================" & @CRLF & "LOG STARTING: " & @YEAR & @MON & @MDAY & " " & @HOUR & ":" & @MIN) FileWriteLine($logFile, "OPEN WINDOWS: ") For $i = 1 To $var[0][0] ; Only display visble windows that have a title If $var[$i][0] <> "" And _IsVisible($var[$i][1]) Then ;MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" & $var[$i][1]) $strActive = _IsForeground($var[$i][1]) FileWriteLine($logFile, $strActive & $var[$i][0]) EndIf Next FileWriteLine($logFile, @CRLF) FileWriteLine($logFile, "TASKS:") FileClose($logFile) EndFunc ;==>_LogWindows ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func _LogOpenClose($action) $logFile = FileOpen(@MyDocumentsDir & "\ActivityLogs\" & @YEAR & @MON & @MDAY & ".log", 1) Switch $action Case "LAUNCH" $status = "PROGRAM LAUNCH" Case "EXIT" $status = "PROGRAM EXIT" EndSwitch FileWriteLine($logFile, "=========================================" & @CRLF & $status & ": " & @YEAR & @MON & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF & "=========================================") FileClose($logFile) EndFunc ;==>_LogOpenClose ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func _IsVisible($handle) If BitAND(WinGetState($handle), 2) Then Return 1 Else Return 0 EndIf EndFunc ;==>_IsVisible ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func _IsForeground($handle) If BitAND(WinGetState($handle), 8) Then Return "***** " Else Return "" EndIf EndFunc ;==>_IsForeground ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func _WriteLog($type) Select Case $type = "NGB" $boxTitle = "Add an NGB related item to log." $boxPrompt = "Enter an NGB-related item to be added to the task log:" & @CRLF & @CRLF & "@Time - Who, What" $boxDefault = "@" & @HOUR & ":" & @MIN & " - " Case $type = "PHONE" $boxTitle = "Add a phone call to log." $boxPrompt = "Enter a phone call to be added to the task log:" & @CRLF & @CRLF & "@Time - Caller, #, Subject" $boxDefault = "@" & @HOUR & ":" & @MIN & " - " Case $type = "TASK" $boxTitle = "Add a task to log." $boxPrompt = "Enter a task to be added to the task log:" $boxDefault = "@" & @HOUR & ":" & @MIN & " - " Case Else $boxTitle = "Generic Entry" $boxPrompt = "Enter text to add to the log." $boxDefault = "@" & @HOUR & ":" & @MIN & " - " EndSelect ;$entryData = InputBox($boxTitle, $boxPrompt, $boxDefault) $entryData = InputBox($boxTitle, $boxPrompt, $boxDefault & Send("{RIGHT}") & Send("{BS 2}")) If Not $entryData = "" Then $logFile = FileOpen(@MyDocumentsDir & "\ActivityLogs\" & @YEAR & @MON & @MDAY & ".log", 1) FileWriteLine($logFile, $type & " - " & $entryData) FileClose($logFile) EndIf EndFunc ;==>_WriteLog ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func _OpenLog() ShellExecute(@MyDocumentsDir & "\ActivityLogs\" & @YEAR & @MON & @MDAY & ".log") EndFunc ;==>_OpenLog ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func MessageBox($iIndex) MsgBox("", "MsgBox " & $iIndex, "Test from Gui " & $iIndex) EndFunc ;==>MessageBox Link to comment Share on other sites More sharing options...
BrewManNH Posted June 27, 2012 Share Posted June 27, 2012 You should probably try to stick to one method or the other when it comes to detecting controls being activated. Use either OnEvent mode or MessageLoop mode, don't mix them like you are because it's causing all kinds of issues in that script. The TrayMenu has an OnEvent mode, you should probably use that if you want to go the full OnEvent mode route. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted June 27, 2012 Share Posted June 27, 2012 (edited) The problem here is much simpler, you never leave the loop in _gui2 so AutoIt just sits there waiting for it to end forever so it can start on the next event. The loop doesn't do anything useful anyway so just remove it. Edited June 27, 2012 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...
BrewManNH Posted June 27, 2012 Share Posted June 27, 2012 heh, I didn't even notice the While loop in gui2(). Too fixated on what the script was trying to do without seeing the forest through the trees. Now that I notice, it's also recursing back to the gui1 function when an item in the combo is selected, rather than just returning. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Casey Posted June 27, 2012 Author Share Posted June 27, 2012 BrewManNH, That is a thought and if I follow that path I will have to change some other things to make it work. I thought that I had read that it was possible to do both and except for that odd behavior, it seems possible. Thanks for the advice. I will start altering it an see how that works. AdmiralAlkex Removing the loop doesn't change the behavior. Also, I am assuming that when the gui is deleted that even if it were in the loop, that would go away. Or am I mistaken? Either way, there is something else happening at the point that the on event should fire that causes it not to the second time _gui2 is called. Thanks again both of you. V/r Casey 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