WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Dialog Editor version 6.X
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

File Browser within Dialog

 Keywords: Dialog AskFileName AskDirectory Browse FileListBox File ListBox 

Question:

I am creating a dialog that needs to allow the user to pick a file from their hard drive to copy. I have no clue where on their PC that the file might reside. Something on the order of a 'browse' function similiar to what you can do with file explorer. Is this possible?????

Answer:

A simple call to AskFileName can handle this.

However if you would like to prompt the user for both a source file and a target directory, in a single dialog, you can create a custom WIL Dialog with a Dialog Callback Procedure:



#DefineFunction FileSelDlgCallbackProc(FileSelDlg_Handle,FileSelDlg_Message,FileSelDlg_Name,FileSelDlg_EventInfo,FileSelDlg_ChangeInfo)
   ;DialogprocOptions Constants
   MSG_INIT=0                    ; The one-time initialization
   MSG_EDITBOX=5                 ; Editbox or Multilinebox
   MSG_BUTTONPUSHED=2            ; Pushbutton or Picturebutton

   ;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

   ;DialogControlSet / DialogControlGet Constants
   DC_EDITBOX=3              ; EDITBOX MULTILINEBOX
   DC_TITLE=4                ; PICTURE RADIOBUTTON CHECKBOX PICTUREBUTTON VARYTEXT STATICTEXT GROUPBOX PUSHBUTTON MENUITEM


   ON_EQUAL = @TRUE                                         ; Initialize variable ON_EQUAL
   Switch FileSelDlg_Message                                ; Switch based on Dialog Message type
      Case MSG_INIT                                         ; Standard Initialization message
         DialogProcOptions(FileSelDlg_Handle,MSG_BUTTONPUSHED,@TRUE)
;         DialogProcOptions(FileSelDlg_Handle,MSG_EDITBOX,@TRUE)
         Return(RET_DO_NOT_EXIT)

     Case MSG_BUTTONPUSHED
        If FileSelDlg_Name == "PushButton_Copy"            ; Copy
              cbSrcFile = DialogControlGet( FileSelDlg_Handle, "EditBox_SrcFile", DC_EDITBOX )
              cbTrgDir =  DialogControlGet( FileSelDlg_Handle, "EditBox_TrgDir", DC_EDITBOX )

              ;Validate User Input
              If cbSrcFile == "" || cbTrgDir == ""
                 Pause("Notice","You must enter BOTH a valid source filename AND a target directory.")
                 Return(RET_DO_NOT_EXIT)
              EndIf
              If !FileExist( cbSrcFile )
                 Pause("Notice","You must enter valid source filename.")
                 Return(RET_DO_NOT_EXIT)
              EndIf
              If !DirExist( cbTrgDir )
                 Pause("Notice","You must enter valid target directory.")
                 Return(RET_DO_NOT_EXIT)
              EndIf
              ;Prompt user to confirm Copy
              response = AskYesNo( "Copy?", "Would you like to copy ": cbSrcFile : " to " : cbTrgDir )
              If response
                FileCopy( cbSrcFile, cbTrgDir, @TRUE )
                Pause("File Copy","Success")
                DialogControlSet( FileSelDlg_Handle, "EditBox_SrcFile", DC_EDITBOX, "" )
                DialogControlSet( FileSelDlg_Handle, "EditBox_TrgDir", DC_EDITBOX, "" )
              EndIf


              :CANCEL ; Capture cancel from AskYesNo
              Return(RET_DO_NOT_EXIT)

        ElseIf FileSelDlg_Name == "PushButton_Cancel"      ; Cancel
              Return(RET_DO_DEFAULT)

        ElseIf FileSelDlg_Name == "PushButton_BrowseSrc"   ; Browse Source
              filename = AskFilename("Choose your file","","All Files|*.*","*.*",1)
              DialogControlSet(FileSelDlg_Handle,"EditBox_SrcFile",DC_EDITBOX,filename)
              :CANCEL ; Capture cancel from AskFileName
              Return(RET_DO_NOT_EXIT)

        ElseIf FileSelDlg_Name == "PushButton_BrowseTrg"   ; Browse Target
              directory = AskDirectory("Choose your Target Directory", "", "", "Are You Sure?", 4 )
              DialogControlSet(FileSelDlg_Handle,"EditBox_TrgDir",DC_EDITBOX,directory)
              :CANCEL ; Capture cancel from AskDirectory
              Return(RET_DO_NOT_EXIT)

        EndIf                                              ; FileSelDlg_Name
        Return(RET_DO_DEFAULT)

;     case MSG_EDITBOX
;        if FileSelDlg_Name == "EditBox_SrcFile"            ; SrcFile
;              return(RET_DO_DEFAULT)

;        elseif FileSelDlg_Name == "EditBox_TrgFile"        ; TrgFile
;              return(RET_DO_DEFAULT)

