Consultor Eletrônico



Kbase 18284: How to open a file or URL with its associated program
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   09/03/2002
INTRODUCTION:
=============

This kbase shows sample 4GL statements to open a file or URL using
its associated program.

Two methods are presented in the kbase:
- Using ShellExecuteA - MS-Windows API call
- Using OS-COMMAND - Progress 4GL statement

The ShellExecuteA is available on MS-Windows 95, 98, and MS-Windows NT and is intented for 32bit versions of Progress.

The Progress 4GL statement OS-COMMAND uses the START command available on MS-Windows 95 and MS-Windows NT.

The ShellExecuteA works provides better performance than the approach with OS-COMMAND, since that latter uses the OS shell START command and ShellExecuteA is a direct MS-Windows API.

WHY YOU NEED TO KNOW THIS:
===========================

With this logic, you can open from a Progress Application a readme
file, a word document, an HTML document or launch a web browser to
access a URL address.
For example to implement a button that goes to your website in the
about screen of your application.


PROCEDURAL APPROACH:
====================

Examples:
- RUN ShellExecuteA(0, "open", "http://www.progress.com/", "", "", 0,
OUTPUT hInstance).

- OS-COMMAND SILENT "START /MIN c:\winnt\printer.wri".

- OS-COMMAND SILENT "START /SEPARATE /Dc:\temp test.doc".

- OS-COMMAND SILENT "START http://techweb.progress.com/".

- OS-COMMAND SILENT "START notepad".


Example program with ShellExecuteA usage and definition


DEFINE VARIABLE hInstance AS INTEGER.

DEF BUTTON b-ok.
FORM b-ok WITH FRAME zz.

ON CHOOSE OF b-ok DO:
RUN ShellExecuteA(0, "open", "http://www.progress.com/", "", "", 0,
OUTPUT hInstance).
END.

UPDATE b-ok WITH FRAME zz.

PROCEDURE ShellExecuteA EXTERNAL "shell32.dll":
DEFINE INPUT PARAMETER hwnd AS LONG.
/* Handle to parent window */
DEFINE INPUT PARAMETER lpOperation AS CHAR.
/* Operation to perform: open, print */
DEFINE INPUT PARAMETER lpFile AS CHAR.
/* Document or executable name */
DEFINE INPUT PARAMETER lpParameters AS CHAR.
/* Command line parameters to executable in lpFile */
DEFINE INPUT PARAMETER lpDirectory AS CHAR.
/* Default directory */
DEFINE INPUT PARAMETER nShowCmd AS LONG.
/* whether shown when opened:
0 hidden, 1 normal, minimized 2, maximized 3,
0 if lpFile is a document */
DEFINE RETURN PARAMETER hInstance AS LONG.
/* Less than or equal to 32 */
END.


NOTES:
- You can use the START command at a Command Prompt window to test it,
before added it to the Progress program.

- The START command has additional options, do START /? | more to get
a usage information.

- The working directory of the program launched will be the working
directory of the Progress application. You can specify the /D option
to specify a different one.

- This kbase describes provides example for ShellExecuteA (32 bit DLL), for Progress 16 bits, the ShellExecute MS-Windows API call can be used for this same purpose.
Please refer to a Microsoft documentation for more information.

References to Written Documentation:

Progress Language Reference - OS-COMMAND statement.
Progress External Programming Interfaces

Progress Knowledge Base Solutions:
21422, "How To Use the Microsoft Web Browser ActiveX from the 4GL"
21881, "How To Open a Web Browser From Progress using ActiveX"