Alexxander Posted September 9, 2013 Share Posted September 9, 2013 (edited) Hi all i want to make a script : while notepad is running a button is visible and when Notepad is not running the button is not visible and when i press the button try.exe is opened #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> $GUI = GUICreate("MY GUI", -1,-1,-1,-1, $WS_POPUP , $WS_EX_TOPMOST) $but = GUICtrlCreateButton("", -1, -1, 100, 100) guisetstate() While 1 $nMsg = GUIGetMsg() WinSetOnTop($GUI, "", 1) $menu = WinExists("[CLASS:Notepad]") if $menu = 1 then GUICtrlSetState($but, $GUI_SHOW) if $menu = 0 then GUICtrlSetState($but, $GUI_HIDE) If $nMsg = $but Then ShellExecute("C:\auto\try.exe") WEnd it is working but the button is flashing when start menu is opened and it is not exciting the try.exe when the button is pressed any ideas ? PS: i'm using win 7 Edited September 9, 2013 by Alexxander Link to comment Share on other sites More sharing options...
FireFox Posted September 9, 2013 Share Posted September 9, 2013 Hi,The button is flickering because you change its state constantly, I would add a boolean to toggle the state only when needed.it is not exciting the try.exe when the button is pressed any ideas ?Where is the exit code?Br, FireFox. Link to comment Share on other sites More sharing options...
Alexxander Posted September 9, 2013 Author Share Posted September 9, 2013 Hi, The button is flickering because you change its state constantly, I would add a boolean to toggle the state only when needed. Where is the exit code? Br, FireFox. bro what does boolean means ? sorry i meant executing not exciting Link to comment Share on other sites More sharing options...
FireFox Posted September 9, 2013 Share Posted September 9, 2013 what does boolean means ?http://lmgtfy.com/?q=what+is+booleanIn other terms:Local $fMyBool = True ;or Local $fMyBool = Falsesorry i meant executing not excitingIt should work. Link to comment Share on other sites More sharing options...
Mat Posted September 9, 2013 Share Posted September 9, 2013 Generally you don't want to set a state in a tight loop. That's just asking for flashing and other graphical glitches. WinExists is not quite what you want either. When you close notepad it hides the window, and only deletes it later (there shouldn't be a huge delay, but I'm using a pretty old computer so it's noticeable). Anyway, I changed the code a bit and it works now. No idea what issue it was stopping your code from working, possibly NOTEPAD wasn't matching any windows, and was matching the start menu somehow. Can't reproduce here on xp. #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> $GUI = GUICreate("MY GUI", 100, 100, 500, 500, $WS_POPUP, $WS_EX_TOPMOST) $but = GUICtrlCreateButton("", -1, -1, 500, 500) GUISetState() Local $fShown = True, $h While 1 $nMsg = GUIGetMsg() $h = WinGetHandle("[CLASS:Notepad]") $menu = Not @error And BitAND(WinGetState($h), @SW_SHOW) If $menu <> $fShown Then GUICtrlSetState($but, $menu ? $GUI_SHOW : $GUI_HIDE) ConsoleWrite($menu & @LF) $fShown = $menu EndIf If $nMsg = $but Then ShellExecute("C:\auto\try.exe") WEnd Alexxander 1 AutoIt Project Listing Link to comment Share on other sites More sharing options...
Alexxander Posted September 9, 2013 Author Share Posted September 9, 2013 Mat thank you bro but i'm getting error at this line GUICtrlSetState($but, $menu ? $GUI_SHOW : $GUI_HIDE) maybe the "?" mark ? Link to comment Share on other sites More sharing options...
FireFox Posted September 9, 2013 Share Posted September 9, 2013 The ternary operator is implemented in the beta version.If $menu Then GUICtrlSetState($but, $GUI_SHOW) Else GUICtrlSetState($but, $GUI_HIDE) EndIf Br, FireFox. Link to comment Share on other sites More sharing options...
Mat Posted September 9, 2013 Share Posted September 9, 2013 My bad. I'm getting so used to using the new features that I forget they aren't present in the latest stable. The stable version still has a function called _Iif in Misc.au3 that is nearly an equivalent to the ternary operator (no difference in this case). AutoIt Project Listing Link to comment Share on other sites More sharing options...
Alexxander Posted September 9, 2013 Author Share Posted September 9, 2013 Guys may u take a look on my new thread ? '?do=embed' frameborder='0' data-embedContent>> Link to comment Share on other sites More sharing options...
TheSaint Posted September 9, 2013 Share Posted September 9, 2013 Personally I would use - If ProcessExists("Notepad.exe") Then But there could be reasons you may not want that method. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) 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