How to print 4GL reports, using Windows GDI ? 
Author Message
 How to print 4GL reports, using Windows GDI ?

Example for printing text to the default printer using Windows API:

Steps to follow for Progress 16 bytes (v8.0-v.8.1):
1) Finding the Windows directory;
2) Load file Win.ini and take the default printer parameters;
3) Creating an context device to the default printer;
4) Creating an default font;
5) Select font into hdc;
6) New document for context device;
7) New page;
8) Printing any text;
9) Close the page;
10) Close the document;
11) Cleaning the memory;

This is the code source for this example:

/*
Procedure: Wprint.p

Romanian Data Soft, Romania
*/

IF "{&OPSYS}":U = "UNIX":U THEN RETURN.

/* API calls */
PROCEDURE GetWindowsDirectory EXTERNAL "KERNEL.EXE":
  DEFINE INPUT PARAMETER dirname AS MEMPTR.
  DEFINE INPUT PARAMETER bufsize AS SHORT.
  DEFINE RETURN PARAMETER len    AS SHORT.
END.

PROCEDURE CreateFont EXTERNAL "GDI.EXE":
   DEF INPUT PARAM nHeight         AS SHORT.
   DEF INPUT PARAM nWidth          AS SHORT.
   DEF INPUT PARAM nEscapement     AS SHORT.
   DEF INPUT PARAM nOrientation    AS SHORT.
   DEF INPUT PARAM fnWeight        AS SHORT.
   DEF INPUT PARAM fdwItalic          AS BYTE.
   DEF INPUT PARAM fdwUnderline       AS BYTE.
   DEF INPUT PARAM fdwStrikeOut       AS BYTE.
   DEF INPUT PARAM fdwCharSet         AS BYTE.
   DEF INPUT PARAM fdwOutputPrecision AS BYTE.
   DEF INPUT PARAM fdwClipPrecision   AS BYTE.
   DEF INPUT PARAM fdwQuality         AS BYTE.
   DEF INPUT PARAM fdwPitchAndFamily  AS BYTE.
   DEF INPUT PARAM lpszFace        AS MEMPTR.
   DEF RETURN PARAM ret-val        AS SHORT.
END.

PROCEDURE SelectObject EXTERNAL "GDI.EXE":
  DEFINE INPUT PARAMETER hDC        AS SHORT.
  DEFINE INPUT PARAMETER hObject    AS SHORT.
  DEFINE RETURN PARAMETER apistatus AS SHORT.
END.

PROCEDURE DeleteObject EXTERNAL "GDI.EXE":
  DEFINE INPUT PARAMETER hObject AS SHORT.
END.

PROCEDURE DeleteDC EXTERNAL "GDI.EXE":
  DEFINE INPUT PARAMETER hDC AS SHORT.
END.

PROCEDURE CreateDC EXTERNAL "GDI.EXE":
  DEFINE INPUT  PARAMETER lpDriverName AS CHAR.
  DEFINE INPUT  PARAMETER lpDeviceName AS CHAR.
  DEFINE INPUT  PARAMETER lpOutput     AS CHAR.
  DEFINE INPUT  PARAMETER lpInitData   AS LONG.
  DEFINE RETURN PARAMETER ret-val      AS SHORT.
END.

PROCEDURE TextOut EXTERNAL "GDI.EXE":
   DEF INPUT PARAM          hdc      AS SHORT.
   DEF INPUT PARAM          nXStart  AS SHORT.
   DEF INPUT PARAM          nYStart  AS SHORT.
   DEF INPUT PARAM          lpString AS MEMPTR.
   DEF INPUT PARAM          cbString AS SHORT.
END.

PROCEDURE StartDoc EXTERNAL "GDI.EXE":
  DEFINE INPUT PARAMETER DC         AS SHORT.
  DEFINE INPUT PARAMETER hdocinfo   AS MEMPTR.
  DEFINE RETURN PARAMETER apistatus AS SHORT.
END.

