home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / COMMONDG.PAK / PRINTDLG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.7 KB  |  148 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE: printdlg.c
  9. //
  10. //  PURPOSE:
  11. //    To show the use of the "Print" and "Print Setup" common dialog
  12. //    boxes.
  13. //
  14. //  FUNCTIONS:
  15. //    CmdPrint   - Present the print dialog to the user and process 
  16. //                 the results.
  17. //    CmdPrintSU - Present the print setup common dialog to the user.
  18. //
  19. //  COMMENTS:
  20. //
  21. //
  22. //
  23. //  SPECIAL INSTRUCTIONS: N/A
  24. //
  25.  
  26. #include <windows.h>            // required for all Windows applications
  27. #ifdef WIN16
  28. #include "win16ext.h"           // required only for win16 applications
  29. #include "commdlg.h"           
  30. #endif
  31. #include "globals.h"            // prototypes specific to this application
  32.  
  33. static HANDLE hDevMode = NULL;
  34. static HANDLE hDevNames = NULL;
  35.  
  36. //
  37. //  FUNCTION: CmdPrint(HWND, WORD, WORD, HWND)
  38. //
  39. //  PURPOSE: Present the print dialog to the user and process the results.
  40. //
  41. //  PARAMETERS:
  42. //    hwnd     - The window handle.
  43. //    wCommand - IDM_PRINT (Unused)
  44. //    wNotify  - Notification number (unused)
  45. //    hwndCtrl - NULL (Unused)
  46. //
  47. //  RETURN VALUE:
  48. //    Always returns 0 - Command handled.
  49. //
  50. //  COMMENTS:
  51. //
  52. //
  53.  
  54. #pragma argsused
  55. LRESULT CmdPrint(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  56. {
  57.     PRINTDLG pd = {0};
  58.  
  59.     static DWORD Flags     = PD_PAGENUMS | PD_SHOWHELP | PD_RETURNDC;
  60.     static WORD  nFromPage = 0xFFFF;
  61.     static WORD  nToPage   = 0xFFFF;
  62.     static WORD  nCopies   = 1;
  63.  
  64.     DWORD  nPageRange = GetPageRange();
  65.  
  66.     pd.lStructSize = sizeof(pd);
  67.     pd.hwndOwner   = hwnd;
  68.     pd.hDevMode    = hDevMode;
  69.     pd.hDevNames   = hDevNames;
  70.     pd.Flags       = Flags;
  71.     pd.nFromPage   = nFromPage;
  72.     pd.nToPage     = nToPage;
  73.     pd.nMinPage    = LOWORD(nPageRange);
  74.     pd.nMaxPage    = HIWORD(nPageRange);
  75.     pd.nCopies     = nCopies;
  76.  
  77.     if (PrintDlg(&pd))
  78.     {
  79.         Print(pd.hDC,
  80.               (BOOL)(pd.Flags & PD_PAGENUMS),
  81.               (BOOL)(pd.Flags & PD_SELECTION),
  82.               (BOOL)(pd.Flags & PD_COLLATE),
  83.               (BOOL)(pd.Flags & PD_PRINTTOFILE),
  84.               pd.nFromPage,
  85.               pd.nToPage,
  86.               pd.nCopies,
  87.               pd.hDevNames);
  88.         hDevMode    = pd.hDevMode;
  89.         hDevNames   = pd.hDevNames;
  90.         Flags       = pd.Flags;
  91.         nFromPage   = pd.nFromPage;
  92.         nToPage     = pd.nToPage;
  93.     }
  94.  
  95.     return 0;
  96. }
  97.  
  98.  
  99. //
  100. //  FUNCTION: CmdPrintSU(HWND, WORD, WORD, HWND)
  101. //
  102. //  PURPOSE: Present the print setup common dialog to the user.
  103. //
  104. //  PARAMETERS:
  105. //    hwnd     - The window handle.
  106. //    wCommand - IDM_PRINTSU (Unused)
  107. //    wNotify   - Notification number (unused)
  108. //    hwndCtrl - NULL (Unused)
  109. //
  110. //  RETURN VALUE:
  111. //    Always returns 0 - Command handled.
  112. //
  113. //  COMMENTS:
  114. //
  115. //
  116.  
  117. #pragma argsused
  118. LRESULT CmdPrintSU(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  119. {
  120.      PRINTDLG pd = {0};
  121.  
  122.     pd.lStructSize = sizeof(pd);
  123.     pd.hwndOwner   = hwnd;
  124.     pd.hDevMode    = hDevMode;
  125.     pd.hDevNames   = hDevNames;
  126.     pd.Flags       = PD_SHOWHELP | PD_PRINTSETUP;
  127.  
  128.     if (PrintDlg(&pd))
  129.     {
  130.         MessageBox(hwnd,
  131.                    "Set up the printer",
  132.                    "Print Setup",
  133.                          MB_ICONINFORMATION|MB_OK);
  134.         hDevMode = pd.hDevMode;
  135.         hDevNames = pd.hDevNames;
  136.     }
  137.     else
  138.     {
  139.         MessageBox(hwnd,
  140.                    "Did not set up the printer",
  141.                    "Print Setup",
  142.                    MB_ICONSTOP|MB_OK);
  143.     }
  144.  
  145.  
  146.      return 0;
  147. }
  148.