nitekram Posted February 20, 2015 Share Posted February 20, 2015 I read another thread that said that once you opened up the menu, all other code stopped. My problem is there seems to be a delay of me clicking and things actually working. I have an example, but basically my code goes out and checks other things, but I still want to be able to interrupt that code if need be. Here is one example: #include <TrayConstants.au3> Opt("TrayMenuMode", 3) Global $tUIPDisableItem = TrayCreateItem("DISABLE") TrayCreateItem("") Global $tExit = TrayCreateItem("EXIT") Local $TRAY While 1 For $x = 0 To 10000 ConsoleWrite($x & @CRLF) Next $TRAY = TrayGetMsg() Select ; delay - checking something else??? Case $TRAY = $tUIPDisableItem If BitAND(TrayItemGetState($tUIPDisableItem), $TRAY_CHECKED) <> $TRAY_CHECKED Then TrayItemSetState($tUIPDisableItem, $TRAY_CHECKED) Else TrayItemSetState($tUIPDisableItem, $TRAY_UNCHECKED) EndIf Case $TRAY = $tExit ; Exit the loop. Exit EndSelect WEnd If I open up the tray, I would think that this would stop the For Loop from starting again, after it has completed one run. I want to be able to check the box, to stop my script from checking other parts of my program, but have found that sometimes, I have to open the tray menu more than once to be able to make the check stick? How can I stop all other parts from continuing if I open the tray, so it is waiting for input from a user? Here is the >LINK that says it is supposed to stop execution until the menu is gone - or am I reading it wrong? 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator Link to comment Share on other sites More sharing options...
LarsJ Posted February 21, 2015 Share Posted February 21, 2015 Are you sure that it's not just the For-loop that teases you? Have you tried to delete the For-loop and place the ConsoleWrite command immediately after While.When the For-loop is running it's blocking the entire message loop, and making it unresponsive. Because the message loop is spending most of the time executing the For-loop, the message loop is blocked most of the time. You can not expect reliable results from a message loop, that is blocked most of the time. A message loop (in MessageLoop mode) should not be blocked. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
kylomas Posted February 22, 2015 Share Posted February 22, 2015 (edited) nitekram, As LarsJ says the for...to loop is interfering with the msg loop. There are two solutions for this. Put the msg loop in the for..to loop like this... #include <TrayConstants.au3> Opt("TrayMenuMode", 3) Global $tUIPDisableItem = TrayCreateItem("DISABLE") TrayCreateItem("") Global $tExit = TrayCreateItem("EXIT") Local $TRAY While 1 For $x = 0 To 10000 ConsoleWrite($x & @CRLF) $TRAY = TrayGetMsg() Select ; delay - checking something else??? Case $TRAY = $tUIPDisableItem If BitAND(TrayItemGetState($tUIPDisableItem), $TRAY_CHECKED) <> $TRAY_CHECKED Then TrayItemSetState($tUIPDisableItem, $TRAY_CHECKED) Else TrayItemSetState($tUIPDisableItem, $TRAY_UNCHECKED) EndIf Case $TRAY = $tExit ; Exit the loop. Exit EndSelect Next WEnd or change for...to loop to a non-blocking paradigm and put it in the msg loop like this... #include <TrayConstants.au3> Opt("TrayMenuMode", 3) Global $tUIPDisableItem = TrayCreateItem("DISABLE") TrayCreateItem("") Global $tExit = TrayCreateItem("EXIT") Local $TRAY, $x While 1 $TRAY = TrayGetMsg() Select ; delay - checking something else??? Case $TRAY = $tUIPDisableItem If BitAND(TrayItemGetState($tUIPDisableItem), $TRAY_CHECKED) <> $TRAY_CHECKED Then TrayItemSetState($tUIPDisableItem, $TRAY_CHECKED) Else TrayItemSetState($tUIPDisableItem, $TRAY_UNCHECKED) EndIf Case $TRAY = $tExit ; Exit the loop. Exit EndSelect if $x < 10000 then ConsoleWrite($x & @CRLF) $x += 1 endif WEnd which you use depends on what you are doing. I favor the second choice, where possible. kylomas Edited February 22, 2015 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
nitekram Posted February 26, 2015 Author Share Posted February 26, 2015 nitekram, As LarsJ says the for...to loop is interfering with the msg loop. There are two solutions for this. Put the msg loop in the for..to loop like this... #include <TrayConstants.au3> Opt("TrayMenuMode", 3) Global $tUIPDisableItem = TrayCreateItem("DISABLE") TrayCreateItem("") Global $tExit = TrayCreateItem("EXIT") Local $TRAY While 1 For $x = 0 To 10000 ConsoleWrite($x & @CRLF) $TRAY = TrayGetMsg() Select ; delay - checking something else??? Case $TRAY = $tUIPDisableItem If BitAND(TrayItemGetState($tUIPDisableItem), $TRAY_CHECKED) <> $TRAY_CHECKED Then TrayItemSetState($tUIPDisableItem, $TRAY_CHECKED) Else TrayItemSetState($tUIPDisableItem, $TRAY_UNCHECKED) EndIf Case $TRAY = $tExit ; Exit the loop. Exit EndSelect Next WEnd or change for...to loop to a non-blocking paradigm and put it in the msg loop like this... #include <TrayConstants.au3> Opt("TrayMenuMode", 3) Global $tUIPDisableItem = TrayCreateItem("DISABLE") TrayCreateItem("") Global $tExit = TrayCreateItem("EXIT") Local $TRAY, $x While 1 $TRAY = TrayGetMsg() Select ; delay - checking something else??? Case $TRAY = $tUIPDisableItem If BitAND(TrayItemGetState($tUIPDisableItem), $TRAY_CHECKED) <> $TRAY_CHECKED Then TrayItemSetState($tUIPDisableItem, $TRAY_CHECKED) Else TrayItemSetState($tUIPDisableItem, $TRAY_UNCHECKED) EndIf Case $TRAY = $tExit ; Exit the loop. Exit EndSelect if $x < 10000 then ConsoleWrite($x & @CRLF) $x += 1 endif WEnd which you use depends on what you are doing. I favor the second choice, where possible. kylomas Thanks for your help...I assumed my calling function was eating up to much time, but you proved that. Since, I have cut down the amount of times I call the function, which has allowed me to interrupt the While loop, and get it working. 2¢ All by me:"Sometimes you have to go back to where you started, to get to where you want to go." "Everybody catches up with everyone, eventually" "As you teach others, you are really teaching yourself." From my dad "Do not worry about yesterday, as the only thing that you can control is tomorrow." WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2 AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit Docs SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language Programming Tips Excel Changes ControlHover.UDF GDI_Plus Draw_On_Screen GDI Basics GDI_More_Basics GDI Rotate GDI Graph GDI CheckExistingItems GDI Trajectory Replace $ghGDIPDll with $__g_hGDIPDll DLL 101? Array via Object GDI Swimlane GDI Plus French 101 Site GDI Examples UEZ GDI Basic Clock GDI Detection Ternary operator 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