home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD Direkt 1995 #1
/
Image.iso
/
cdd
/
source
/
vbsource
/
vbprint
/
vbprint.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-09
|
48KB
|
1,409 lines
/*************************************************************************
Print Engine for Visual Basic
Printing utilities for hardcopy output
Written by Barry Nolte
06-28-92 File Created
11-12-92 Added Graphics Functions
01-17-93 General Cleanup of Sources
02-03-93 Simple Bug Fixes
*************************************************************************/
// COPYRIGHT:
//
// (C) Copyright Microsoft Corp. 1993. All rights reserved.
//
// You have a royalty-free right to use, modify, reproduce and
// distribute the Sample Files (and/or any modified version) in
// any way you find useful, provided that you agree that
// Microsoft has no warranty obligations or liability for any
// Sample Application Files which are modified.
//
#include <windows.h>
#include <drivinit.h>
#include <commdlg.h>
#include <memory.h>
#include <stdlib.h>
#include <string.h>
#include "vbprint.h"
// DLL Version Numbers
#define MAJOR_VERSION 1
#define MINOR_VERSION 0
#define BORDER_WIDTH 2 // Default border in points
/*************************************************************************
GLOBAL VARIABLES
*************************************************************************/
static HANDLE hInst; // Handle to calling app
static HWND hWndApp; // Handle ot calling apps main window
static PRINTDLG ppPrinter; // Structure of printer properties
// Misc Procs
static FARPROC lpfnPrintDlgProc; // Printing dialog proc
static FARPROC lpfnAbortProc; // Printing about proc
static BOOL fAbort;
static struct tagPrinterInfo // Information on printer needed to place objects correctly
{
POINT ptPageSize; // Size of the page
RECT rcUnprintable; // Unprintable regions of the printer
RECT rcMargins; // Margins that are set in the Page Layout Function
POINT ptResolution; // Printer Resolution in device DPI
} PrinterInfo;
static struct tagPageInfo // Information on where I'm printing on the page
{
POINT ptCurrentPos; // Current Print Position
DWORD dwCurLineWidth; // Current Line Width, good for multiple calls to ParagraphText
int nTabStop; // Current Tab Stop value
BOOL bPageDirty; // Is the page dirty?
} PageInfo;
static struct tagParagraphInfo // Information on paragraph attributes
{
HFONT hFont; // Handle to paragraphs default font
HFONT hOldFont; // Handle to previous font
TEXTMETRIC tm; // Text metric struct that has info on the font
DWORD dwWidth; // Width of column to print into
int nStyle; // Border and Font Attributes
WORD wBorderWidth; // Border Width in device units (HIBYTE = Horizontal, LOBYTE = Vertical)
int nWidth[LAST_CHAR - FIRST_CHAR + 1]; // Widths of all the fonts characters
int nSpaceBefore; // Space before Paragraph in Points
int nSpaceAfter; // Space After Paragraph in Points
int nLeftIndent; // Paragraph Left Indent size, good for check box justification
} ParagraphInfo;
static struct tagColumnInfo // Information on printing columns
{
HFONT hFont; // Handle to paragraphs default font
HFONT hOldFont; // Handle to previous font
TEXTMETRIC tm; // Text Metric struct that has info on the font
WORD wBorderWidth; // Border Width in device units (HIBYTE = Horizontal, LOBYTE = Vertical)
int nNumColumns; // Number of vertical Columns
int nCellHeight; // Height of Cells
int rgColumnWidths[MAX_COLUMNS]; // Widths of Columns
int nWidth[LAST_CHAR - FIRST_CHAR + 1]; // Widths of all the fonts characters
int nStyle; // Border and Font attributes
} ColumnInfo;
/*************************************************************************
PROTOTYPES
*************************************************************************/
int FAR PASCAL PrinterSetup(HWND hWnd);
int FAR PASCAL InitializePrinter(HWND hWnd);
int FAR PASCAL PageLayoutSetup(int nTop, int nRight, int nBottom, int nLeft);
BOOL DoCommDlgError(HWND hWnd, DWORD dError);
int FAR PASCAL DonePrinting(void);
int FAR PASCAL StartParagraph(LPSTR szFontName, int nFontSize, int nStyle);
int FAR PASCAL FinishParagraph(void);
int FAR PASCAL PrintHeadline(LPSTR szHeadLine, LPSTR szFontName, int nFontSize, int nStyle);
int FAR PASCAL ParagraphText(LPSTR szText);
int FAR PASCAL EjectPage (void);
int TextOutAtCurPos(LPSTR szText);
int GetColumnOffset(int nColumn);
int CellDrawText(HDC hDC, LPSTR szText, LPRECT rc);
BOOL GetUnprintableRegion(HDC hDCPrn);
BOOL GetPrinterResolution(HDC hDCPrn);
BOOL FAR PASCAL PrnAbortProc(HDC hDCPrn, short nCode);
BOOL FAR PASCAL PrintDlgProc(HWND hDlg, WORD message, WORD wParam, LONG lParam);
int FAR PASCAL PrintDLLVersion(VOID);
BOOL FAR PASCAL SetParagraphSpacing(int nSpaceBefore, int nSpaceAfter);
BOOL FAR PASCAL SetBorderWidth(int nWidth);
int FAR PASCAL SetUpColumns(int nNumColumns, LPINT nC, LPSTR szFontName, int nFontSize, int nStyle);
int FAR PASCAL PrintColumnText(LPSTR szText);
int FAR PASCAL EndColumnPrinting(VOID);
int FAR PASCAL PrintColumnHeaders(LPSTR szHeader, int nNumColumns, LPINT nC, LPSTR szFontName, int nFontSize, int nStyle);
HDC GetPrinterDC(void);
BOOL FAR PASCAL KillJob(void);
BOOL FAR PASCAL PrinterName(LPSTR szPrinterName);
BOOL FAR PASCAL PrinterPort(LPSTR szPortName);
BOOL FAR PASCAL IsPageDirty(void);
int FAR PASCAL PagePosY(void);
int FAR PASCAL PagePosX(void);
int FAR PASCAL PageSizeY(void);
int FAR PASCAL PageSizeX(void);
BOOL FAR PASCAL MoveYPos(int nY);
int FDrawLine(HDC hDC, int nStartX, int nStartY, int nEndX, int nEndY);
int FDrawRectangle(HDC hDC, int nStartX, int nStartY, int nEndX, int nEndY);
int FDrawRndRectangle(HDC hDC, int nStartX, int nStartY, int nEndX, int nEndY, int nElpX, int nElpY);
int FDrawEllipse(HDC hDC, int nStartX, int nStartY, int nEndX, int nEndY);
BOOL FAR PASCAL DrawLine(int nX1, int nY1, int nX2, int nY2);
BOOL FAR PASCAL DrawRectangle(int nX1, int nY1, int nX2, int nY2);
BOOL FAR PASCAL DrawRndRectangle(int nX1, int nY1, int nX2, int nY2, int nX3, int nY3);
BOOL FAR PASCAL DrawEllipse(int nX1, int nY1, int nX2, int nY2);
/*************************************************************************
DLL initialization, called once when loaded
*************************************************************************/
int FAR PASCAL LibMain(HANDLE hInstance, WORD wDataSeg, WORD wHeapSize, LPSTR lpszCmdLine)
{
hInst = hInstance; // Save this for later, we may need it
/* Set all structure members to zero. */
_fmemset(&ppPrinter, 0, sizeof(PRINTDLG));
return TRUE;
}
/*************************************************************************
Initialize Printer Driver and set defaults
*************************************************************************/
int FAR PASCAL InitializePrinter(HWND hWnd)
{
char szQueueName[80]={""};
hWndApp = hWnd; // Save the calling apps window handle so we can put up dialogs
fAbort = FALSE;
PageInfo.bPageDirty = FALSE;
ppPrinter.hDC = GetPrinterDC();
if (ppPrinter.hDC)
{
// Do stuff for AbortProc and Printing Dialog
lpfnAbortProc = MakeProcInstance(PrnAbortProc, hInst);
Escape(ppPrinter.hDC, SETABORTPROC, NULL, (LPSTR)(long)lpfnAbortProc, (LPSTR)NULL);
GetUnprintableRegion(ppPrinter.hDC);
GetPrinterResolution(ppPrinter.hDC);
LoadString(hInst, IDS_QUEUE_NAME, (LPSTR)szQueueName, 80);
Escape(ppPrinter.hDC, STARTDOC,lstrlen((LPSTR)szQueueName) ,(LPSTR)szQueueName, NULL);
// Temp Defaults
// Setup defaults
// Set Margins to 1" all around
PrinterInfo.rcMargins.top =
PrinterInfo.rcMargins.bottom =
PrinterInfo.rcMargins.left =
PrinterInfo.rcMargins.right = (int)(INCH * (PrinterInfo.ptResolution.x * 0.01));
// Start at upper left hand corner
PageInfo.ptCurrentPos.x = PrinterInfo.rcMargins.left;
PageInfo.ptCurrentPos.y = PrinterInfo.rcMargins.top;
// Default Tab Stops = 1/2"
PageInfo.nTabStop = (int)(HALF_INCH * (PrinterInfo.ptResolution.x * 0.01));