PROCEDURE StartPage EXTERNAL "GDI.EXE":
  DEFINE INPUT PARAMETER DC AS SHORT.
  DEFINE RETURN PARAMETER apistatus AS SHORT.
END.

PROCEDURE EndPage EXTERNAL "GDI.EXE":
  DEFINE INPUT PARAMETER DC AS SHORT.
  DEFINE RETURN PARAMETER apistatus AS SHORT.
END.

PROCEDURE EndDoc EXTERNAL "GDI.EXE":
  DEFINE INPUT PARAMETER DC AS SHORT.
  DEFINE RETURN PARAMETER apistatus AS SHORT.
END.

/* Definitions */
DEF VAR  lm_windir  AS MEMPTR NO-UNDO.
DEF VAR  lm_pdtxt   AS MEMPTR NO-UNDO.
DEF VAR  lm_pdtxt1  AS MEMPTR NO-UNDO.
DEF VAR  lc_windowsdir  AS CHAR NO-UNDO.
DEF VAR  lc_winini      AS CHAR NO-UNDO.
DEF VAR  li_outsize     AS INTE NO-UNDO.
DEF VAR  li_apistatus   AS INTE NO-UNDO.
DEF VAR  ii_x           AS INTE NO-UNDO.
DEF VAR  ii_y           AS INTE NO-UNDO.
DEF VAR  lc_dev         AS CHAR NO-UNDO.
DEF VAR  lc_device      AS CHAR NO-UNDO.
DEF VAR  lc_driver      AS CHAR NO-UNDO.
DEF VAR  lc_output      AS CHAR NO-UNDO.
DEF VAR  lc_init        AS INTE NO-UNDO.
DEF VAR  hDC            AS INTE NO-UNDO.
DEF VAR  hfont          AS INTE NO-UNDO.
DEF VAR  hobj           AS INTE NO-UNDO.
DEF VAR  lm_pdocname    AS MEMPTR NO-UNDO.
DEF VAR  lm_poutbuf     AS MEMPTR NO-UNDO.
DEF VAR  lm_lpdocinfo   AS MEMPTR NO-UNDO.
DEF VAR  lc_docname     AS CHAR NO-UNDO.
DEF VAR  lc_outbuf      AS CHAR NO-UNDO.
DEF VAR  lc_def_font    AS CHAR NO-UNDO.
DEF VAR  lm_lpszFace    AS MEMPTR NO-UNDO.
/* end definitions */

/* find the windows directory */

SET-SIZE(lm_windir) = 80.
RUN GetWindowsDirectory(lm_windir,80, OUTPUT li_outsize).
ASSIGN
      lc_windowsdir = GET-STRING(lm_windir,1)
      lc_winini     = lc_windowsdir + "\" + "WIN.INI"
         .

LOAD lc_winini NO-ERROR .
IF ERROR-STATUS:ERROR THEN DO:
    MESSAGE "LOAD error" VIEW-AS ALERT-BOX.
END.
USE lc_winini NO-ERROR .

/* Load file Win.ini and take the default printer parameters*/

GET-KEY-VALUE SECTION "windows" KEY "device" VALUE lc_dev .
UNLOAD lc_winini NO-ERROR .

lc_device   = ENTRY( 1,lc_dev ) .
lc_driver    = ENTRY( 2,lc_dev ) .
lc_output    = ENTRY( 3,lc_dev ) .

/* Creating an context device to the default printer*/

RUN CreateDC( INPUT lc_driver,
              INPUT lc_device,
              INPUT lc_output,
              INPUT lc_init,
              OUTPUT hDC ) .

/* Creating font */

lc_def_font = "MS Serif" .
SET-SIZE( lm_lpszFace )        = LENGTH( lc_def_font ) + 1.
PUT-STRING( lm_lpszFace,1 )    = lc_def_font .

                      /*6 * li_pxy*/
