home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 October / PCWorld_2002-10_cd.bin / Software / Topware / fprint / fpdk400.exe / samples / msvc / callback / Fpcall.cpp < prev    next >
C/C++ Source or Header  |  2000-06-02  |  6KB  |  216 lines

  1. //
  2. //    fpcall.cpp
  3. //
  4. //        Copyright (c) 1999 FinePrint Software
  5. //        All Rights Reserved.
  6. //
  7. #include <windows.h>
  8. #include <windowsx.h>
  9. #include <stdio.h>
  10. #include <tchar.h>
  11. #include "fpapi.h"
  12. #include "resource.h"
  13.  
  14. HINSTANCE ghInstCallback;
  15.  
  16. /*--------------------------------------------------------------------------
  17. |    DllMain
  18. |
  19. |        Initial entry point.
  20. --------------------------------------------------------------------------*/
  21. extern "C" BOOL WINAPI DllMain (HINSTANCE hInstance, DWORD dwReason, PCONTEXT pContext)
  22. {
  23.     switch (dwReason) {
  24.  
  25.     case DLL_PROCESS_ATTACH:
  26.         ghInstCallback = hInstance;
  27.         break;
  28.  
  29.     }
  30.     return (TRUE);
  31. }
  32.  
  33. static BOOL NEAR OnInitDialog (
  34.                     HWND    hdlg,
  35.                     HWND    hctlFocus,
  36.                     LPARAM    lParam);
  37. static void NEAR OnCommand (
  38.                     HWND    hdlg,
  39.                     int        id,
  40.                     HWND    hwndCtl,
  41.                     UINT    uNotifyCode);
  42.  
  43. /*--------------------------------------------------------------------------
  44. |    CallbackDlgProc
  45. |
  46. |        Dialog function for the Callback dialog box.
  47. --------------------------------------------------------------------------*/
  48. BOOL WINAPI CallbackDlgProc (
  49.                 HWND    hdlg,
  50.                 UINT    wMsg,
  51.                 WPARAM    wParam,
  52.                 LPARAM    lParam)
  53. {
  54.     switch (wMsg) {
  55.     case WM_INITDIALOG:
  56.         return (BOOL) HANDLE_WM_INITDIALOG (hdlg, wParam, lParam, OnInitDialog);
  57.     case WM_COMMAND:
  58.         HANDLE_WM_COMMAND (hdlg, wParam, lParam, OnCommand);
  59.         return (TRUE);
  60.     }
  61.  
  62.     // indicate that we did not process the message
  63.     return (FALSE);
  64. }
  65.  
  66. /*--------------------------------------------------------------------------
  67. |    OnInitDialog
  68. |
  69. |        WM_INITDIALOG handler. Returns FALSE if we set the focus.
  70. --------------------------------------------------------------------------*/
  71. static BOOL NEAR OnInitDialog (
  72.                     HWND    hdlg,
  73.                     HWND    hctlFocus,
  74.                     LPARAM    lParam)
  75. {
  76.     return (TRUE);
  77. }
  78.  
  79. /*--------------------------------------------------------------------------
  80. |    OnCommand
  81. |
  82. |        WM_COMMAND handler.
  83. --------------------------------------------------------------------------*/
  84. static void NEAR OnCommand (
  85.                     HWND    hdlg,
  86.                     int        id,
  87.                     HWND    hwndCtl,
  88.                     UINT    uNotifyCode)
  89. {
  90.     switch (id) {
  91.     case PB_Early:
  92.     case PB_Late:
  93.     case PB_Never:
  94.     case IDCANCEL:
  95.         EndDialog (hdlg, id);
  96.         break;
  97.     }
  98. }
  99.  
  100. /*--------------------------------------------------------------------------
  101. |    fpOnStartDocA
  102. |
  103. |        FinePrint doc callback function.
  104. --------------------------------------------------------------------------*/
  105. extern "C" DWORD WINAPI fpOnStartDocA (FpDocCallbackA *pDoc)
  106. {
  107.     HFinePrint    hfp;
  108.     HFpStat        hStat;
  109.     LPCTSTR        pszStat = TEXT ("OnStartDoc");
  110.  
  111.     if (fpOpen (pDoc->szFinePrinter, &hfp) == 0) {
  112.         // set to 8-up mode
  113.         fpSetLayoutAttr (hfp, eliLayout, (const void *) eLayout8);
  114.  
  115.         // create and select a stationery
  116.         if (fpCreateStationery (hfp, pszStat, &hStat) == 0) {
  117.             fpSetStationeryAttr (hfp, hStat, esiWatermark, esiaText, TEXT ("OnStartDoc watermark"));
  118.             fpCloseStationery (hfp, hStat);
  119.             fpSetLayoutAttr (hfp, eliStationery, pszStat);
  120.         }
  121.  
  122.         fpClose (hfp, FALSE);
  123.     }
  124.  
  125.     // bring up a dialog box
  126.     MessageBeep (0);
  127.     switch (DialogBox (ghInstCallback, MAKEINTRESOURCE (IDD_Callback), NULL, CallbackDlgProc)) {
  128.     case PB_Early:
  129.         // show the FinePrint dialog now
  130.         pDoc->dwShowDlg = ShowDlg_Early;
  131.         return (TRUE);
  132.     case PB_Late:
  133.         // show the FinePrint dialog later
  134.         pDoc->dwShowDlg = ShowDlg_Late;
  135.         return (TRUE);
  136.     case PB_Never:
  137.         // skip the FinePrint dialog
  138.         pDoc->dwShowDlg = ShowDlg_Never;
  139.         return (TRUE);
  140.     }
  141.     // abort the print job
  142.     return (FALSE);
  143. }
  144.  
  145. /*--------------------------------------------------------------------------
  146. |    fpOnEndDocA
  147. |
  148. |        FinePrint doc callback function.
  149. --------------------------------------------------------------------------*/
  150. extern "C" DWORD WINAPI fpOnEndDocA (FpDocCallbackA *pDoc)
  151. {
  152.     MessageBeep (0);
  153.     MessageBox (NULL, TEXT ("In fpOnEndDoc callback."), TEXT ("FinePrint callback DLL"), MB_SETFOREGROUND | MB_ICONINFORMATION | MB_OK);
  154.     return (TRUE);
  155. }
  156.  
  157. /*--------------------------------------------------------------------------
  158. |    fpPrePrintA
  159. |
  160. |        FinePrint callback function.
  161. --------------------------------------------------------------------------*/
  162. extern "C" DWORD WINAPI fpPrePrintA (FpPrintCallbackA *pPrint)
  163. {
  164.     HFinePrint    hfp = 0;
  165.     TCHAR        szPrinter[256] = {0};
  166.     LPTSTR        pszMsg = new TCHAR [1024];
  167.     BOOL        fRet;
  168.  
  169.     if (fpOpen (pPrint->szFinePrinter, &hfp) == 0) {
  170.         fpGetLayoutAttr (hfp, eliDestPrinter, szPrinter, sizeof (szPrinter));
  171.         fpClose (hfp, FALSE);
  172.     }
  173.     _stprintf (
  174.         pszMsg,
  175.         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?"),
  176.         szPrinter,
  177.         pPrint->pc.cDocPages,
  178.         pPrint->pc.cPaperSides,
  179.         pPrint->pc.cPaperSheets);
  180.     MessageBeep (0);
  181.     fRet = (MessageBox (
  182.                 NULL,
  183.                 pszMsg,
  184.                 ("FinePrint callback DLL"),
  185.                 MB_SETFOREGROUND | MB_ICONINFORMATION | MB_YESNO) == IDYES);
  186.     delete pszMsg;
  187.     return (fRet);
  188. }
  189. /*--------------------------------------------------------------------------
  190. |    fpOnPrintA
  191. |
  192. |        FinePrint callback function.
  193. --------------------------------------------------------------------------*/
  194. extern "C" DWORD WINAPI fpOnPrintA (FpPrintCallbackA *pPrint)
  195. {
  196.     HFinePrint    hfp = 0;
  197.     TCHAR        szPrinter[256] = {0};
  198.     LPTSTR        pszMsg = new TCHAR [1024];
  199.  
  200.     if (fpOpen (pPrint->szFinePrinter, &hfp) == 0) {
  201.         fpGetLayoutAttr (hfp, eliDestPrinter, szPrinter, sizeof (szPrinter));
  202.         fpClose (hfp, FALSE);
  203.     }
  204.     _stprintf (
  205.         pszMsg,
  206.         TEXT ("Printed to printer \"%s\":\n\n%d document pages\n%d sides of paper\n%d sheets of paper"),
  207.         szPrinter,
  208.         pPrint->pc.cDocPages,
  209.         pPrint->pc.cPaperSides,
  210.         pPrint->pc.cPaperSheets);
  211.     MessageBeep (0);
  212.     MessageBox (NULL, pszMsg, ("FinePrint callback DLL"), MB_SETFOREGROUND | MB_ICONINFORMATION | MB_OK);
  213.     delete pszMsg;
  214.     return (0);        // return value is ignored
  215. }
  216.