Dialog Box Button Push Programatically (or sendkeys)

Started by johanjo, September 02, 2013, 05:43:22 AM

Previous topic - Next topic

johanjo

Hi,

Please help!!!

Does anyone here who knows how to push button or sendKeys programmatically in a dialog box under a certain number of seconds? Maybe by using a Timer? Do you have sample code for this? Putting some delay in the MSG_INIT just doesn't work because the popup screen will not show up until the delay ends.

Basically I have this dialog box, for a number of seconds it will click the OK button.

Please view the image of my small pop up screen

JTaylor

Use the dialog timer event instead of the initialization event.

Jim

Deana

Deana F.
Technical Support
Wilson WindowWare Inc.

johanjo

Hi

I have tried this, as far as the timer is concern it works but  problem is it doesn't go the routine where the normal OK button flow will go and what's worst is it closes my message screen. How it is working now (manually) is when the user clicks OK, the scraper processes open IE but the screen stays there until the process ends.

#DefineFunction MyDialogCallbackProc(MyDialog_Handle, MyDialog_Message ,MyDialog_Name, MyDialog_EventInfo, rsvd)
Switch MyDialog_Message
      Case MSG_INIT
      Case MSG_TIMER
      Case MSG_BUTTONPUSHED
          If MyDialog_Name == "PushButton_OK"
               .................  <it doesnt go here> ............
          EndIf
      EndSwitch
#EndFunction



Please advice if theres something I missed. I can give u sample working script if you want. Just help with this... thanks

Deana

Here is a code sample that uses the timer event:

Code (winbatch) Select
#DefineFunction MyDialogProc(D_Handle,D_Message,D_ControlID,Reserved_0,Reserved_1)
  MSG_INIT=0
  MSG_TIMER=1
   
   switch D_Message

      case MSG_INIT
         timeoutinsec = 10
         DialogProcOptions(D_Handle,MSG_TIMER,timeoutinsec*1000)
         break

      case MSG_TIMER
          return(101) ;Specify value of button to return if timeout occured.

   endswitch
   return(-1)
#EndFunction



MyDialogFormat=`WWWDLGED,6.1`

