SAMPLE: Code Sample Manages Printing Reports in Applications

Last reviewed: February 15, 1996
Article ID: Q75110
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) for Windows versions 3.1 and 3.0

SUMMARY

REPMGR is a file in the Software Library that contains source code for a Windows module that manages the generating of reports from an application. The following seven services are provided:

  1. Printing textual data in a fixed-pitch font

  2. Numbering each page of the report

  3. Printing headers and footers and the date on each page

  4. Activating the appropriate printer-setup dialog box

  5. Activating a printer selection dialog box

  6. Printing some very simple graphics

  7. Providing a basic Print Preview operation

The following is a list of three enhancements that one might add to provide additional functionality:

  1. Provide support for proportional fonts with tabs

  2. Print bitmap graphics

  3. Format the text

This article discusses the services that this module provides and contains a code fragment that demonstrates using some of the services to print a simple report.

MORE INFORMATION

The interface to the report generator is as follows:

   BOOL PrinterControl(int iCommand, int iParam, LPSTR szParam);

Functions:

   iCommand         iParam                 szParam
   --------         ------                 -------

   PC_SETCOLS       # of columns           Not used
   PC_SETROWS       # of rows              Not used
   PC_PRINT         Not used               Not used
   PC_CLEARALL      Not used               Not used
   PC_ADDLINE       -1 for next line,
                    (n) for line # to add  LPSTR to line
   PC_ADDBAR        -1 for width of page,  LPSTR to character
                    (n) for bar width      (NULL = '-')
   PC_SETPAGENUM    Page number            Not used
   PC_SETHEADERn    Not used               LPSTR to header, NULL = clear
   PC_ADDHEADERn    Not used               Not used
   PC_SETFOOTER1    Not used               LPSTR to header, NULL = clear
   PC_ADDFOOTER1    Not used               Not used
   PC_STARTJOB      Not used               Not used
   PC_ENDJOB        TRUE = OK,
                    FALSE = Abort          Not used
   PC_SETTITLE      Not used               LPSTR to title
   PC_SETPRINTMODE  PC_CODE_PRINT or
                    PC_CODE_PREVIEW        Not used
   PC_GRAPHICS      Not used               LPGRAPHPARAMBLOCK


The following code prints a sample report:

void DoSampleReport (int iMode)
{
    int  i;
    char szText[80];

    PrinterControl(PC_SETPRINTMODE, iMode, 0L);
    PrinterControl(PC_SETCOLS, 80, 0L);
    PrinterControl(PC_SETROWS, 55, 0L);

    PrinterControl(PC_SETHEADER1, 0, "Header #1");
    PrinterControl(PC_SETHEADER2, 0, "Header #2");
    PrinterControl(PC_SETHEADER3, 0, "Header #3");

    PrinterControl(PC_SETTITLE, 0, "Sample Report");
    PrinterControl(PC_STARTJOB, 0, 0L);
    PrinterControl(PC_CLEARALL, 0, 0L);

    PrinterControl(PC_ADDBAR, -1, "=");
    PrinterControl(PC_ADDLINE, -1, "Added line");

    for (i = 0; i < 100; i++)
      {
      wsprintf(szText, "Loop Added Line #%d", i + 1);
      PrinterControl(PC_ADDLINE, -1, szText);
      }

    PrinterControl(PC_ADDBAR, -1, "=");
    PrinterControl(PC_PRINT, CUR_PRINT_MODE, NULL);

    PrinterControl(PC_ENDJOB, HARDCOPYONLY, NULL);
}

The following functions are provided to set up and select the printer:

   PrinterSetupDialog();
   PrinterSelectDialog();

Download REPMGR.EXE, a self-extracting file, from the Microsoft Software Library (MSL) on the following services:
  • Microsoft Download Service (MSDL)

          Dial (206) 936-6735 to connect to MSDL
          Download REPMGR.EXE (size: 27591 bytes) 
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the \SOFTLIB\MSLFILES directory
          Get REPMGR.EXE (size: 27591 bytes) 
    


Additional reference words: 3.10 softlib REPMGR.EXE
KBCategory: kbprg kbfile
KBSubcategory: GdiPrn


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 15, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.