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        DPlot is not currently running. Check user's

c        registration database for location.


        wStatus = RegOpenKey( HKEY_CURRENT_USER,

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

    2                         hKey )


        if( wStatus .eq. ERROR_SUCCESS ) then


c           DPlot's location is in the

c           registration database... now retrieve it.



           wStatus=RegQueryValue( hKey, NULL_POINTER,

    1                            szDPlot, dwLength )

           wStatus=RegCloseKey( hKey )




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






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




    1                             len(szDPlot))





     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 )



(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: