Navigation:  Programmer's Reference >

Using WinExec to plot an existing File

JR   Viewer

Print this Topic Previous pageReturn to chapter overviewNext page

 

The following code fragment (in FORTRAN) demonstrates a method for instructing DPlot to plot an existing file from within another Windows-based program.

 

     integer*4 hWndDPlot         ! Handle of DPlot window

     integer*4 hInstDPlot        ! Instance handle of DPlot module

     integer*4 wStatus           ! API return code

     integer*4 hKey              ! Registration database key

     integer*4 dwLength          ! String length

     character szFileName*80     ! Null-terminated string containing

                                 ! name of file to plot.

     character szDPlot*256       ! Full d:\path\filename.ext

                                 ! of DPLOT.EXE

     .

     .

     hWndDPlot=FindWindow('DPlot'c, NULL_POINTER)

     if (hWndDPlot.eq.0) then

c

c        DPlot is not currently running. Check user's

c        registration database for location.

c

        wStatus = RegOpenKey( HKEY_CURRENT_USER,

    1                         'Software\DPlot\shell\open\command'c,

    2                         hKey )

 

        if( wStatus .eq. ERROR_SUCCESS ) then

c

c           DPlot's location is in the

c           registration database... now retrieve it.

c

           dwLength=len(szDPlot)

           wStatus=RegQueryValue( hKey, NULL_POINTER,

    1                            szDPlot, dwLength )

           wStatus=RegCloseKey( hKey )

 

        else

 

           szDPlot = 'DPLOT.EXE'//char(0)

 

        endif

 

     else

 

c        DPlot IS running. Use API routines to get filespec.

 

        hInstDPlot=GetWindowWord(hWndDPlot,GWW_HINSTANCE)

        wStatus=GetModuleFileName(hInstDPlot,szDPlot,

    1                             len(szDPlot))

 

     endif

 

     dwLength=index(szDPlot,char(0))

     wStatus = WinExec(szDPlot(1:dwLength-1)//' '//

    1                  szFileName,SW_SHOWNORMAL)

     if( wStatus .lt. 32 )

    1   wStatus=MessageBox(hWnd,'Cannot find DPLOT.EXE'//char(0),

    2                      'MYAPPLICATION'//char(0),

    3                      MB_OK .or. MB_ICONEXCLAMATION )

 

Notes:

(1) Registration database. DPlot's installation program automatically changes the user's registration database to indicate the location of DPLOT.EXE. DPlot also checks the entry in the registration database against its location every time it runs, and modifies the database entry if necessary. (This might be necessary if the user has moved the program since installing it.)

(2) WinExec. DPLOT.EXE takes a substantial amount of time to load the first time on slower systems. However, if the user does not close DPlot, subsequent calls to WinExec are relatively fast.

 

 


Page url: https://www.dplot.com/help/index.htm?helpid_prog_winexec.htm