MyDialogCaption=`Auto Timeout`
MyDialogX=002
MyDialogY=030
MyDialogWidth=144
MyDialogHeight=133
MyDialogNumControls=004
MyDialogProcedure=`MyDialogProc`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`
MyDialogConfig=0

MyDialog001=`045,101,032,010,PUSHBUTTON,DEFAULT,"Cancel",0,40,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog002=`043,047,036,012,PUSHBUTTON,DEFAULT,"Button 2",102,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog003=`043,067,036,012,PUSHBUTTON,DEFAULT,"Button 3",103,30,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
MyDialog004=`043,025,036,012,PUSHBUTTON,DEFAULT,"Button 1",101,10,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("MyDialog")

Pause('ButtonPushed', ButtonPushed)
Deana F.
Technical Support
Wilson WindowWare Inc.

johanjo

Hi Miss Deane,

It seems not working on my case? How am I going to pass the dialog_handle aside from within the MyDialogCallbackProc()? Its not even passing through the inside of the procedure call MyDialogCallbackProc().PushButton_OK. I just want to get the dialog_handle, if I can achieve that in the way you suggested above it would be fine.

Heres my actual code. Please execute and test it, I just want to get the MyDialog_Handle so I can manipulate the form itself interms of display and behavior.

Please help me and give some of ur suggested work arounds (at least I can be able pass handle MyDialog_Handle from outside MyDialogCallbackProc() )

Code (winbatch) Select

#DefineSubRoutine InitDialogConstants()
   ;DialogprocOptions Constants
   MSG_INIT=0                ; The one-time initialization
   MSG_TIMER=1               ; Timer event
   MSG_BUTTONPUSHED=2        ; Pushbutton or Picturebutton
   MSG_RADIOPUSHED=3         ; Radiobutton clicked  
   MSG_CHECKBOX=4            ; Checkbox clicked
   MSG_EDITBOX=5             ; Editbox or Multilinebox
   MSG_FILESELECT=6          ; Filelistbox
   MSG_ITEMSELECT=7          ; Itembox
   MSG_COMBOCHANGE=8         ; Combobox/Droplistbox
   MSG_CALENDAR=9            ; Calendar date change
   MSG_SPINNER=10            ; Spinner number change
   MSG_CLOSEVIA49=11         ; Close clicked (Enabled via Intcontrol 49)
   MSG_FILEBOXDOUBLECLICK=12 ; Get double-click message on a FileListBox
   MSG_ITEMBOXDOUBLECLICK=13 ; Get double-click message on an ItemBox
   DPO_DISABLESTATE=1000     ; codes -1=GetSetting 0=EnableDialog 1=DisableDialog
   DPO_CHANGEBACKGROUND=1001 ; -1=Get Current otherise bitmap or color string
   DPO_CHANGESYSMENU=1002    ; -1=Get Current 0=none 1=close 2=close/min 3=close/max 4=close/min/max
   DPO_CHANGETITLE=1003      ; -1=Get Current otherise new title

   ;DialogControlState Constants
   DCSTATE_SETFOCUS=1        ; Give Control Focus
   DCSTATE_QUERYSTYLE=2      ; Query control's style
   DCSTATE_ADDSTYLE=3        ; Add control style
   DCSTATE_REMOVESTYLE=4     ; Remove control style
   DCSTATE_GETFOCUS=5        ; Get control that has focus
   DCSTYLE_INVISIBLE=1       ; Set Control Invisible
   DCSTYLE_DISABLED=2        ; Set Control Disabled
   DCSTYLE_NOUSERDATA=4      ; Note: Setable via DialogControlState function ONLY SPINNER control only
   DCSTYLE_READONLY=8        ; Sets control to read-only (user cannot type in data) EDITBOX MULTILINEBOX SPINNER
   DCSTYLE_PASSWORD=16       ; Sets 'password mode' where only *'s are displayed EDITBOX
   DCSTYLE_DEFAULTBUTTON=32  ; Sets a button as the default button PUSHBUTTON PICTUREBUTTON
   DCSTYLE_DIGITSONLY=64     ; Set edit box to accept digits only EDITMOX MULTILINEBOX
   DCSTYLE_FLAT=128          ; Makes a 'flat' hyperlink-looking button PUSHBUTTON PICTUREBUTTON
   DCSTYLE_NOADJUST=256      ; Turns off auto-height adjustment  ITEMBOX FILELISTBOX
   DCSTYLE_TEXTCENTER=512    ; Center text in control VARYTEXT STATICTEXT
   DCSTYLE_TEXTRIGHT=1024    ; Flush-Right text in control VARYTEXT STATICTEXT
   DCSTYLE_NOSELCURLEFT=2048 ; No selection, cursor left EDITBOX MULTILINEBOX
   DCSTYLE_NOSELCURRIGHT=4096; No selection, cursor right EDITBOX MULTILINEBOX

   ;DialogControlSet / DialogControlGet Constants
   DC_CHECKBOX=1             ; CHECKBOX
   DC_RADIOBUTTON=2          ; RADIOBUTTON
   DC_EDITBOX=3              ; EDITBOX MULTILINEBOX
   DC_TITLE=4                ; PICTURE RADIOBUTTON CHECKBOX PICTUREBUTTON VARYTEXT STATICTEXT GROUPBOX PUSHBUTTON
   DC_ITEMBOXCONTENTS=5      ; ITEMBOX FILELISTBOX DROPLISTBOX
   DC_ITEMBOXSELECT=6        ; ITEMBOX FILELISTBOX DROPLISTBOX
   DC_CALENDAR=7             ; CALENDAR
   DC_SPINNER=8              ; SPINNER
   DC_MULTITABSTOPS=9        ; MULTILINEBOX
   DC_ITEMSCROLLPOS=10       ; ITEMBOX FILELISTBOX
   DC_BACKGROUNDCOLOR=11     ; RADIOBUTTON CHECKBOX VARYTEXT STATICTEXT GROUPBOX PUSHBUTTON ITEMBOX FILELISTBOX DROPLISTBOX SPINNER EDITBOX MULTILINEBOX
   DC_PICTUREBITMAP=12       ; PICTURE PICTUREBUTTON
   DC_TEXTCOLOR=13           ; RADIOBUTTON CHECKBOX VARYTEXT STATICTEXT GROUPBOX PUSHBUTTON ITEMBOX FIELLISTBOX DROPLISTBOX SPINNER EDITBOX MULTILINEBOX
   DC_ITEMBOXADD=14          ; ITEMBOX FILELISTBOX DROPLISTBOX
   DC_ITEMBOXREMOVE=15       ; ITEMBOX FILELISTBOX DROPLISTBOX

   ;Return code constants
   RET_DO_CANCEL=0           ; Cancels dialog
   RET_DO_DEFAULT= -1        ; Continue with default processing for control
   RET_DO_NOT_EXIT= -2       ; Do not exit the dialog
   Return
#EndSubRoutine


#DefineFunction MyDialogCallbackProc(MyDialog_Handle, MyDialog_Message ,MyDialog_Name, MyDialog_EventInfo, rsvd)
InitDialogConstants()                                       ; Initialize Dialog Constants


Switch MyDialog_Message                                  ; Switch based on Dialog Message type

      Case MSG_INIT

DialogProcOptions(MyDialog_Handle, MSG_TIMER, 1000)
DialogControlSet(MyDialog_Handle,"StaticText_6",DC_TITLE, "Scrapper will start in 3 second(s).")

Return RET_DO_DEFAULT

case MSG_TIMER
Clock = DialogControlGet(MyDialog_Handle,"VaryText_1",DC_TITLE)
Clock = Clock-1
     
If Clock == 0 Then Return(101) ; exit,

str = StrCat("Scrapper will start in ",Clock," second(s).")
DialogControlSet(MyDialog_Handle,"StaticText_6",DC_TITLE, str)
DialogControlSet(MyDialog_Handle,"VaryText_1",DC_TITLE, Clock)
Return RET_DO_DEFAULT

Case MSG_BUTTONPUSHED
If MyDialog_Name == "PushButton_OK"

Pause('ButtonPushed', "Yes! Button OK is clicked... StartProcess() is called process here.")

; StartProcess(MyDialog_Handle, userdata)

DialogControlSet(MyDialog_Handle,"StaticText_6",DC_TITLE, "")
DialogControlState(MyDialog_Handle, MyDialog_Name, DCSTATE_ADDSTYLE, DCSTYLE_DISABLED) ;disable OK button
 
        Return(RET_DO_DEFAULT)

ElseIf MyDialog_Name == "PushButton_1"
Run('notepad.exe', StrCat(DirScript(), 'users.txt'))
Return(RET_DO_NOT_EXIT)
ElseIf MyDialog_Name == "PushButton_Cancel"
Return(RET_DO_DEFAULT)
EndIf
EndSwitch
#EndFunction

MyDialogFormat=`WWWDLGED,6.2`

MyDialogCaption=`MyTimeOutForm`
MyDialogX=164
MyDialogY=178
MyDialogWidth=274
MyDialogHeight=101
MyDialogNumControls=009
MyDialogProcedure=`MyDialogCallbackProc`
MyDialogFont=`DEFAULT`
MyDialogTextColor=`DEFAULT`
MyDialogBackground=`DEFAULT,DEFAULT`
MyDialogConfig=0

MyDialog001=`157,041,046,014,PUSHBUTTON,"PushButton_OK",DEFAULT,"OK",101,1,32,"Verdana|5632|40|34","0|0|0",DEFAULT`
MyDialog002=`207,041,046,014,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,2,DEFAULT,"Verdana|5632|40|34","0|0|0",DEFAULT`
MyDialog003=`057,019,098,014,EDITBOX,"EditBox_1",ebVariable1,DEFAULT,DEFAULT,1,2056,"Verdana|5632|40|34","0|0|0",DEFAULT`
MyDialog004=`009,019,044,012,STATICTEXT,"StaticText_1",DEFAULT,"Default User:",DEFAULT,50,1024,"Verdana|5632|40|34","0|0|0",DEFAULT`
MyDialog005=`003,007,256,054,GROUPBOX,"GroupBox_1",DEFAULT,"User Settings",DEFAULT,120,DEFAULT,"Verdana|5632|40|34","0|0|0",DEFAULT`
MyDialog006=`015,041,138,014,STATICTEXT,"StaticText_6",DEFAULT,DEFAULT,DEFAULT,110,512,"Verdana|5632|40|34","255|0|0",DEFAULT`
MyDialog007=`207,019,046,014,PUSHBUTTON,"PushButton_1",DEFAULT,"Update Users",2,100,0,"Verdana|5632|40|34",DEFAULT,DEFAULT`
MyDialog008=`159,021,044,012,CHECKBOX,"CheckBox_1",cbVariable1,"Fresh Start",1,90,0,"Verdana|5632|40|34","0|0|255",DEFAULT`
MyDialog009=`019,077,248,012,VARYTEXT,"VaryText_1",clock,"3",DEFAULT,80,512,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("MyDialog")

