&ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12 GUI &ANALYZE-RESUME &Scoped-define WINDOW-NAME C-Win &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS C-Win /*------------------------------------------------------------------------ File: ftpDownload.w Description: This program utilizes the standard DoFileDownload API. On the occasions when you simply need to download one file, this routine will display the IE file download dialog. The nice thing is that the dialog takes care of all aspects of the interface, including the progressbar, animation and statistics. This code can eaisly be integrated into any application requiring this type of functionality. Input Parameters: Output Parameters: Author: Todd G. Nist tnist@bellsouth.net Created: 11/1/2000 ------------------------------------------------------------------------*/ /* This .W file was created with the Progress UIB. */ /*----------------------------------------------------------------------*/ /* Create an unnamed pool to store all the widgets created by this procedure. This is a good default which assures that this procedure's triggers and internal procedures will execute in this procedure's storage, and that proper cleanup will occur on deletion of the procedure. */ CREATE WIDGET-POOL. /* *************************** Definitions ************************** */ /* Parameters Definitions --- */ /* Local Variable Definitions --- */ Procedure DoFileDownload External 'shdocvw.dll':U: define input parameter lpszFile as long. end. /* WideChar (unicode) to MultiByte (Ansi) */ PROCEDURE WideCharToMultiByte EXTERNAL "KERNEL32.dll": define input parameter uCodePage as long. /* code page */ define input parameter dwFlags as long. /* performance and mapping flags */ define input parameter lpWideCharStr as long. /* address of wide-character string */ define input parameter cbWideChar as long. /* number of characters in string, if -1 is calculated on the fly */ define input parameter lpMultiByteStr as long. /* address of buffer for new string */ define input parameter cbMultiByte as long. /* size of buffer */ define input parameter lpDefaultChar as long. /* address of default for unmappable characters */ define input parameter lpUsedDefaultChar as long. /* address of flag set when default char is used */ define return parameter iRetCode as long. /* if successful, number of bytes written to the lpMultiByteStr buffer, else 0 */ END. /* MultiByte (Ansi) to WideChar (Unicode) */ PROCEDURE MultiByteToWideChar EXTERNAL "KERNEL32.dll": define input parameter uCodePage as long. /* code page */ define input parameter dwFlags as long. /* performance and mapping flags */ define input parameter lpMultiByteStr as long. /* address of wide-character string */ define input parameter cbMubtiByte as long. /* number of characters in string */ define input parameter lpWideCharStr as long. /* address of buffer for new string */ define input parameter cbMultiByte as long. /* size of buffer */ define return parameter iRetCode as long. /* if successful, number of bytes written to the lpMultiByteStr buffer, else 0 */ END. /* _UIB-CODE-BLOCK-END */ &ANALYZE-RESUME &ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK /* ******************** Preprocessor Definitions ******************** */ &Scoped-define PROCEDURE-TYPE Window /* Name of first Frame and/or Browse and/or first Query */ &Scoped-define FRAME-NAME DEFAULT-FRAME /* Standard List Definitions */ &Scoped-Define ENABLED-OBJECTS cDownloadUrl btnDownload &Scoped-Define DISPLAYED-OBJECTS cDownloadUrl /* Custom List Definitions */ /* List-1,List-2,List-3,List-4,List-5,List-6 */ /* _UIB-PREPROCESSOR-BLOCK-END */ &ANALYZE-RESUME /* *********************** Control Definitions ********************** */ /* Define the widget handle for the window */ DEFINE VAR C-Win AS WIDGET-HANDLE NO-UNDO. /* Definitions of the field level widgets */ DEFINE BUTTON btnDownload LABEL "Download" SIZE 15 BY 1.05. DEFINE VARIABLE cDownloadUrl AS CHARACTER FORMAT "X(256)":U INITIAL "http://www.global-shared.com/api/dl/apisite.chm" VIEW-AS FILL-IN SIZE 59 BY 1 NO-UNDO. /* ************************ Frame Definitions *********************** */ DEFINE FRAME DEFAULT-FRAME cDownloadUrl AT ROW 1.33 COL 2 NO-LABEL btnDownload AT ROW 1.33 COL 62.2 WITH 1 DOWN NO-BOX KEEP-TAB-ORDER OVERLAY SIDE-LABELS NO-UNDERLINE THREE-D AT COL 1 ROW 1 SIZE 77 BY 1.71. /* *********************** Procedure Settings ************************ */ &ANALYZE-SUSPEND _PROCEDURE-SETTINGS /* Settings for THIS-PROCEDURE Type: Window Allow: Basic,Browse,DB-Fields,Window,Query Other Settings: COMPILE */ &ANALYZE-RESUME _END-PROCEDURE-SETTINGS /* ************************* Create Window ************************** */ &ANALYZE-SUSPEND _CREATE-WINDOW IF SESSION:DISPLAY-TYPE = "GUI":U THEN CREATE WINDOW C-Win ASSIGN HIDDEN = YES TITLE = "FTP File Download" HEIGHT = 1.67 WIDTH = 77 MAX-HEIGHT = 16 MAX-WIDTH = 80 VIRTUAL-HEIGHT = 16 VIRTUAL-WIDTH = 80 RESIZE = yes SCROLL-BARS = no STATUS-AREA = no BGCOLOR = ? FGCOLOR = ? KEEP-FRAME-Z-ORDER = yes THREE-D = yes MESSAGE-AREA = no SENSITIVE = yes. ELSE {&WINDOW-NAME} = CURRENT-WINDOW. /* END WINDOW DEFINITION */ &ANALYZE-RESUME /* *************** Runtime Attributes and UIB Settings ************** */ &ANALYZE-SUSPEND _RUN-TIME-ATTRIBUTES /* SETTINGS FOR WINDOW C-Win VISIBLE,,RUN-PERSISTENT */ /* SETTINGS FOR FRAME DEFAULT-FRAME */ /* SETTINGS FOR FILL-IN cDownloadUrl IN FRAME DEFAULT-FRAME ALIGN-L */ IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(C-Win) THEN C-Win:HIDDEN = no. /* _RUN-TIME-ATTRIBUTES-END */ &ANALYZE-RESUME /* ************************ Control Triggers ************************ */ &Scoped-define SELF-NAME C-Win &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL C-Win C-Win ON END-ERROR OF C-Win /* FTP File Download */ OR ENDKEY OF {&WINDOW-NAME} ANYWHERE DO: /* This case occurs when the user presses the "Esc" key. In a persistently run window, just ignore this. If we did not, the application would exit. */ IF THIS-PROCEDURE:PERSISTENT THEN RETURN NO-APPLY. END. /* _UIB-CODE-BLOCK-END */ &ANALYZE-RESUME &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL C-Win C-Win ON WINDOW-CLOSE OF C-Win /* FTP File Download */ DO: /* This event will close the window and terminate the procedure. */ APPLY "CLOSE":U TO THIS-PROCEDURE. RETURN NO-APPLY. END. /* _UIB-CODE-BLOCK-END */ &ANALYZE-RESUME &Scoped-define SELF-NAME btnDownload &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL btnDownload C-Win ON CHOOSE OF btnDownload IN FRAME DEFAULT-FRAME /* Download */ DO: &SCOPE MAX_PATH 260 define var lpFileSpec as memptr no-undo. define var lpwFileSpec as memptr no-undo. define var iRetCode as int no-undo. define var cwStr as char no-undo. define var i as i no-undo. set-size(lpFileSpec) = length(cDownloadUrl:screen-value) + 1. put-string(lpFileSpec,1) = cDownloadUrl:screen-value. set-size(lpwFileSpec) = {&MAX_PATH}. /* convert from ansi to unicode */ run MultiByteToWideChar(input 0, /* use ANSI code page */ input 0, /* flags that specify the handling of unmapped characters */ input get-pointer-value(lpFileSpec), /* pointer to wide-character string (unicode) */ input get-size(lpFileSpec), /* count of bytes in string string */ input get-pointer-value(lpwFileSpec), /* address of buffer for new unicode string */ input get-size(lpwFileSpec), /* size of buffer */ output iRetCode). run DoFileDownload(input get-pointer-value(lpwFileSpec)). set-size(lpwFileSpec) = 0. set-size(lpFileSpec) = 0. END. /* _UIB-CODE-BLOCK-END */ &ANALYZE-RESUME &UNDEFINE SELF-NAME &ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK C-Win /* *************************** Main Block *************************** */ /* Set CURRENT-WINDOW: this will parent dialog-boxes and frames. */ ASSIGN CURRENT-WINDOW = {&WINDOW-NAME} THIS-PROCEDURE:CURRENT-WINDOW = {&WINDOW-NAME}. /* The CLOSE event can be used from inside or outside the procedure to */ /* terminate it. */ ON CLOSE OF THIS-PROCEDURE RUN disable_UI. /* Best default for GUI applications is... */ PAUSE 0 BEFORE-HIDE. /* Now enable the interface and wait for the exit condition. */ /* (NOTE: handle ERROR and END-KEY so cleanup code will always fire. */ MAIN-BLOCK: DO ON ERROR UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK ON END-KEY UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK: RUN enable_UI. IF NOT THIS-PROCEDURE:PERSISTENT THEN WAIT-FOR CLOSE OF THIS-PROCEDURE. END. /* _UIB-CODE-BLOCK-END */ &ANALYZE-RESUME /* ********************** Internal Procedures *********************** */ &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE disable_UI C-Win _DEFAULT-DISABLE PROCEDURE disable_UI : /*------------------------------------------------------------------------------ Purpose: DISABLE the User Interface Parameters: Notes: Here we clean-up the user-interface by deleting dynamic widgets we have created and/or hide frames. This procedure is usually called when we are ready to "clean-up" after running. ------------------------------------------------------------------------------*/ /* Delete the WINDOW we created */ IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(C-Win) THEN DELETE WIDGET C-Win. IF THIS-PROCEDURE:PERSISTENT THEN DELETE PROCEDURE THIS-PROCEDURE. END PROCEDURE. /* _UIB-CODE-BLOCK-END */ &ANALYZE-RESUME &ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE enable_UI C-Win _DEFAULT-ENABLE PROCEDURE enable_UI : /*------------------------------------------------------------------------------ Purpose: ENABLE the User Interface Parameters: Notes: Here we display/view/enable the widgets in the user-interface. In addition, OPEN all queries associated with each FRAME and BROWSE. These statements here are based on the "Other Settings" section of the widget Property Sheets. ------------------------------------------------------------------------------*/ DISPLAY cDownloadUrl WITH FRAME DEFAULT-FRAME IN WINDOW C-Win. ENABLE cDownloadUrl btnDownload WITH FRAME DEFAULT-FRAME IN WINDOW C-Win. {&OPEN-BROWSERS-IN-QUERY-DEFAULT-FRAME} VIEW C-Win. END PROCEDURE. /* _UIB-CODE-BLOCK-END */ &ANALYZE-RESUME