987learner Posted May 20, 2010 Share Posted May 20, 2010 Trying very hard to find what's wrong with my code but I gave up. Can anyone help to see where is the error? Both GUI Button when clicked is not working at all #Include <Misc.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Opt("WinTitleMatchMode", 2) Opt("TrayIconDebug", 1) _Singleton(@ScriptName, 0) $Parent1= GUICreate("Shutdown", 190, 100,@DesktopWidth/2,@DesktopHeight/2,-1,$WS_EX_TOPMOST) GUICtrlCreateLabel("Auto forced Shutdown in ",10, 10) GUICtrlCreateLabel("sec",155, 10) $Now=GUICtrlCreateButton("Now",20,40,50,25) $Abort=GUICtrlCreateButton("Abort",100,40,50,25) GUISetState(@SW_SHOW) For $i=5 to 0 Step -1 While 1 $msg = GUIGetMsg() GUICtrlCreateLabel($i,135, 10) Select Case $msg =$Now msgbox (0,"Now","Now pressed") Case $msg =$Abort msgbox (0,"Abort","Abort pressed") exit Case $msg =$GUI_EVENT_CLOSE exit EndSelect sleep (1000) Exitloop WEnd Next Link to comment Share on other sites More sharing options...
GEOSoft Posted May 20, 2010 Share Posted May 20, 2010 I don't know how you managed to get so much wrong in such a small script but I guess anything is possible if you try hard enough. Obviously it wasn't going to let the buttons do anything because you kept it in a 1 second sleep during which the script doesn't even get time to react to a message and it can't react during a sleep() Also NEVER create a GUI control in a loop like that. What you were actually doing was creating 5 separate labels on top of each other. Declare the label as part of the GUI code and use GUICtrlSetData(). This should get you started expandcollapse popup#Include <Misc.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Opt("WinTitleMatchMode", 2) Opt("TrayIconDebug", 1) _Singleton(@ScriptName, 0) $Parent1= GUICreate("Shutdown", 190, 100,@DesktopWidth/2,@DesktopHeight/2);,-1,$WS_EX_TOPMOST) GUICtrlCreateLabel("Auto forced Shutdown in ",10, 10) GUICtrlCreateLabel("sec",155, 10) $lbl_data = GUICtrlCreateLabel("",135, 10, 20,20) $Now=GUICtrlCreateButton("Now",20,40,50,25) $Abort=GUICtrlCreateButton("Abort",100,40,50,25) GUISetState(@SW_SHOW) $iTime = TimerInit() ;For $i=5 to 0 Step -1 While 1 $msg = GUIGetMsg() ;GUICtrlCreateLabel($i,135, 10) $iCurrent = 5 - Round(TimerDiff($iTime)/1000, 0) If GUICtrlRead($lbl_data) <> $iCurrent Then GUICtrlSetData($lbl_data, $iCurrent) If $iCurrent = 0 Then ExitLoop Select Case $msg =$Now msgbox (0,"Now","Now pressed") Case $msg =$Abort msgbox (0,"Abort","Abort pressed") exit Case $msg =$GUI_EVENT_CLOSE exit EndSelect ;sleep (1000) ;Exitloop WEnd ;Next George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Tvern Posted May 20, 2010 Share Posted May 20, 2010 I see GeoSoft already answered your post, but I made a commented script already, so I thought I'd post it. Have a look: #Include <Misc.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Opt("WinTitleMatchMode", 2) Opt("TrayIconDebug", 1) _Singleton(@ScriptName, 0) Local $oldsecleft $Parent1 = GUICreate("Shutdown", 190, 100,@DesktopWidth/2,@DesktopHeight/2,-1,$WS_EX_TOPMOST) $timeLabel = GUICtrlCreateLabel("Auto forced Shutdown in 5 sec",10, 10) $Now=GUICtrlCreateButton("Now",20,40,50,25) $Abort=GUICtrlCreateButton("Abort",100,40,50,25) GUISetState(@SW_SHOW) $timer = TimerInit() ;start a timer While 1 $msg = GUIGetMsg() $secleft = 5 - Round(TimerDiff($timer)/1000,0) ;calculate the time left If $secleft <= 0 Then Exit ;exit if time left <= 0 ElseIf $secleft <> $oldsecleft Then ;only udate if the value of $secleft changed to avoid flicker GUICtrlSetData($timeLabel,"Auto forced Shutdown in " & $secleft & " sec") ;update the control, rather than creating a new one $oldsecleft = $secleft ;set the control variable to check next loop EndIf Switch $msg ;switch is a little more appropriate here, but select was fine too Case $Now msgbox (0,"Now","Now pressed") Case $Abort msgbox (0,"Abort","Abort pressed") exit Case $GUI_EVENT_CLOSE exit EndSwitch WEnd Link to comment Share on other sites More sharing options...
GEOSoft Posted May 20, 2010 Share Posted May 20, 2010 Great minds and all that. You only missed one thing but you made up for it with the pretty colors and comments. The label displaying the seconds remaining needs the height set or it chops a bit off the bottom of the number. At least on mine it does. Actually all of those labels would have been better with the dimensions specified. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
987learner Posted May 20, 2010 Author Share Posted May 20, 2010 Thnaks for the help,comment and pointers. I'm new to GUI coding... 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