home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 October / PCWorld_2002-10_cd.bin / Software / Topware / fprint / fpdk400.exe / samples / msvc / Apisamp2.cpp < prev   
C/C++ Source or Header  |  2000-07-18  |  4KB  |  171 lines

  1. //
  2. //    apisamp.cpp
  3. //
  4. //        Copyright (c) 1999-2000 FinePrint Software
  5. //        All Rights Reserved.
  6. //
  7. #include <windows.h>
  8. #include <stdio.h>
  9. #include <tchar.h>
  10. #include "fpapi.h"
  11.  
  12. #define ZeroInit(pb)        memset((void *)pb,0,sizeof(*(pb)))
  13. #define NUM_ELEMENTS(array)    (sizeof(array)/sizeof(array[0]))
  14.  
  15. // forward references
  16. void ShowError (LPCTSTR pszFunc, FpError fpe);
  17. void ShowError (LPCTSTR pszFunc, DWORD dwError);
  18. void Warning (LPCTSTR pszFmt, ...);
  19.  
  20. /*--------------------------------------------------------------------------
  21. |    WinMain
  22. --------------------------------------------------------------------------*/
  23. int WINAPI WinMain (
  24.                 HINSTANCE    hInstance,
  25.                 HINSTANCE    hPrevInstance,
  26.                 LPSTR        pszCmdLine,
  27.                 int            nCmdShow)
  28. {
  29.     HFinePrint    hfp = 0;
  30.     FpError        fpe;
  31.     TCHAR        szFinePrinter[MAX_PATH];
  32.  
  33. // open a FinePrint session
  34.     fpGetFinePrinterName (0, szFinePrinter);
  35.     if ((fpe = fpOpen (NULL, &hfp)) != 0) {
  36.         ShowError (TEXT ("fpOpen"), fpe);
  37.         goto Return;
  38.     }
  39.  
  40. /*
  41. **    Print some jobs to FinePrint.  Wait for each job to finish before
  42. **    printing the next one, otherwise synchronization problems can result.
  43. */
  44.     HDC            hdc;
  45.     DOCINFO        di;
  46.     FpJobCount    jcOrig;
  47.     FpJobStatus    js;
  48.  
  49.     hdc = CreateDC (NULL, szFinePrinter, NULL, NULL);
  50.     ZeroInit (&di);
  51.     di.cbSize = sizeof (di);
  52.  
  53. // print job #1
  54.     di.lpszDocName = TEXT ("job1");
  55.     fpGetJobCount (hfp, &jcOrig);
  56.     StartDoc (hdc, &di);
  57.     StartPage (hdc);
  58.     TextOut (hdc, 0, 0, di.lpszDocName, _tcslen (di.lpszDocName));
  59.     EndPage (hdc);
  60.     EndDoc (hdc);
  61.     fpWaitForJob (hfp, &jcOrig, NULL, 30, 30, &js);
  62.  
  63. // print job #2
  64.     di.lpszDocName = TEXT ("job2");
  65.     fpGetJobCount (hfp, &jcOrig);
  66.     StartDoc (hdc, &di);
  67.     StartPage (hdc);
  68.     TextOut (hdc, 0, 0, di.lpszDocName, _tcslen (di.lpszDocName));
  69.     EndPage (hdc);
  70.     EndDoc (hdc);
  71.     fpWaitForJob (hfp, &jcOrig, NULL, 30, 30, &js);
  72.  
  73. // print job #3
  74.     di.lpszDocName = TEXT ("job3");
  75.     fpGetJobCount (hfp, &jcOrig);
  76.     StartDoc (hdc, &di);
  77.     StartPage (hdc);
  78.     TextOut (hdc, 0, 0, di.lpszDocName, _tcslen (di.lpszDocName));
  79.     EndPage (hdc);
  80.     EndDoc (hdc);
  81.     fpWaitForJob (hfp, &jcOrig, NULL, 30, 30, &js);
  82.  
  83. #if 0
  84. // show the FinePrint dialog
  85.     DWORD    dwDlg;
  86.  
  87.     fpe = fpDisplayDialog (hfp, &dwDlg);
  88. #endif
  89. #if 0
  90. // print the current jobs to the dest printer, deleting them afterwards
  91.     fpe = fpPrintAllJobs (hfp, NULL, TRUE, TRUE);
  92. #endif
  93.  
  94.     // success
  95.     MessageBeep (0);
  96.     MessageBox (
  97.         NULL,
  98.         TEXT ("All tests completed successfully!"),
  99.         TEXT ("Fpapi Sample Program"),
  100.         MB_ICONINFORMATION | MB_OK | MB_SETFOREGROUND);
  101.  
  102. Return:
  103.     if (hfp != 0) {
  104.         // close the FinePrint session, leaving the jobs open
  105.         fpClose (hfp, FALSE);
  106.     }
  107.     return (0);
  108. }
  109.  
  110. /*--------------------------------------------------------------------------
  111. |    ShowError
  112. --------------------------------------------------------------------------*/
  113. void ShowError (LPCTSTR pszFunc, FpError fpe)
  114. {
  115.     TCHAR    sz[256];
  116.  
  117.     wsprintf (
  118.         sz,
  119.         TEXT ("%s failed with error code %d."),
  120.         pszFunc,
  121.         fpe);
  122.     MessageBeep (0);
  123.     MessageBox (
  124.             NULL,
  125.             sz,
  126.             TEXT ("Fpapi Sample Program"),
  127.             MB_ICONERROR | MB_OK | MB_SETFOREGROUND);
  128. }
  129.  
  130. /*--------------------------------------------------------------------------
  131. |    ShowError
  132. --------------------------------------------------------------------------*/
  133. void ShowError (LPCTSTR pszFunc, DWORD dwError)
  134. {
  135.     TCHAR    sz[256];
  136.  
  137.     wsprintf (
  138.         sz,
  139.         TEXT ("%s failed with error code %d."),
  140.         pszFunc,
  141.         dwError);
  142.     MessageBeep (0);
  143.     MessageBox (
  144.             NULL,
  145.             sz,
  146.             TEXT ("Fpapi Sample Program"),
  147.             MB_ICONERROR | MB_OK | MB_SETFOREGROUND);
  148. }
  149.  
  150. /*--------------------------------------------------------------------------
  151. |    Warning
  152. |
  153. |        Displays a warning message.
  154. --------------------------------------------------------------------------*/
  155. void Warning (LPCTSTR pszFmt, ...)
  156. {
  157.     // expand the message string
  158.     va_list    args;
  159.     TCHAR    sz[512];
  160.  
  161.     va_start (args, pszFmt);
  162.     wvsprintf (sz, pszFmt, args);
  163.     va_end (args);
  164.     MessageBeep (0);
  165.     MessageBox (
  166.             NULL,
  167.             sz,
  168.             TEXT ("Fpapi Sample Program"),
  169.             MB_ICONINFORMATION | MB_OK | MB_SETFOREGROUND);
  170. }
  171.