viewpoint-particle

Author Topic: Closing a window after a time  (Read 575 times)

siocnarf

  • Newbie
  • *
  • Posts: 23
Closing a window after a time
« on: March 03, 2017, 10:47:27 am »
Hi,

I am creating a Window with Winbatch studio. In this Window, I have 2 buttons and those will trigger different actions. Is it possible to add a countdown timer and making the Window closing by itself?

Code: [Select]
MyDialogFormat=`WWWDLGED,6.2`

MyDialogCaption=`Collaboration de l'utilisateur requise`
MyDialogX=999
MyDialogY=999
MyDialogWidth=238
MyDialogHeight=232
MyDialogNumControls=006
MyDialogProcedure=`DEFAULT`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,226|226|226`
MyDialogConfig=0

MyDialog001=`003,213,126,012,PUSHBUTTON,"PushButton_OK",DEFAULT,"Fermer les programmes pour moi",1,1,@csDefButton,"Microsoft Sans Serif|8192|40|34",DEFAULT,DEFAULT`
MyDialog002=`163,213,060,012,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Poursuivre",0,2,DEFAULT,"Microsoft Sans Serif|8192|40|34",DEFAULT,DEFAULT`
MyDialog003=`003,003,228,012,STATICTEXT,"StaticText_2",DEFAULT,"La collaboration de l'utilisateur est requise.",DEFAULT,40,@csCenter,"Microsoft Sans Serif|9728|40|34","255|255|255","0|128|255"`
MyDialog004=`003,031,230,026,VARYTEXT,"VaryText_1",vtVariable1,"Vary 1",DEFAULT,30,@csCenter|@csDisabled,"Microsoft Sans Serif|8192|70|34","0|0|0","253|253|253"`
MyDialog005=`001,075,232,050,VARYTEXT,"VaryText_2",vtVariable2,"Vary 2",DEFAULT,50,@csCenter|@csDisabled,"Microsoft Sans Serif|8192|70|34","0|0|0","253|253|253"`
MyDialog006=`075,143,072,056,ITEMBOX,"ItemBox_1",ibVariable1,DEFAULT,DEFAULT,60,@csDisabled,"Microsoft Sans Serif|6656|40|34",DEFAULT,"255|255|255"`

ButtonPushed=Dialog("MyDialog")

Thanks,


morenos1

  • Jr. Member
  • **
  • Posts: 53
Re: Closing a window after a time
« Reply #1 on: March 03, 2017, 12:40:15 pm »
This sample accomplish that ....

#DefineSubRoutine DialogUDF(Handle,DialogMessage,DialogControlID,param4,param5)

   TimerTick  = 1
   Switch (DialogMessage)
      Case 0
         pbar = ""
         fPbar = 1
         MaxTimeOut = 180  ;3 mintues
         DialogProcOptions(Handle,2,1)
         DialogProcOptions(Handle,TimerTick, 1000)   ; enable 1 second timer events
         Break;

      Case TimerTick
         MaxTimeOut = MaxTimeOut - 1
         if fPbar == 1 then
            pbar = StrCat(pbar, "Ý")
            fPbar = 2
         else
            fPbar = 1
            pbar = StrReplace(pbar, "Ý", "Û")
         end if
         DialogControlSet(Handle,9,4,PBAR)       ;update vary text with new percentage bar
         if MaxTimeOut == 0 then  return 2      ;leave the routine
         Return(-1)
         break

      Case 2
         if DialogControlID == 4 then
            ;reset the timeout bar
            pbar = ""
            fPbar = 1
            MaxTimeOut = 180  ;3 mintues

            tUserID        = StrTrim(DialogControlGet(Handle, 1,3))   
            tPW_USERPSWD1  = StrTrim(DialogControlGet(Handle, 2,3))   
            tPW_USERPSWD2  = StrTrim(DialogControlGet(Handle, 3,3))   

            if StrLen(tUserID) == 0 then
               Message("Invalid Login ID","Please Enter A Valid Login ID")
               return -2
            else
               if StrLen(tPW_USERPSWD1) == 0 then
                  Message("Invalid Password","Please Enter A Valid Password")         
                  return -2
               end if

               if tPW_USERPSWD1 <> tPW_USERPSWD2 then
                  Message("Invalid Password","Password Does Not Match Confirmation Password")         
                  return -2
               end if
            end if
         end if
         return -1
         break
   EndSwitch
   Return -2
