home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / mswindo / programm / tools / 1771 < prev    next >
Encoding:
Text File  |  1992-12-21  |  3.1 KB  |  78 lines

  1. Newsgroups: comp.os.ms-windows.programmer.tools
  2. Path: sparky!uunet!usc!rpi!uwm.edu!cs.utexas.edu!torn!nott!emr1!jagrant
  3. From: jagrant@emr1.emr.ca (John Grant)
  4. Subject: Re: printing
  5. Message-ID: <1992Dec19.024552.9812@emr1.emr.ca>
  6. Organization: Energy, Mines, and Resources, Ottawa
  7. References: <1658@bdrc.bdrc.bd.com>
  8. Date: Sat, 19 Dec 1992 02:45:52 GMT
  9. Lines: 67
  10.  
  11. In article <1658@bdrc.bdrc.bd.com> jcl@bdrc.bd.com (John C. Lusth) writes:
  12. >This question maybe a FAQ; if it is, I most humbly apologize and will
  13. >wait anxiously for it to appear as it is not on site at the moment.
  14. >
  15. >How does one print using OWL?  The Borland documentation is very confusing
  16. >to me (perhaps because I'm a windows newbie).  It seems to me that
  17. >all I would need to do is instead of writing to a display context
  18. >I would write to device context instead.  Windows should take
  19. >care of everything else for me.  Thus, if I had a function that produced
  20. >some output, I would send it a device context or a display context
  21. >depending on where I wanted the output to go.  Am I being naive? 
  22.  
  23.     You're on the right track.  All you need is an hDC connected
  24.     to either a printer or a client window.  For printing, use
  25.     StartDoc/EndDoc and StartPage/EndPage around your code.
  26.     See Petzold's book for details on how to do this.  You may
  27.     also want a 'cancel' dialog box - this is all explained
  28.     in his and other books as well.
  29.  
  30. >Another question is how to I get a device context?  The CreateDC function
  31. >needs the driver name, the device name, and so on.  Why do I need to
  32. >supply these things?  I just want output to go to the default printer.
  33.  
  34.     Use COMMDLG function PrintDlg() to get an hDC.  You can have
  35.     it come up with the standard interactive display or you
  36.     can have it just return an hDC for the default printer
  37.     with no interaction.  Look at PD_RETURNDC (so it returns
  38.     an hDC) and also PD_RETURNDEFAULT (for default printer,
  39.     with no dialog box displayed).
  40.  
  41. My printing function looks like:
  42.     void PrintMyPicture(HDC hdc,HWND hwnd);
  43.  
  44. so I can use it to process paint & print messages:
  45.     case WM_PAINT:    hdc=BeginPaint(hwnd,&ps);
  46.             PrintMyPicture(hdc,hwnd);
  47.             EndPaint(hwnd,&ps);
  48.             break;
  49.  
  50.     case WM_COMMAND:if(wparam==IDM_PRINT){
  51.               PrintDlg(&pd);
  52.               PrintMyPicture(pd.hDC,NULL);
  53.               DeleteDC(pd.hDC);
  54.             }else{
  55.               ...
  56.             }
  57.             break;
  58.  
  59. Inside PrintMyPicture, I use hwnd to detect whether or not I
  60. am drawing to the printer (hwnd==NULL) or if I am drawing to
  61. the client area.  If I am drawing to the client area,
  62. I use GetClientRect(hwnd,&rect) to get the dimensions of it and
  63. if I am drawing to the printer, I use GetDeviceCaps(hdc,VERTSIZE)
  64. (and HORZSIZE) to get the paper dimensions.  This assumes you
  65. always want to scale your output to the printer page or client
  66. area - it all depends on what you want to do.  With careful
  67. planning, you can structure your code so the same routine
  68. works for both.  I guess this is primarily for graphics - perhaps
  69. it is more difficult for text (I don't do text, just pictures)
  70. since you have to worry about scroll bars etc.  I dunno - maybe
  71. it will work just as well.
  72.  
  73. Good luck.
  74. -- 
  75. John A. Grant                        jagrant@emr1.emr.ca
  76. Airborne Geophysics
  77. Geological Survey of Canada, Ottawa
  78.