RUN CreateFont( INPUT 120,              /*nHeight*/
                INPUT 0,                       /*nWidth*/
                INPUT 0,                       /*nEscapement*/
                INPUT 0,                       /*nOrientation*/
                INPUT 400,                     /*fnWeight*/
                INPUT 0,                       /*fdwItalic*/
                INPUT 0,                       /*fdwUnderline*/
                INPUT 0,                       /*fdwStrikeOut*/
                INPUT 1,                       /*fdwCharSet*/
                INPUT 0,                       /*fdwOutputPrecision*/
                INPUT 0,                       /*fdwClipPrecision*/
                INPUT 2,                       /*fdwQuality*/
                INPUT 0,                       /*fdwPitchAndFamily*/
                INPUT lm_lpszFace,              /*pszFace*/
                OUTPUT hfont ).

SET-SIZE( lm_lpszFace )        = 0 .

/*Select font into hdc*/

RUN SelectObject( INPUT hDC,
                  INPUT hfont,
                  OUTPUT hobj ).

/* document properties */

SET-SIZE(lm_pdocname)     = LENGTH(lc_docname) + 1.
PUT-STRING(lm_pdocname,1) = lc_docname.
SET-SIZE(lm_poutbuf)      = LENGTH(lc_outbuf) + 1.
PUT-STRING(lm_poutbuf,1)  = lc_outbuf.

/* Load up the lpdocinfo STRUCT */

bytes each */
PUT-SHORT(lm_lpdocinfo,1)   = 10. /* size of the STRUCT */
PUT-LONG(lm_lpdocinfo,3)    = get-pointer-value(lm_pdocname). /* pointer
to CHAR */
PUT-LONG(lm_lpdocinfo,7)    = get-pointer-value(lm_poutbuf).  /* pointer
to CHAR */

/* new doc*/

RUN StartDoc( INPUT hDC,
              INPUT lm_lpdocinfo,
              OUTPUT li_apistatus ) .

/* new page*/

RUN StartPage( INPUT hDC,
               OUTPUT li_apistatus ) .

ii_x = 100 .
ii_y = 100 .

/* printing texte*/

DEF VAR lc_texte AS CHAR NO-UNDO.
DEF VAR nb AS INTE NO-UNDO.
lc_texte = "Progress 4GL with Windows API - demo".

DO nb=0 TO 10:
    SET-SIZE( lm_pdtxt )      = LENGTH( lc_texte ) + 1 .
    PUT-STRING( lm_pdtxt, 1 ) = lc_texte.

    ii_y = ii_y + 200.

    RUN TextOut( INPUT hDC,
                 INPUT ii_x,                                /*nXStart*/
                 INPUT ii_y,                                /*nYStart*/
                 INPUT lm_pdtxt,                            /*lpString*/

                 INPUT LENGTH( lc_texte  ) ).         /*cbString*/
    SET-SIZE( lm_pdtxt )     = 0 .

END. /*do*/

/* close page*/

RUN EndPage( INPUT hDC,    OUTPUT li_apistatus ) .

/* close document*/

RUN EndDoc( INPUT hDC,       OUTPUT li_apistatus ) .

/* cleaning the font object*/

RUN DeleteObject( INPUT hfont ).

/* cleaning the context device object*/

RUN DeleteDC( INPUT hDC ).



Sun, 14 Oct 2001 03:00:00 GMT
 
 [ 1 post ] 

 Relevant Pages 

1. Printing Access reports or using Access to print/preview reports

2. please revive project 4GL++, using 4gl for Windows and New Era

3. please revive project 4GL++, using 4gl for Windows and New Er

4. Reporting Tool Windows 4GL (MS-Windows)

5. Windows report printing outside of Report Builder

6. Crystal Reports ANd VB 6.0 Printing reports using CRPEAUTO Object, specifying paper orientation problem

7. Printing report from Dynaset using Crystal Report and VB

8. Condensed Printing on 4GL for Windows

9. document failed to print due to GDI/Driver error in rendering

10. 4GL Report (Logo Printing)

11. 4gl report print


 
Powered by phpBB® Forum Software