Kbase 20101: How to Modify _osprint.p to Run on an AppServer
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  3/25/2009 |
|
Status: Verified
GOAL:
How to Modify _osprint.p to Run on an AppServer
FACT(s) (Environment):
Progress 9.x
Windows
OpenEdge 10.x
OpenEdge Category: Language (4GL/ABL)
FIX:
As it is shipped now, _osprint.p cannot run on a Progress AppServer. It expects a user-interface layer to be present on the Progress session where it runs, but AppServer processes have no user-interface layer at all. _osprint.p can be changed as described below so that it will run on both an AppServer process and a regular Progress session.
Code changes are highlighted by "CHANGE BEGIN" and "CHANGE END". The code base for these changes is adecomm\_osprint.p as it is shipped in Progress Version 9.1A.
NOTE the following:
- When _osprint.p is run on the AppServer, font specifications are taken from the AppServer's registry/.INI file.
- No alert-box appears if an error occurs (for example, the file to be printed is not found); _osprint.p silently returns with p_Printed set to NO.
- The Windows Print Setup Dialog is not displayed. Any setting that pertains to orientation, paper size etc. must be passed in the p_PrintFlags parameter before running _osprint.p.
The following code has been tested by Progress Technical Support in most environments but not in every circumstance and environment. Progress recommends you test all software extensively prior to placing it in production. The suggested changes are not supported.
/************** _osprint.p modified source code **************/
/*************************************************************/
/* Copyright (c) 1984-1996 by Progress Software Corporation */
/* */
/* All rights reserved. No part of this program or document */
/* may be reproduced in any form or by any means without */
/* permission in writing from Progress Software Corporation. */
/*************************************************************/
/****************************************************************************
File _osprint.p
Syntax
RUN adecomm/_osprint.p ( INPUT p_Window,
INPUT p_PrintFile,
INPUT p_FontNumber,
INPUT p_PrintFlags,
INPUT p_PageSize,
INPUT p_PageCount,
OUTPUT p_Printed ).
Purpose Send a specified operating system text file to the default
printer.
Remarks Output is sent to printer as PAGED output, with a default
page size of zero. This lets the printer handle the paging.
The page size can be specified using p_PageSize.
Max characters per line: 255.
Under MS-Windows, the MSW Print Setup dialog box
is called via a PROGRESS DLL (PROPRINT.DLL) and the
SESSION:PRINTER-CONTROL-HANDLE is always cleared.
Author J. Palazzo
Created Mar 1994
Updated Sept 1996 Changed p_UseDialog parameter to p_PrintFlags.
****************************************************************************/
DEFINE INPUT PARAMETER p_Window AS WIDGET NO-UNDO.
/* Parent window for Dialogs and Message boxes. Default
to CURRENT-WINDOW if p_Window is not valid. */
DEFINE INPUT PARAMETER p_PrintFile AS CHAR NO-UNDO.
/* Text file to print. Can be specified relative to PROPATH. */
DEFINE INPUT PARAMETER p_FontNumber AS INTEGER NO-UNDO.
/* PROGRESS Font Number to use when printing file. MSW Only.
This may not match screen font exactly and the printer
driver will make the ultimate choice, not PROGRESS. */
DEFINE INPUT PARAMETER p_PrintFlags AS INTEGER NO-UNDO.
/* Integer express.ion that specifies various print options.
The table below lists the flag values that correspond to
each print option. If a zero (0) value is passed, option
defaults are used.
Print Option Flag Value Meaning
useDialog 1 Display the MSW Print Setup Dialog.
Default is to not display the Print
dialog.
useLandscape 2 Set print orientation to Landscape.
Default orientation is Portrait.
You can specify any combination of these flags. For
example, you can pass three (1 + 2) as an input parameter to
specify that the Print Setup Dialog be displayed and that
the print orientation be landscape. */
DEFINE INPUT PARAMETER p_PageSize AS INTEGER NO-UNDO.
/* Page length - number of lines per page. */
DEFINE INPUT PARAMETER p_PageCount AS INTEGER NO-UNDO.
/* If non-zero, then enable the page range selection controls
in the printer setup dialog. If zero, the entire text file
is printed. */
DEFINE OUTPUT PARAMETER p_Printed AS LOGICAL INIT TRUE NO-UNDO .
/* Returns TRUE if able to complete the OUTPUT TO PRINTER. */
DEFINE STREAM In_Stream.
DEFINE STREAM Out_Stream.
DEFINE VAR Text_Line AS CHARACTER FORMAT "x(255)" NO-UNDO .
DEFINE VAR PrintResult AS INTEGER INITIAL 0 NO-UNDO .
/****** CHANGE BEGIN
I need one more INTEGER variable. */
DEFINE VAR WindowHwnd AS INTEGER NO-UNDO.
/****** CHANGE END */
DO ON STOP UNDO, RETRY ON ERROR UNDO, RETRY:
IF NOT RETRY THEN
DO:
/* Point to a valid window handle. */
ASSIGN p_Window = IF VALID-HANDLE( p_Window ) THEN
p_Window
ELSE IF VALID-HANDLE( CURRENT-WINDOW ) THEN
CURRENT-WINDOW
ELSE
DEFAULT-WINDOW.
/* Get file info on file to print. */
ASSIGN FILE-INFO:FILE-NAME = p_PrintFile NO-ERROR .
IF ( FILE-INFO:FULL-PATHNAME = ? ) THEN
DO:
/****** CHANGE BEGIN
On the AppServer, we cannot MESSAGE to the screen. */
IF NOT SESSION:REMOTE THEN
/****** CHANGE END */
MESSAGE "Unable to find file to print."
VIEW-AS ALERT-BOX ERROR BUTTONS OK IN WINDOW p_Window.
STOP.
END.
ASSIGN p_PrintFile = FILE-INFO:FULL-PATHNAME.
/* Run Proprint DLL for Windows and 32bit Windows Char Console. */
IF (SESSION:WINDOW-SYSTEM BEGINS "MS-WIN") OR
(OPSYS = "WIN32" AND SESSION:WINDOW-SYSTEM = "TTY") THEN
DO:
/****** CHANGE BEGIN
If we are on the AppServer we can set WindowHwnd to 0,
but then we must disable the useDialog flag. */
IF SESSION:REMOTE THEN
ASSIGN WindowHwnd = 0
p_PrintFlags = TRUNCATE(p_PrintFlags / 2, 0) * 2.
ELSE
ASSIGN WindowHwnd = p_Window:HWND.
/****** CHANGE END */
/* Clear the current print handle. */
ASSIGN SESSION:PRINTER-CONTROL-HANDLE = ?.
RUN ProPrintFile ( INPUT SESSION:PRINTER-CONTROL-HANDLE,
INPUT p_PrintFlags ,
/****** CHANGE BEGIN
Was INPUT p_Window:HWND */
INPUT WindowHwnd,
/****** CHANGE END */
INPUT p_FontNumber,
INPUT p_PrintFile,
INPUT p_PageCount,
OUTPUT PrintResult ).
/* Return value from DLL of 0 indicates a successful reques.t to
print the file. It does NOT indicate the file has finished
printing.
*/
ASSIGN p_Printed = ( PrintResult = 0 ).
END.
ELSE
DO:
/* All other operating environments/windowing systems.
Break out into a CASE statement to customize. */
RUN PrintFile.
END.
END. /* NOT RETRY */
ELSE
ASSIGN p_Printed = FALSE.
INPUT STREAM In_Stream CLOSE.
OUTPUT STREAM Out_Stream CLOSE.
END.
/* -----------------------------------------------------------------------*/
PROCEDURE ProPrintFile EXTERNAL "PROPRINT.DLL":
/* Internal Procedure call to MS-Windows DLL to Print Setup dialog. */
DEFINE INPUT PARAMETER hControl AS LONG.
DEFINE INPUT PARAMETER fPrintFlags AS LONG.
DEFINE INPUT PARAMETER hWndParent AS LONG.
DEFINE INPUT PARAMETER nFontNo AS LONG.
DEFINE INPUT PARAMETER lpszFile AS CHARACTER.
DEFINE INPUT PARAMETER nPages AS LONG.
DEFINE RETURN PARAMETER Print_Result AS LONG.
END.
/* -----------------------------------------------------------------------*/
PROCEDURE PrintFile:
/* Print an operating system file via simple OUTPUT TO PRINTER. */
INPUT STREAM In_Stream FROM VALUE(p_PrintFile) NO-ECHO NO-MAP.
OUTPUT STREAM Out_Stream TO PRINTER PAGE-SIZE VALUE( p_PageSize ).
/* Frame must be down frame, so scope to REPEAT. */
REPEAT ON STOP UNDO, LEAVE WITH FRAME f_Print:
IMPORT STREAM In_Stream UNFORMATTED Text_Line.
DISPLAY STREAM Out_Stream Text_Line
WITH FRAME f_Print NO-LABELS STREAM-IO
NO-BOX USE-TEXT WIDTH 255.
END.
END PROCEDURE.
/* _osprint.p - end of file */
.