#EndSubRoutine
;-------------------------------------------------------------------------
#DefineFunction GetNamePassWord(Site)

   UserID = ""
   PW_USERPSWD1 = ""

   Dialog1Format=`WWWDLGED,6.1`

   t1 = StrCat("Please Enter Your UserName And PassWord For Site: ",Site)
   Dialog1Caption=t1
;   Dialog1Caption=`Please Enter Your UserName And PassWord`
   Dialog1X=-01
   Dialog1Y=-01
   Dialog1Width=206
   Dialog1Height=120
   Dialog1NumControls=010
   Dialog1Procedure=`DialogUDF`
   Dialog1Font=`DEFAULT`
   Dialog1TextColor=`DEFAULT`
   Dialog1Background=`DEFAULT,DEFAULT`

   Dialog1001=`091,011,074,012,EDITBOX,UserID,"Login ID",DEFAULT,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
   Dialog1002=`091,033,074,012,EDITBOX,PW_USERPSWD1,DEFAULT,DEFAULT,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
   Dialog1003=`091,047,074,012,EDITBOX,PW_USERPSWD2,DEFAULT,DEFAULT,3,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
   Dialog1004=`119,093,036,012,PUSHBUTTON,DEFAULT,"&OK",1,4,32,DEFAULT,DEFAULT,DEFAULT`
   Dialog1005=`059,093,036,012,PUSHBUTTON,DEFAULT,"&Cancel",2,5,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
   Dialog1006=`015,011,022,008,STATICTEXT,DEFAULT,"User ID",DEFAULT,6,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
   Dialog1007=`015,035,042,012,STATICTEXT,DEFAULT,"New Password",DEFAULT,7,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
   Dialog1008=`015,049,066,012,STATICTEXT,DEFAULT,"Reconfirm New Password",DEFAULT,8,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
   Dialog1009=`009,077,180,010,VARYTEXT,Timer,DEFAULT,DEFAULT,4,DEFAULT,"Terminal|4096|40|65329","0|0|128",DEFAULT`
   Dialog1010=`009,067,032,008,STATICTEXT,DEFAULT,"Waiting...",DEFAULT,10,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

   ButtonPushed=Dialog("Dialog1")
   if StrLen(UserID) == 0 || StrLen(PW_USERPSWD1) == 0 then
      return -1
   else
      msg = StrCat(UserID,@TAB,PW_USERPSWD1)
   end if

   return msg

#EndFunction
;-------------------------------------------------------------------------

ReturnMsg = GetNamePassword("DialUp Site 1")

exit

siocnarf

  • Newbie
  • *
  • Posts: 23
Re: Closing a window after a time
« Reply #2 on: March 04, 2017, 03:39:53 am »
HI,

Something is wrong in this code
3054: Unrecognizable item found on line
UserID=""

OK, finally found out to replace the tab with winbatch tab...

1. Not sure to understand how return -1 and return -2 are working.


Thanks

td

  • Tech Support
  • *****
  • Posts: 2185
    • WinBatch
Re: Closing a window after a time
« Reply #3 on: March 05, 2017, 09:02:18 am »
From the Consolidated WIL Help file under the user-defined-callback documentation ( Windows Interface Language Reference -> Things to Know -> Dialogs -> Dynamic Dialogs):

(i) The return value has special meaning: 

@retCancel (0) cancels dialog without updating control variables

@retDefault (-1) performs usual processing after return

@retNoExit (-2) will not terminate. (Note: control variables will not get updated until the Dialog exits.) Use DialogControlGet and DialogControlSet, to get and set values.

n (positive integer) performs usual processing and exits the dialog and the number n is the return value of the Dialog statement as it exits.

"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates