home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / w3_prog / prncdlg.arj / PRNCDLG.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-03  |  21.3 KB  |  780 lines

  1. //*************************************************************
  2. //  File name: PRNCDLG.c
  3. //
  4. //  Description:
  5. //
  6. //      WinMain and window procedure routines.
  7. //
  8. // This sample demonstrates the usage of new printing API available
  9. // in Windows 3.10.  The sample demonstrates the SetAbortProc(), 
  10. // StartDoc(), EndDoc(), StartPage(), and EndPage() printing API.
  11. //
  12. // The sample also demonstrates how to use the ChooseFont and Print
  13. // common dialogs.  The sample allows the user to pick a font and
  14. // display a line of text using that font to the screen.  Also, the
  15. // user can print out the same line of text to a printer selected
  16. // through the Print common dialog.
  17. //
  18. // Development Team:
  19. //
  20. //      Don Miller
  21. //
  22. //
  23. // Written by Microsoft Product Support Services, Windows Developer Support
  24. // Copyright (c) 1992 Microsoft Corporation. All rights reserved.
  25. //*************************************************************
  26. #define PRINTING                    // needed so constants are defined
  27.  
  28. #ifndef _GLOBALINC
  29. #include "global.h"
  30. #endif
  31. #include <string.h>
  32. #include <drivinit.h>               // contains printing constants
  33.  
  34. HANDLE  ghInst          = NULL;
  35. HWND    ghWndMain       = NULL;
  36.  
  37. char    szMainMenu[]    = "MainMenu";
  38. char    szMainClass[]   = "PRNCDLGClass";
  39.  
  40. //*************************************************************
  41. //
  42. //  WinMain()
  43. //
  44. //  Purpose:
  45. //
  46. //        Entry point for all Windows applications.
  47. //
  48. //
  49. //  Parameters:
  50. //
  51. //      HANDLE hInstance     - Handle to current instance
  52. //      HANDLE hPrevInstance - Handle to previous instance
  53. //      LPSTR  lpCmdLine     - Command-line arguments
  54. //      int    nCmdShow      - How window is initially displayed
  55. //      
  56. //
  57. //  Return: (int PASCAL)
  58. //
  59. //
  60. //  Comments:
  61. //
  62. //
  63. //  History:    Date       Author     Comment
  64. //              1/2/92     DAM        Created
  65. //
  66. //*************************************************************
  67.  
  68. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  69. {
  70.     MSG msg;
  71.  
  72.     if (!hPrevInstance && !InitApplication(hInstance))
  73.             return(FALSE);       
  74.  
  75.     if (!InitInstance(hInstance, nCmdShow))
  76.         return(FALSE);
  77.  
  78.     while (GetMessage(&msg, NULL, NULL, NULL))
  79.     {
  80.         TranslateMessage(&msg);      
  81.         DispatchMessage(&msg);       
  82.     }
  83.     return(msg.wParam);      
  84.  
  85. } //*** WinMain
  86.  
  87.  
  88. //*************************************************************
  89. //
  90. //  MainWndProc()
  91. //
  92. //  Purpose:
  93. //
  94. //        Main Window procedure.
  95. //
  96. //
  97. //  Parameters:
  98. //
  99. //      HWND     hWnd   - Handle to main window
  100. //      unsigned msg    - Message passed to application
  101. //      WORD     wParam - Additional message information
  102. //      LONG     lParam - Additional message information
  103. //      
  104. //
  105. //  Return: (long FAR PASCAL)
  106. //
  107. //
  108. //  Comments:
  109. //
  110. //
  111. //  History:    Date       Author     Comment
  112. //              1/2/92     DAM        Created
  113. //
  114. //*************************************************************
  115.  
  116. long FAR PASCAL MainWndProc (HWND hWnd, unsigned msg, WORD wParam, LONG lParam)
  117. {
  118.     FARPROC lpProc;
  119.  
  120.     switch (msg) 
  121.     {
  122.         case WM_CREATE:
  123.             // set global handles to NULL
  124.             pis.hCurrDevMode  = NULL;
  125.             pis.hCurrDevNames = NULL;
  126.             pis.hPrinterFont  = NULL;
  127.  
  128.             // set default text color to black
  129.             sis.crTextColor = RGB(0,0,0);
  130.             break;
  131.  
  132.         case WM_PAINT:
  133.             {
  134.             PAINTSTRUCT ps;
  135.             int         nxLogPix, nyLogPix, iOldMode;
  136.             HFONT       hOldFont;
  137.             DWORD       dwOldColor;
  138.  
  139.             BeginPaint(hWnd, &ps);
  140.  
  141.             // get logical pixels per inch 
  142.             nxLogPix = GetDeviceCaps(ps.hdc, LOGPIXELSX);
  143.             nyLogPix = GetDeviceCaps(ps.hdc, LOGPIXELSY);
  144.  
  145.             // set so text background color is same as window backround color
  146.             iOldMode = SetBkMode(ps.hdc, TRANSPARENT);
  147.  
  148.             // if a screen font has been made use it
  149.             if (sis.hScreenFont != NULL)
  150.                hOldFont = SelectObject(ps.hdc, sis.hScreenFont);
  151.  
  152.             // set text color to color selected by ChooseFont dialog
  153.             dwOldColor = SetTextColor(ps.hdc, sis.crTextColor);
  154.  
  155.             // output a line of text to the screen
  156.             TextOut(ps.hdc, nxLogPix, nyLogPix, "This a line of text", 19);
  157.  
  158.             // reset text color
  159.             SetTextColor(ps.hdc, dwOldColor);
  160.  
  161.             // reset background mode back to previous mode
  162.             SetBkMode(ps.hdc, iOldMode);
  163.  
  164.             // reselect old font back in to dc
  165.             if (sis.hScreenFont != NULL)
  166.                SelectObject(ps.hdc, hOldFont);
  167.  
  168.             EndPaint(hWnd, &ps);
  169.             }
  170.             break;
  171.  
  172.         case WM_COMMAND: 
  173.             switch ( wParam )
  174.             {
  175.                 case IDM_FONTS:
  176.                      // show ChooseFont common dialog box
  177.                      ShowFontBox(hWnd);
  178.                      break;
  179.  
  180.                 case IDM_PRINT:
  181.                      // show Print common dialog box
  182.                      ShowPrintBox(hWnd);
  183.                      break;
  184.  
  185.                 case IDM_PRINTSETUP:
  186.                      // show Print Setup common dialog box
  187.                      ShowPrintSetup(hWnd);
  188.                      break;
  189.  
  190.                 case IDM_EXIT:
  191.                      PostMessage( hWnd, WM_SYSCOMMAND, SC_CLOSE, 0L );
  192.                      break;
  193.  
  194.                 case IDM_ABOUT:
  195.                     // display About dialog box
  196.                     lpProc = MakeProcInstance(About, ghInst);
  197.                     DialogBox(ghInst, "AboutBox", hWnd, lpProc);    
  198.                     FreeProcInstance(lpProc);
  199.                 break;
  200.             }
  201.         break;
  202.  
  203.         case WM_DESTROY:
  204.             // clean up printer font 
  205.             if (pis.hPrinterFont != NULL)
  206.                 DeleteObject(pis.hPrinterFont);
  207.  
  208.             // clean up screen font
  209.             if (sis.hScreenFont != NULL)
  210.                 DeleteObject(sis.hScreenFont);
  211.  
  212.             // had to keep around until app is done using the info 
  213.             if (pis.hCurrDevMode != NULL)
  214.                 GlobalFree(pis.hCurrDevMode);
  215.  
  216.             // had to keep around until app is done using the info 
  217.             if (pis.hCurrDevNames != NULL)
  218.                 GlobalFree(pis.hCurrDevNames);
  219.  
  220.             PostQuitMessage(0);
  221.         break;
  222.     }
  223.     return(DefWindowProc(hWnd, msg, wParam, lParam));
  224.  
  225. } //*** MainWndProc
  226.  
  227.  
  228. //*************************************************************
  229. //
  230. //  About()
  231. //
  232. //  Purpose:
  233. //
  234. //        The About dialog box procedure.
  235. //
  236. //
  237. //  Parameters:
  238. //
  239. //      HWND     hDlg   - Handle to dialog window
  240. //      unsigned msg    - Message passed to dialog window
  241. //      WORD     wParam - Additional message information
  242. //      LONG     lParam - Additional message information
  243. //      
  244. //
  245. //  Return: (BOOL FAR PASCAL)
  246. //
  247. //      TRUE  - About dialog procedure handled the message.
  248. //      FALSE - About dialog procedure did not handle the message.
  249. //
  250. //  Comments:
  251. //
  252. //
  253. //  History:    Date       Author     Comment
  254. //              1/2/92     DAM        Created
  255. //
  256. //*************************************************************
  257.  
  258. BOOL FAR PASCAL About (HWND hDlg, unsigned msg, WORD wParam, LONG lParam)
  259. {
  260.     switch (msg) 
  261.     {
  262.         case WM_INITDIALOG: 
  263.             return(TRUE);
  264.  
  265.         case WM_COMMAND:
  266.             if (wParam == IDOK || wParam == IDCANCEL) 
  267.             {
  268.                 EndDialog(hDlg, TRUE);         
  269.                 return(TRUE);
  270.             }
  271.         break;
  272.     }
  273.     return(FALSE);      // Didn't process a message
  274.  
  275. } //*** About
  276.  
  277.  
  278. //*************************************************************
  279. //
  280. //  ShowPrintSetup
  281. //
  282. //  Purpose:
  283. //        
  284. //    Function responsible for displaying Print Setup common
  285. //    dialog box.  Stores a handle to the current DEVMODE and a
  286. //    handle to the current DEVNAMES in a global PRINTINFOSTRUCT.
  287. //
  288. //  Parameters:
  289. //      HWND hWnd
  290. //      
  291. //
  292. //  Return: (BOOL)
  293. //
  294. //
  295. //  Comments:
  296. //
  297. //
  298. //  History:    Date       Author     Comment
  299. //              1/6/92     DAM        Created
  300. //*************************************************************
  301.  
  302. BOOL ShowPrintSetup (HWND hWnd)
  303. {
  304.     PRINTDLG pdPrint;
  305.  
  306.     pdPrint.lStructSize = sizeof(PRINTDLG);
  307.     pdPrint.hwndOwner   = hWnd;
  308.     pdPrint.hDevMode    = (HANDLE)pis.hCurrDevMode;
  309.     pdPrint.hDevNames   = (HANDLE)pis.hCurrDevNames;
  310.     pdPrint.Flags       = PD_PRINTSETUP;
  311.     pdPrint.hInstance   = (HANDLE)ghInst;
  312.  
  313.     if (PrintDlg(&pdPrint))
  314.     {
  315.         // set global handles
  316.         pis.hCurrDevMode   = pdPrint.hDevMode;
  317.         pis.hCurrDevNames  = pdPrint.hDevNames;
  318.         return TRUE;
  319.     }
  320.     else
  321.     {
  322.         // set global handles
  323.         pis.hCurrDevMode   = pdPrint.hDevMode;
  324.         pis.hCurrDevNames  = pdPrint.hDevNames;
  325.         return FALSE;
  326.     }
  327. } //*** ShowPrintSetup
  328.  
  329.  
  330. //*************************************************************
  331. //
  332. //  ShowFontBox
  333. //
  334. //  Purpose:
  335. //        
  336. //    Function is responsible for displaying ChooseFont common
  337. //    dialog.  Also, the function creates a printer font and a 
  338. //    screen font and stores them in their respective global
  339. //    structures.
  340. //
  341. //  Parameters:
  342. //      HWND hWnd
  343. //      
  344. //
  345. //  Return: (void)
  346. //
  347. //
  348. //  Comments:
  349. //
  350. //
  351. //  History:    Date       Author     Comment
  352. //              1/6/92     DAM        Created
  353. //*************************************************************
  354.  
  355. void ShowFontBox (HWND hWnd)
  356. {
  357.     CHOOSEFONT cf;
  358.     HDC        hPrnDC;
  359.     LOGFONT    lfTemp;
  360.     int        nyLogPix; 
  361.  
  362.     if ((hPrnDC = GetPrinterDC ()) != NULL)
  363.     {
  364.         cf.lStructSize      = sizeof(CHOOSEFONT);
  365.         cf.hwndOwner        = hWnd;
  366.         cf.hDC              = hPrnDC;
  367.         cf.lpLogFont        = &pis.lfCurrFont;
  368.         cf.Flags            = CF_WYSIWYG | CF_BOTH | CF_EFFECTS | CF_SCALABLEONLY | CF_INITTOLOGFONTSTRUCT;
  369.         cf.lCustData        = 0L;
  370.         cf.rgbColors        = sis.crTextColor;
  371.         cf.lpfnHook         = (FARPROC)NULL;
  372.         cf.lpTemplateName   = (LPSTR)NULL;
  373.         cf.hInstance        = ghInst;
  374.         cf.lpszStyle        = (LPSTR)NULL;
  375.         cf.nFontType        = PRINTER_FONTTYPE;
  376.         cf.nSizeMin         = 0;
  377.         cf.nSizeMax         = 0;
  378.  
  379.  
  380.         if (ChooseFont(&cf))
  381.         {
  382.             // get rid of old screen font, if one 
  383.             if (sis.hScreenFont != NULL)
  384.             {
  385.                 DeleteObject(sis.hScreenFont);
  386.                 sis.hScreenFont = NULL;
  387.             }
  388.             // store text color for screen
  389.             sis.crTextColor = (COLORREF)cf.rgbColors;
  390.  
  391.             //create screen font
  392.             sis.hScreenFont = CreateFontIndirect(&pis.lfCurrFont);
  393.  
  394.             // create printer font
  395.             // use temp logfont because global logfont is for screen */
  396.             lfTemp = pis.lfCurrFont;
  397.  
  398.             // adjust font height for correct point size on printer */
  399.             nyLogPix = GetDeviceCaps(hPrnDC, LOGPIXELSY);
  400.             lfTemp.lfHeight = -((cf.iPointSize/10) * nyLogPix)/72;
  401.  
  402.             // get rid of old printer font, if one
  403.             if (pis.hPrinterFont != NULL)
  404.             {
  405.                 DeleteObject(pis.hPrinterFont);
  406.                 pis.hPrinterFont = NULL;
  407.             }
  408.             pis.hPrinterFont = CreateFontIndirect(&lfTemp);
  409.  
  410.             // redraw the client
  411.             InvalidateRect(hWnd, NULL, TRUE);
  412.         }
  413.         DeleteDC(hPrnDC);
  414.     }
  415. } //*** ShowFontBox
  416.  
  417.  
  418. //*************************************************************
  419. //
  420. //  ShowPrintBox
  421. //
  422. //  Purpose:
  423. //        
  424. //    Function responsible for displaying Print  common
  425. //    dialog box.  Stores a handle to the current DEVMODE and a
  426. //    handle to the current DEVNAMES in a global PRINTINFOSTRUCT.
  427. //
  428. //  Parameters:
  429. //      HWND hWnd
  430. //      
  431. //
  432. //  Return: (BOOL)
  433. //
  434. //
  435. //  Comments:
  436. //
  437. //
  438. //  History:    Date       Author     Comment
  439. //              1/6/92     DAM        Created
  440. //*************************************************************
  441.  
  442. BOOL ShowPrintBox (HWND hWnd)
  443. {
  444.     PRINTDLG pdPrint;
  445.     BOOL     bResult;
  446.  
  447.     pdPrint.lStructSize = sizeof(PRINTDLG);
  448.     pdPrint.hwndOwner   = hWnd;
  449.     pdPrint.hDevMode    = (HANDLE)pis.hCurrDevMode;
  450.     pdPrint.hDevNames   = (HANDLE)pis.hCurrDevNames;
  451.     pdPrint.nCopies     = 1;
  452.     pdPrint.Flags       = PD_ALLPAGES | PD_NOPAGENUMS | PD_COLLATE |
  453.                           PD_NOSELECTION | PD_HIDEPRINTTOFILE;
  454.  
  455.     pdPrint.hInstance   = (HANDLE)ghInst;
  456.  
  457.     if (PrintDlg(&pdPrint))
  458.     {
  459.         // set global handles
  460.         pis.hCurrDevMode   = pdPrint.hDevMode;
  461.         pis.hCurrDevNames  = pdPrint.hDevNames;
  462.  
  463.         // send printdlg info to printing routines
  464.         bResult = PrintIt(hWnd, &pdPrint);
  465.  
  466.         return bResult;
  467.     }
  468.     else
  469.     {
  470.         // set global handles
  471.         pis.hCurrDevMode   = pdPrint.hDevMode;
  472.         pis.hCurrDevNames  = pdPrint.hDevNames;
  473.         return FALSE;
  474.     }
  475. } //*** ShowPrintBox
  476.  
  477.  
  478. //*************************************************************
  479. //
  480. //  GetPrinterDC
  481. //
  482. //  Purpose:
  483. //        
  484. //    Function that retrieves a printer dc.  Retrieves a dc with
  485. //    respect to the data in the current DEVMODE and DEVNAMES.
  486. //
  487. //  Parameters:
  488. //      void
  489. //      
  490. //
  491. //  Return: (HDC)
  492. //
  493. //
  494. //  Comments:
  495. //
  496. //
  497. //  History:    Date       Author     Comment
  498. //              1/6/92     DAM        Created
  499. //*************************************************************
  500.  
  501. HDC GetPrinterDC (void)
  502. {
  503.    LPDEVMODE  lpdmDevMode   = NULL;
  504.    LPDEVNAMES lpdnDevNames  = NULL;
  505.    LPSTR      lpstrDevNames = NULL;
  506.  
  507.    // lock handle to DEVMODE struct and send info to CreateDC 
  508.    // This causes a DC to be created that will have the same
  509.    // DEVMODE attributes as what the user picked in the Print
  510.    // Setup dialog.  
  511.  
  512.    if (pis.hCurrDevMode != NULL)
  513.        lpdmDevMode = (LPDEVMODE)GlobalLock(pis.hCurrDevMode);
  514.  
  515.    // lock handle to DEVNAMES struct and send info to CreateDC
  516.    // This causes a DC to be created and linked to the device
  517.    // (printer) that the user selected in the Print Setup 
  518.    // dialog.  If hCurrDevNames is NULL then we create a DC
  519.    // linked to the default printer.
  520.  
  521.    if (pis.hCurrDevNames != NULL)
  522.    {
  523.        lpdnDevNames = (LPDEVNAMES)GlobalLock(pis.hCurrDevNames);
  524.        pis.szDevice = (LPSTR)lpdnDevNames + lpdnDevNames->wDeviceOffset;
  525.        pis.szDriver = (LPSTR)lpdnDevNames + lpdnDevNames->wDriverOffset;
  526.        pis.szOutput = (LPSTR)lpdnDevNames + lpdnDevNames->wOutputOffset;
  527.  
  528.        return CreateDC (pis.szDriver, pis.szDevice, pis.szOutput, (LPSTR)lpdmDevMode);
  529.    }
  530.    else  // create a DC that is linked to the default printer
  531.    {
  532.        GetProfileString ("windows", "device", "", pis.szPrinter, 64) ;
  533.  
  534.        if ((pis.szDevice = (LPSTR)strtok (pis.szPrinter, "," )) &&
  535.            (pis.szDriver = (LPSTR)strtok (NULL,      ", ")) && 
  536.            (pis.szOutput = (LPSTR)strtok (NULL,      ", ")))
  537.            return CreateDC (pis.szDriver, pis.szDevice, pis.szOutput, (LPSTR)lpdmDevMode);
  538.    }
  539.    return NULL;
  540. } //*** GetPrinterDC
  541.  
  542.  
  543. //*************************************************************
  544. //
  545. //  PrintIt
  546. //
  547. //  Purpose:
  548. //        
  549. //    Function that handles all the printing.  Manual banding is
  550. //    not implemented.
  551. //
  552. //  Parameters:
  553. //      HWND hWnd
  554. //      
  555. //
  556. //  Return: (BOOL)
  557. //
  558. //
  559. //  Comments:
  560. //
  561. //
  562. //  History:    Date       Author     Comment
  563. //              1/6/92     DAM        Created
  564. //*************************************************************
  565.  
  566. BOOL PrintIt (HWND hWnd, LPPRINTDLG lpPD)
  567. {
  568.     HDC     hPrnDC;
  569.     DOCINFO di;
  570.     FARPROC lpAbortProc, lpAbortDlg;
  571.     HFONT   hOldFont;
  572.     int     nxLogPix, nyLogPix, dxPrinter, dyPrinter, iPageNum, iCopyNum;
  573.     char    szBuffer[35];
  574.  
  575.     // get a printer dc 
  576.     if ((hPrnDC = GetPrinterDC ()) == NULL)
  577.     {
  578.          MessageBox(hWnd, "Cannot create printer DC!", "ERROR",
  579.                     MB_APPLMODAL|MB_ICONSTOP|MB_OK);
  580.          return FALSE;
  581.     }
  582.  
  583.     // set user abort flag 
  584.     pis.bAbort = FALSE;
  585.  
  586.     // Initialize the abort procedure. 
  587.     lpAbortProc = MakeProcInstance((FARPROC)PrintAbortProc, ghInst);
  588.     lpAbortDlg  = MakeProcInstance((FARPROC)PrintAbortDlg,  ghInst);
  589.  
  590.     // disable main application window 
  591.     EnableWindow(hWnd, FALSE);
  592.  
  593.     // display abort dialog 
  594.     pis.hDlgAbort = CreateDialog(ghInst, "PrintDLG", hWnd, (FARPROC)lpAbortDlg);
  595.  
  596.     // set abort procedure 
  597.     if (SetAbortProc(hPrnDC, lpAbortProc) < 0)
  598.     {
  599.          MessageBox(NULL, "The SetAbortProc function failed.", "ERROR",
  600.                     MB_APPLMODAL|MB_ICONSTOP|MB_OK);
  601.  
  602.          DeleteDC(hPrnDC);
  603.          return FALSE;
  604.     }
  605.  
  606.     // need for StartDoc 
  607.     di.cbSize      = sizeof(DOCINFO);
  608.     di.lpszDocName = (LPSTR)"PRNCDLG";
  609.     di.lpszOutput  = NULL;
  610.  
  611.     // issue STARTDOC 
  612.     if (StartDoc(hPrnDC, &di) < 0)
  613.     {
  614.          MessageBox(NULL, "STARTDOC escape problem", "ERROR",
  615.                     MB_APPLMODAL|MB_ICONSTOP|MB_OK);
  616.  
  617.          DeleteDC(hPrnDC);
  618.          return FALSE;
  619.     }
  620.  
  621.     // get logical pixels per inch 
  622.     nxLogPix  = GetDeviceCaps(hPrnDC, LOGPIXELSX);
  623.     nyLogPix  = GetDeviceCaps(hPrnDC, LOGPIXELSY);
  624.  
  625.     // get page resolution 
  626.     dxPrinter = GetDeviceCaps(hPrnDC, HORZRES);
  627.     dyPrinter = GetDeviceCaps(hPrnDC, VERTRES);
  628.  
  629.     // do the number of collated copies
  630.     for (iCopyNum=1; iCopyNum <= (int)lpPD->nCopies; iCopyNum++)
  631.     {
  632.       for (iPageNum=1; iPageNum <=2 && !pis.bAbort; iPageNum++)
  633.       {
  634.          // update abort dialog box page number
  635.          wsprintf(szBuffer, "Now printing Page %d of", iPageNum);
  636.          SetDlgItemText(pis.hDlgAbort, 100, (LPSTR)szBuffer); 
  637.  
  638.          // select font in
  639.          if (pis.hPrinterFont != NULL)
  640.             hOldFont = SelectObject(hPrnDC, pis.hPrinterFont);
  641.         
  642.          // start printing a page
  643.          StartPage(hPrnDC);
  644.  
  645.          // write something to printer 
  646.          wsprintf(szBuffer, "This is a line of text on page %d", iPageNum);
  647.          TextOut(hPrnDC, nxLogPix, nyLogPix, szBuffer, strlen(szBuffer));
  648.  
  649.          // end the page; resets the dc to normal defaults
  650.          EndPage(hPrnDC);
  651.       }
  652.     }
  653.     // only do if user has not aborted 
  654.     if (!pis.bAbort)
  655.     {
  656.       if (EndDoc(hPrnDC) < 0)    // end the document
  657.       {
  658.              MessageBox(NULL, "EndDoc function problem", "ERROR",
  659.                         MB_APPLMODAL|MB_ICONSTOP|MB_OK);
  660.  
  661.              return FALSE;
  662.       }
  663.     }
  664.  
  665.     // enable main application window 
  666.     EnableWindow(hWnd, TRUE);
  667.  
  668.     // get rid of abort dialog 
  669.     DestroyWindow(pis.hDlgAbort);
  670.  
  671.     // clean up 
  672.     FreeProcInstance(lpAbortProc);
  673.     FreeProcInstance(lpAbortDlg); 
  674.  
  675.     // deselect font, if changed 
  676.     if (pis.hPrinterFont != NULL)
  677.       SelectObject(hPrnDC, hOldFont);
  678.       
  679.     DeleteDC(hPrnDC);
  680. } //*** PrintIt
  681.  
  682.  
  683. // -------------------- Abort Routines --------------------
  684.  
  685.  
  686. //*************************************************************
  687. //
  688. //  PrintAbortProc
  689. //
  690. //  Purpose:
  691. //        
  692. //    Function is used to give application some "multi-tasking"
  693. //    through the use of a PeekMessage().  Also, it gives the 
  694. //    application some error control during printing.
  695. //
  696. //  Parameters:
  697. //      HDC hDC
  698. //      short code
  699. //      
  700. //
  701. //  Return: (BOOL FAR PASCAL)
  702. //
  703. //
  704. //  Comments:
  705. //
  706. //
  707. //  History:    Date       Author     Comment
  708. //              1/6/92     DAM        Created
  709. //*************************************************************
  710.  
  711. BOOL FAR PASCAL PrintAbortProc (HDC hDC, short code)
  712. {
  713.    MSG msg;
  714.  
  715.    while (!pis.bAbort && PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
  716.       if (!IsDialogMessage(pis.hDlgAbort, &msg))
  717.          {
  718.          TranslateMessage(&msg);
  719.          DispatchMessage(&msg);
  720.          }
  721.    return (!pis.bAbort);
  722. }  //*** PrintAbortProc
  723.  
  724.  
  725. //*************************************************************
  726. //
  727. //  PrintAbortDlg
  728. //
  729. //  Purpose:
  730. //        
  731. //    Dialog procedure for print abort dialog.
  732. //
  733. //  Parameters:
  734. //      HWND hWnd
  735. //      unsigned msg
  736. //      WORD wParam
  737. //      LONG lParam
  738. //      
  739. //
  740. //  Return: (int FAR PASCAL)
  741. //
  742. //
  743. //  Comments:
  744. //
  745. //
  746. //  History:    Date       Author     Comment
  747. //              1/6/92     DAM        Created
  748. //*************************************************************
  749.  
  750. int FAR PASCAL PrintAbortDlg (HWND hWnd, unsigned msg, WORD wParam, LONG lParam)
  751. {
  752.    char szMsgBuffer[64];
  753.  
  754.    switch (msg)
  755.       {
  756.       case WM_INITDIALOG:
  757.          SetFocus(hWnd);
  758.          EnableMenuItem(GetSystemMenu(hWnd, FALSE), SC_CLOSE, MF_GRAYED);
  759.  
  760.          // set printing info to abort dialog 
  761.          SetDlgItemText(hWnd, 100, "Now printing Page 1 of");
  762.          
  763.          wsprintf((LPSTR)szMsgBuffer, "'%.25s' on the", (LPSTR)"PRNCDLG"); 
  764.          SetDlgItemText(hWnd, 101, (LPSTR)szMsgBuffer);
  765.  
  766.          wsprintf((LPSTR)szMsgBuffer, "%.20s on %.20s",(LPSTR)pis.szDevice,(LPSTR)pis.szOutput); 
  767.          SetDlgItemText(hWnd, 102, (LPSTR)szMsgBuffer);
  768.  
  769.          return TRUE;
  770.  
  771.       case WM_COMMAND:
  772.          pis.bAbort = TRUE;
  773.          return TRUE;
  774.       }
  775.  
  776.    return FALSE;
  777. }  // PrintAbortDlg() 
  778.  
  779. /*** EOF: PRNCDLG.c ***/
  780.