Pause('ButtonPushed', ButtonPushed)


Deana

Sounds like you want to execute the same chunk of code whether the button was pushed OR the timer has timed out. Your timer procedure should probable look something like this:

Code (winbatch) Select
        case MSG_TIMER
                        Clock = DialogControlGet(MyDialog_Handle,"VaryText_1",DC_TITLE)
                        Clock = Clock-1
             
                        If Clock == 0
                             Pause('Timer timed out', "StartProcess() is called process here.")
                             DialogProcOptions(MyDialog_Handle, MSG_TIMER, 0);disable timer
;                            StartProcess(MyDialog_Handle, userdata)
                             DialogControlSet(MyDialog_Handle,"StaticText_6",DC_TITLE, "")
                             DialogControlState(MyDialog_Handle, MyDialog_Name, DCSTATE_ADDSTYLE, DCSTYLE_DISABLED) ;disable OK button
                             Return(RET_DO_DEFAULT)
                        Endif

                        str = StrCat("Scrapper will start in ",Clock," second(s).")
                        DialogControlSet(MyDialog_Handle,"StaticText_6",DC_TITLE, str)
                        DialogControlSet(MyDialog_Handle,"VaryText_1",DC_TITLE, Clock)
                        Return RET_DO_DEFAULT
Deana F.
Technical Support
Wilson WindowWare Inc.

johanjo

wow. It works for me now. Thank you so much.

I really appreciated it. :)