home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.ms-windows.programmer.tools
- Path: sparky!uunet!usc!rpi!uwm.edu!cs.utexas.edu!torn!nott!emr1!jagrant
- From: jagrant@emr1.emr.ca (John Grant)
- Subject: Re: printing
- Message-ID: <1992Dec19.024552.9812@emr1.emr.ca>
- Organization: Energy, Mines, and Resources, Ottawa
- References: <1658@bdrc.bdrc.bd.com>
- Date: Sat, 19 Dec 1992 02:45:52 GMT
- Lines: 67
-
- In article <1658@bdrc.bdrc.bd.com> jcl@bdrc.bd.com (John C. Lusth) writes:
- >This question maybe a FAQ; if it is, I most humbly apologize and will
- >wait anxiously for it to appear as it is not on site at the moment.
- >
- >How does one print using OWL? The Borland documentation is very confusing
- >to me (perhaps because I'm a windows newbie). It seems to me that
- >all I would need to do is instead of writing to a display context
- >I would write to device context instead. Windows should take
- >care of everything else for me. Thus, if I had a function that produced
- >some output, I would send it a device context or a display context
- >depending on where I wanted the output to go. Am I being naive?
-
- You're on the right track. All you need is an hDC connected
- to either a printer or a client window. For printing, use
- StartDoc/EndDoc and StartPage/EndPage around your code.
- See Petzold's book for details on how to do this. You may
- also want a 'cancel' dialog box - this is all explained
- in his and other books as well.
-
- >Another question is how to I get a device context? The CreateDC function
- >needs the driver name, the device name, and so on. Why do I need to
- >supply these things? I just want output to go to the default printer.
-
- Use COMMDLG function PrintDlg() to get an hDC. You can have
- it come up with the standard interactive display or you
- can have it just return an hDC for the default printer
- with no interaction. Look at PD_RETURNDC (so it returns
- an hDC) and also PD_RETURNDEFAULT (for default printer,
- with no dialog box displayed).
-
- My printing function looks like:
- void PrintMyPicture(HDC hdc,HWND hwnd);
-
- so I can use it to process paint & print messages:
- case WM_PAINT: hdc=BeginPaint(hwnd,&ps);
- PrintMyPicture(hdc,hwnd);
- EndPaint(hwnd,&ps);
- break;
-
- case WM_COMMAND:if(wparam==IDM_PRINT){
- PrintDlg(&pd);
- PrintMyPicture(pd.hDC,NULL);
- DeleteDC(pd.hDC);
- }else{
- ...
- }
- break;
-
- Inside PrintMyPicture, I use hwnd to detect whether or not I
- am drawing to the printer (hwnd==NULL) or if I am drawing to
- the client area. If I am drawing to the client area,
- I use GetClientRect(hwnd,&rect) to get the dimensions of it and
- if I am drawing to the printer, I use GetDeviceCaps(hdc,VERTSIZE)
- (and HORZSIZE) to get the paper dimensions. This assumes you
- always want to scale your output to the printer page or client
- area - it all depends on what you want to do. With careful
- planning, you can structure your code so the same routine
- works for both. I guess this is primarily for graphics - perhaps
- it is more difficult for text (I don't do text, just pictures)
- since you have to worry about scroll bars etc. I dunno - maybe
- it will work just as well.
-
- Good luck.
- --
- John A. Grant jagrant@emr1.emr.ca
- Airborne Geophysics
- Geological Survey of Canada, Ottawa
-