home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / MULTIPAD.PAK / PRINTDLG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.4 KB  |  133 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. //    CmdFilePrint   - Present the print dialog to the user and process 
  16. //                       the results.
  17. //    CmdFilePrintSU -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. #include "globals.h"            // prototypes specific to this application
  28. #include "resource.h"
  29.  
  30. static HANDLE hDevMode = NULL;
  31. static HANDLE hDevNames = NULL;
  32.  
  33. //
  34. //  FUNCTION: CmdFilePrint(HWND, WORD, WORD, HWND)
  35. //
  36. //  PURPOSE: Present the print dialog to the user and process the results.
  37. //
  38. //  PARAMETERS:
  39. //    hwnd     - The window handle.
  40. //    wCommand - IDM_PRINT (Unused)
  41. //    wNotify  - Notification number (unused)
  42. //    hwndCtrl - NULL (Unused)
  43. //
  44. //  RETURN VALUE:
  45. //    Always returns 0 - Command handled.
  46. //
  47. //  COMMENTS:
  48. //
  49. //
  50.  
  51. #pragma argsused
  52. LRESULT CmdFilePrint(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  53. {
  54.     PRINTDLG pd = {0};
  55.  
  56.     static DWORD Flags     = PD_ALLPAGES | PD_SHOWHELP | PD_RETURNDC;
  57.     static WORD  nFromPage = 0xFFFF;
  58.     static WORD  nToPage   = 0xFFFF;
  59.     static WORD  nCopies   = 1;
  60.  
  61.      DWORD  nPageRange = GetPageRange();
  62.  
  63.     pd.lStructSize = sizeof(pd);
  64.     pd.hwndOwner   = hwnd;
  65.     pd.hDevMode    = hDevMode;
  66.     pd.hDevNames   = hDevNames;
  67.     pd.Flags       = Flags;
  68.     pd.nFromPage   = nFromPage;
  69.     pd.nToPage     = nToPage;
  70.     pd.nMinPage    = LOWORD(nPageRange);
  71.     pd.nMaxPage    = HIWORD(nPageRange);
  72.     pd.nCopies     = nCopies;
  73.  
  74.     if (PrintDlg(&pd))
  75.     {
  76.           Print(hwnd,
  77.               pd.hDC,
  78.               MAKEBOOL(pd.Flags & PD_PAGENUMS),
  79.               MAKEBOOL(pd.Flags & PD_SELECTION),
  80.               MAKEBOOL(pd.Flags & PD_COLLATE),
  81.               MAKEBOOL(pd.Flags & PD_PRINTTOFILE),
  82.               pd.nFromPage,
  83.               pd.nToPage,
  84.               pd.nCopies,
  85.               pd.hDevNames);
  86.         hDevMode   = pd.hDevMode;
  87.         hDevNames  = pd.hDevNames;
  88.         Flags      = pd.Flags;
  89.         nFromPage  = pd.nFromPage;
  90.         nToPage    = pd.nToPage;
  91.      }
  92.     return 0;
  93. }
  94.  
  95.  
  96. //
  97. //  FUNCTION: CmdPrintSU(HWND, WORD, WORD, HWND)
  98. //
  99. //  PURPOSE: Present the print setup common dialog to the user.
  100. //
  101. //  PARAMETERS:
  102. //    hwnd     - The window handle.
  103. //    wCommand - IDM_PRINTSU (Unused)
  104. //    wNotify   - Notification number (unused)
  105. //    hwndCtrl - NULL (Unused)
  106. //
  107. //  RETURN VALUE:
  108. //    Always returns 0 - Command handled.
  109. //
  110. //  COMMENTS:
  111. //
  112. //
  113.  
  114. #pragma argsused
  115. LRESULT CmdFilePrintSU(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
  116. {
  117.      PRINTDLG pd = {0};
  118.  
  119.     pd.lStructSize = sizeof(pd);
  120.     pd.hwndOwner   = hwnd;
  121.     pd.hDevMode    = hDevMode;
  122.     pd.hDevNames   = hDevNames;
  123.     pd.Flags = PD_SHOWHELP | PD_PRINTSETUP;
  124.  
  125.     if (PrintDlg(&pd))
  126.     {
  127.         hDevMode = pd.hDevMode;
  128.         hDevNames = pd.hDevNames;
  129.     }
  130.  
  131.     return 0;
  132. }
  133.