;        endif                                              ; FileSelDlg_Name
;        return(RET_DO_DEFAULT)

   EndSwitch                                                ; FileSelDlg_Message
   Return(RET_DO_DEFAULT)
#EndFunction                                                ; End of Dialog Callback FileSelDlgCallbackProc

;============================================================
;============================================================
;============================================================





FileSelDlgFormat=`WWWDLGED,6.2`

FileSelDlgCaption=`File Selection`
FileSelDlgX=-01
FileSelDlgY=-01
FileSelDlgWidth=440
FileSelDlgHeight=115
FileSelDlgNumControls=008
FileSelDlgProcedure=`FileSelDlgCallbackProc`
FileSelDlgFont=`DEFAULT`
FileSelDlgTextColor=`DEFAULT`
FileSelDlgBackground=`DEFAULT,128|128|128`
FileSelDlgConfig=0

FileSelDlg001=`151,077,034,014,PUSHBUTTON,"PushButton_Copy",DEFAULT,"Copy",1,DEFAULT,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
FileSelDlg002=`205,077,034,014,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,DEFAULT,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
FileSelDlg003=`345,023,034,014,PUSHBUTTON,"PushButton_BrowseSrc",DEFAULT,"Browse",2,DEFAULT,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
FileSelDlg004=`083,023,260,014,EDITBOX,"EditBox_SrcFile",SrcFile,DEFAULT,DEFAULT,1,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
FileSelDlg005=`021,025,040,008,STATICTEXT,"StaticText_SrcFile",DEFAULT,"Source File:",DEFAULT,7,DEFAULT,"Microsoft Sans Serif|5325|70|34","0|0|0",DEFAULT`
FileSelDlg006=`083,043,260,014,EDITBOX,"EditBox_TrgDir",TrgDir,DEFAULT,DEFAULT,2,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
FileSelDlg007=`345,043,034,014,PUSHBUTTON,"PushButton_BrowseTrg",DEFAULT,"Browse",3,4,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
FileSelDlg008=`021,045,060,008,STATICTEXT,"StaticText_TrgDir",DEFAULT,"Target Directory:",DEFAULT,8,DEFAULT,"Microsoft Sans Serif|5325|70|34","0|0|0",DEFAULT`

ButtonPushed=Dialog("FileSelDlg")




Exit


Older 6.1 format example that simply allows the user to select a source file.

#DefineFunction ConfigProc(ConfigDlgHandle,ConfigDlgMessage,ConfigDlgControlID,param4,param5)
   InitDialog=0 
   DC_ButtonPressed= 2 ; some constant we define laters
   DC_SetTitle = 3
   Switch ConfigDlgMessage

          Case InitDialog   ; Init_Dialog  (case number 0 subject to change on implementation)
               DialogProcOptions(ConfigDlgHandle,DC_ButtonPressed,1)   ; enable buttonclicked messages
               Return (-1)
   
          Case DC_ButtonPressed
              Switch ConfigDlgControlID
                  Case 3   ; the browse button
                     x=AskFilename("Choose your file","","All Files|*.*","*.*",1)
                     DialogControlSet(ConfigDlgHandle,4,DC_SetTitle,x)
                     :CANCEL ; Capture cancel from AskFileName
                     Return(-2)  ; don't exit
               EndSwitch   ;ConfigDlgControlID
               Return(-1)  ; do default processing

   EndSwitch ; ConfigDlgMessage
   Return(-1) ; Do default processing#EndFunction
#EndFunction


ConfigDlgFormat=`WWWDLGED,6.1`

ConfigDlgCaption=`Configuration Options`
ConfigDlgX=-01
ConfigDlgY=-01
ConfigDlgWidth=257
ConfigDlgHeight=072
ConfigDlgNumControls=005
ConfigDlgProcedure=`ConfigProc`
ConfigDlgFont=`DEFAULT`
ConfigDlgTextColor=`DEFAULT`
ConfigDlgBackground=`DEFAULT,128|255|128`

ConfigDlg001=`068,044,035,014,PUSHBUTTON,DEFAULT,"OK",1,DEFAULT,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
ConfigDlg002=`119,044,035,014,PUSHBUTTON,DEFAULT,"Cancel",0,DEFAULT,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
ConfigDlg003=`209,020,035,014,PUSHBUTTON,DEFAULT,"Browse",2,DEFAULT,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
ConfigDlg004=`007,020,192,014,EDITBOX,DaFile,"",DEFAULT,DEFAULT,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
ConfigDlg005=`009,006,187,009,STATICTEXT,DEFAULT,"Filename:",DEFAULT,DEFAULT,DEFAULT,"Microsoft Sans Serif|5325|70|34","0|0|0",DEFAULT`

ButtonPushed=Dialog("ConfigDlg")

Message("Selected File",DaFile)
Exit


Article ID:   W15467
File Created: 2012:12:03:14:46:04
Last Updated: 2012:12:03:14:46:04