home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2002 July & August
/
PCWorld_2002-07-08_cd.bin
/
Software
/
Topware
/
fprint
/
fpdk400.exe
/
samples
/
msvc
/
callback
/
Fpcall.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2000-06-02
|
6KB
|
216 lines
//
// fpcall.cpp
//
// Copyright (c) 1999 FinePrint Software
// All Rights Reserved.
//
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <tchar.h>
#include "fpapi.h"
#include "resource.h"
HINSTANCE ghInstCallback;
/*--------------------------------------------------------------------------
| DllMain
|
| Initial entry point.
--------------------------------------------------------------------------*/
extern "C" BOOL WINAPI DllMain (HINSTANCE hInstance, DWORD dwReason, PCONTEXT pContext)
{
switch (dwReason) {
case DLL_PROCESS_ATTACH:
ghInstCallback = hInstance;
break;
}
return (TRUE);
}
static BOOL NEAR OnInitDialog (
HWND hdlg,
HWND hctlFocus,
LPARAM lParam);
static void NEAR OnCommand (
HWND hdlg,
int id,
HWND hwndCtl,
UINT uNotifyCode);
/*--------------------------------------------------------------------------
| CallbackDlgProc
|
| Dialog function for the Callback dialog box.
--------------------------------------------------------------------------*/
BOOL WINAPI CallbackDlgProc (
HWND hdlg,
UINT wMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (wMsg) {
case WM_INITDIALOG:
return (BOOL) HANDLE_WM_INITDIALOG (hdlg, wParam, lParam, OnInitDialog);
case WM_COMMAND:
HANDLE_WM_COMMAND (hdlg, wParam, lParam, OnCommand);
return (TRUE);
}
// indicate that we did not process the message
return (FALSE);
}
/*--------------------------------------------------------------------------
| OnInitDialog
|
| WM_INITDIALOG handler. Returns FALSE if we set the focus.
--------------------------------------------------------------------------*/
static BOOL NEAR OnInitDialog (
HWND hdlg,
HWND hctlFocus,
LPARAM lParam)
{
return (TRUE);
}
/*--------------------------------------------------------------------------
| OnCommand
|
| WM_COMMAND handler.
--------------------------------------------------------------------------*/
static void NEAR OnCommand (
HWND hdlg,
int id,
HWND hwndCtl,
UINT uNotifyCode)
{
switch (id) {
case PB_Early:
case PB_Late:
case PB_Never:
case IDCANCEL:
EndDialog (hdlg, id);
break;
}
}
/*--------------------------------------------------------------------------
| fpOnStartDocA
|
| FinePrint doc callback function.
--------------------------------------------------------------------------*/
extern "C" DWORD WINAPI fpOnStartDocA (FpDocCallbackA *pDoc)
{
HFinePrint hfp;
HFpStat hStat;
LPCTSTR pszStat = TEXT ("OnStartDoc");
if (fpOpen (pDoc->szFinePrinter, &hfp) == 0) {
// set to 8-up mode
fpSetLayoutAttr (hfp, eliLayout, (const void *) eLayout8);
// create and select a stationery
if (fpCreateStationery (hfp, pszStat, &hStat) == 0) {
fpSetStationeryAttr (hfp, hStat, esiWatermark, esiaText, TEXT ("OnStartDoc watermark"));
fpCloseStationery (hfp, hStat);
fpSetLayoutAttr (hfp, eliStationery, pszStat);
}
fpClose (hfp, FALSE);
}
// bring up a dialog box
MessageBeep (0);
switch (DialogBox (ghInstCallback, MAKEINTRESOURCE (IDD_Callback), NULL, CallbackDlgProc)) {
case PB_Early:
// show the FinePrint dialog now
pDoc->dwShowDlg = ShowDlg_Early;
return (TRUE);
case PB_Late:
// show the FinePrint dialog later
pDoc->dwShowDlg = ShowDlg_Late;
return (TRUE);
case PB_Never:
// skip the FinePrint dialog
pDoc->dwShowDlg = ShowDlg_Never;
return (TRUE);
}
// abort the print job
return (FALSE);
}
/*--------------------------------------------------------------------------
| fpOnEndDocA
|
| FinePrint doc callback function.
--------------------------------------------------------------------------*/
extern "C" DWORD WINAPI fpOnEndDocA (FpDocCallbackA *pDoc)
{
MessageBeep (0);
MessageBox (NULL, TEXT ("In fpOnEndDoc callback."), TEXT ("FinePrint callback DLL"), MB_SETFOREGROUND | MB_ICONINFORMATION | MB_OK);
return (TRUE);
}
/*--------------------------------------------------------------------------
| fpPrePrintA
|
| FinePrint callback function.
--------------------------------------------------------------------------*/
extern "C" DWORD WINAPI fpPrePrintA (FpPrintCallbackA *pPrint)
{
HFinePrint hfp = 0;
TCHAR szPrinter[256] = {0};
LPTSTR pszMsg = new TCHAR [1024];
BOOL fRet;
if (fpOpen (pPrint->szFinePrinter, &hfp) == 0) {
fpGetLayoutAttr (hfp, eliDestPrinter, szPrinter, sizeof (szPrinter));
fpClose (hfp, FALSE);
}
_stprintf (
pszMsg,
TEXT ("About to print to printer \"%s\":\n\n%d document pages\n%d sides of paper\n%d sheets of paper\n\nPrint this job?"),
szPrinter,
pPrint->pc.cDocPages,
pPrint->pc.cPaperSides,
pPrint->pc.cPaperSheets);
MessageBeep (0);
fRet = (MessageBox (
NULL,
pszMsg,
("FinePrint callback DLL"),
MB_SETFOREGROUND | MB_ICONINFORMATION | MB_YESNO) == IDYES);
delete pszMsg;
return (fRet);
}
/*--------------------------------------------------------------------------
| fpOnPrintA
|
| FinePrint callback function.
--------------------------------------------------------------------------*/
extern "C" DWORD WINAPI fpOnPrintA (FpPrintCallbackA *pPrint)
{
HFinePrint hfp = 0;
TCHAR szPrinter[256] = {0};
LPTSTR pszMsg = new TCHAR [1024];
if (fpOpen (pPrint->szFinePrinter, &hfp) == 0) {
fpGetLayoutAttr (hfp, eliDestPrinter, szPrinter, sizeof (szPrinter));
fpClose (hfp, FALSE);
}
_stprintf (
pszMsg,
TEXT ("Printed to printer \"%s\":\n\n%d document pages\n%d sides of paper\n%d sheets of paper"),
szPrinter,
pPrint->pc.cDocPages,
pPrint->pc.cPaperSides,
pPrint->pc.cPaperSheets);
MessageBeep (0);
MessageBox (NULL, pszMsg, ("FinePrint callback DLL"), MB_SETFOREGROUND | MB_ICONINFORMATION | MB_OK);
delete pszMsg;
return (0); // return value is ignored
}