Skip to main content

Problem:

This example illustrates how to use dsdir.obj/.gnt in your COBOL Dialog System application. Buttons defined within the File menu are used to collect and return

Resolution:

INTRODUCTION

============

This example illustrates how to use dsdir.obj/.gnt in your COBOL Dialog System application. Buttons defined within the File menu are used to collect and return information to the

main program.

SOURCE FILES:

==========

Program Files     Description

----------------     -----------------------------------------------------------

NewSet.cbl        Example program using File menu buttons. Open and Save to collect filenames

                          for file processing.

OPERATION:

==========

When I started Dialog System to create a new screenset, I added Open and Save buttons to the File menu. The Save button is disabled. The Open button is enabled. The Open button's choice name is OPENFILENAME. The Save button's choice name is SAVEFILENAME.

I then added the data definitions for dsdir and an additional data item named APP-STARTUP-DIR.

EXIT-FLAG                             9    1.0             CONFIG-FLAG                      C5     4.0           CONFIG-VALUE                    C5   4.0             APP-STARTUP-DIR               X    256.0           DSDIR-PARAMS                           1                DSDIR-FUNCTION                X      4.0             DSDIR-RETURN-CODE        C      2.0             DSDIR-FILENAME                 X    256.0           DSDIR-PARAMS2                         1                DSDIR-TITLE                        X    256.0           

APP-STARTUP-DIR is initialized by the main program to the

current directory before the dialog gains control.

Below is the dialog for OPENFILENAME:

  @OPENFILENAME

     MOVE "Get Filename to Open" DSDIR-TITLE(1)

     MOVE "open" DSDIR-FUNCTION(1)

     MOVE APP-STARTUP-DIR DSDIR-FILENAME(1)

     CLEAR-CALLOUT-PARAMETERS $NULL

     CALLOUT-PARAMETER 1 DSDIR-PARAMS $NULL

     CALLOUT-PARAMETER 2 DSDIR-PARAMS2 $NULL

     CALLOUT "dsdir" 0 $PARMLIST

     DISABLE-MENU-CHOICE $WINDOW OPENFILENAME

     ENABLE-MENU-CHOICE $WINDOW SAVEFILENAME

     RETC

Note that APP-STARTUP-DIR is used to initialize DSDIR-FILENAME. The dsdir routine handles both

GetOpenFileName and GetSaveFileName Win32 API functions. When DSDIR-FILENAME has a value it is used by dsdir to set the initial directory for the API functions.

Note also that the OPENFILENAME dialog ends with disabling the Open button and enabling the Save button.

Below is the dialog for OPENFILENAME:

   @SAVEFILENAME

     MOVE "Get Filename to Save" DSDIR-TITLE(1)

     MOVE "save" DSDIR-FUNCTION(1)

     CLEAR-CALLOUT-PARAMETERS $NULL

     CALLOUT-PARAMETER 1 DSDIR-PARAMS $NULL

     CALLOUT-PARAMETER 2 DSDIR-PARAMS2 $NULL

     CALLOUT "dsdir" 0 $PARMLIST

     DISABLE-MENU-CHOICE $WINDOW SAVEFILENAME

     ENABLE-MENU-CHOICE $WINDOW OPENFILENAME

     RETC

Note that SAVEFILENAME ends with disabling the Save button and enabling the Open button.

When you look at the NewSet.cbl program you will see this code in the Program-Initialize section:

     call 'CBL_GET_CURRENT_DIR' using by value     0 size 4

                                                               by value     length of APP-STARTUP-DIR size 4

                                                               by reference APP-STARTUP-DIR

                                                    returning status-code

     end-call

     perform with test after varying dirLength from 256 by -1

                  until APP-STARTUP-DIR(dirLength:1) <> SPACE

     end-perform

     add 1 to dirLength

     move z'\\*.*' to APP-STARTUP-DIR(dirLength:)

This code initializes APP-STARTUP-DIR with the current directory followed by wild cards and a null character. This ensures that the Win32 API functions dsdir uses will open into the current directory.

In the Program-Body section I added this code to perform a routine that would track the user's activity with the Open and Save buttons.

     if NOT EXIT-FLAG-TRUE

          perform dialogFilter

     end-if

When the dialog-filter section determines that both an input file name and an output file name have been provided, it performs the file processing section which copies a file to the new name.

References:

===========

Dailog System Help:

Dialog Statements Events (book)

     Menu Events (article)

Dialog System Extensions (book)

     Dsdir (book)

     Dsdir (article)

     Using Dsdir (article)

     Dsdir Functions (book)

     Dsdir Functions (article)

     Open (article)

     Save (article)

     Chek (article)

     Dsdir Example (article)

==========================================================

Keywords: demonstration, sample, example, demo, Dialog System, usingDSDir.zip

demo.ex

demo.ne

Attachments:

UsingDSDir.zip

Old KB# 4239