home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2001 April
/
PCWorld_2001-04_cd.bin
/
Software
/
Topware
/
fprint
/
fpdk400.exe
/
samples
/
msvc
/
Apisamp2.cpp
< prev
Wrap
C/C++ Source or Header
|
2000-07-18
|
4KB
|
171 lines
//
// apisamp.cpp
//
// Copyright (c) 1999-2000 FinePrint Software
// All Rights Reserved.
//
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include "fpapi.h"
#define ZeroInit(pb) memset((void *)pb,0,sizeof(*(pb)))
#define NUM_ELEMENTS(array) (sizeof(array)/sizeof(array[0]))
// forward references
void ShowError (LPCTSTR pszFunc, FpError fpe);
void ShowError (LPCTSTR pszFunc, DWORD dwError);
void Warning (LPCTSTR pszFmt, ...);
/*--------------------------------------------------------------------------
| WinMain
--------------------------------------------------------------------------*/
int WINAPI WinMain (
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR pszCmdLine,
int nCmdShow)
{
HFinePrint hfp = 0;
FpError fpe;
TCHAR szFinePrinter[MAX_PATH];
// open a FinePrint session
fpGetFinePrinterName (0, szFinePrinter);
if ((fpe = fpOpen (NULL, &hfp)) != 0) {
ShowError (TEXT ("fpOpen"), fpe);
goto Return;
}
/*
** Print some jobs to FinePrint. Wait for each job to finish before
** printing the next one, otherwise synchronization problems can result.
*/
HDC hdc;
DOCINFO di;
FpJobCount jcOrig;
FpJobStatus js;
hdc = CreateDC (NULL, szFinePrinter, NULL, NULL);
ZeroInit (&di);
di.cbSize = sizeof (di);
// print job #1
di.lpszDocName = TEXT ("job1");
fpGetJobCount (hfp, &jcOrig);
StartDoc (hdc, &di);
StartPage (hdc);
TextOut (hdc, 0, 0, di.lpszDocName, _tcslen (di.lpszDocName));
EndPage (hdc);
EndDoc (hdc);
fpWaitForJob (hfp, &jcOrig, NULL, 30, 30, &js);
// print job #2
di.lpszDocName = TEXT ("job2");
fpGetJobCount (hfp, &jcOrig);
StartDoc (hdc, &di);
StartPage (hdc);
TextOut (hdc, 0, 0, di.lpszDocName, _tcslen (di.lpszDocName));
EndPage (hdc);
EndDoc (hdc);
fpWaitForJob (hfp, &jcOrig, NULL, 30, 30, &js);
// print job #3
di.lpszDocName = TEXT ("job3");
fpGetJobCount (hfp, &jcOrig);
StartDoc (hdc, &di);
StartPage (hdc);
TextOut (hdc, 0, 0, di.lpszDocName, _tcslen (di.lpszDocName));
EndPage (hdc);
EndDoc (hdc);
fpWaitForJob (hfp, &jcOrig, NULL, 30, 30, &js);
#if 0
// show the FinePrint dialog
DWORD dwDlg;
fpe = fpDisplayDialog (hfp, &dwDlg);
#endif
#if 0
// print the current jobs to the dest printer, deleting them afterwards
fpe = fpPrintAllJobs (hfp, NULL, TRUE, TRUE);
#endif
// success
MessageBeep (0);
MessageBox (
NULL,
TEXT ("All tests completed successfully!"),
TEXT ("Fpapi Sample Program"),
MB_ICONINFORMATION | MB_OK | MB_SETFOREGROUND);
Return:
if (hfp != 0) {
// close the FinePrint session, leaving the jobs open
fpClose (hfp, FALSE);
}
return (0);
}
/*--------------------------------------------------------------------------
| ShowError
--------------------------------------------------------------------------*/
void ShowError (LPCTSTR pszFunc, FpError fpe)
{
TCHAR sz[256];
wsprintf (
sz,
TEXT ("%s failed with error code %d."),
pszFunc,
fpe);
MessageBeep (0);
MessageBox (
NULL,
sz,
TEXT ("Fpapi Sample Program"),
MB_ICONERROR | MB_OK | MB_SETFOREGROUND);
}
/*--------------------------------------------------------------------------
| ShowError
--------------------------------------------------------------------------*/
void ShowError (LPCTSTR pszFunc, DWORD dwError)
{
TCHAR sz[256];
wsprintf (
sz,
TEXT ("%s failed with error code %d."),
pszFunc,
dwError);
MessageBeep (0);
MessageBox (
NULL,
sz,
TEXT ("Fpapi Sample Program"),
MB_ICONERROR | MB_OK | MB_SETFOREGROUND);
}
/*--------------------------------------------------------------------------
| Warning
|
| Displays a warning message.
--------------------------------------------------------------------------*/
void Warning (LPCTSTR pszFmt, ...)
{
// expand the message string
va_list args;
TCHAR sz[512];
va_start (args, pszFmt);
wvsprintf (sz, pszFmt, args);
va_end (args);
MessageBeep (0);
MessageBox (
NULL,
sz,
TEXT ("Fpapi Sample Program"),
MB_ICONINFORMATION | MB_OK | MB_SETFOREGROUND);
}