🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.os.ms-windows.programmer.tools
4 messages
4 total messages Started by John C. Lusth Fri, 18 Dec 1992 19:38
printing
#710
Author: John C. Lusth
Date: Fri, 18 Dec 1992 19:38
23 lines
1373 bytes
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? 

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.

Would some kind soul send me a minimal program to print the phrase
"Hello, world!" via Windows?

thanks muchly,

john
-- 
John C. Lusth, Becton Dickinson Research Center, RTP, NC, USA  jcl@bdrc.bd.com
Re: printing
#712
Author: Chris Marriott
Date: Fri, 18 Dec 1992 21:15
54 lines
2599 bytes
In article <1658@bdrc.bdrc.bd.com> jcl@bdrc.bd.com writes:

>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? 
>

That's exactly right.  Just write your drawing code to draw on a DC.
In most cases the code shouldn't care if it's drawing on the screen,
to a printer, a metafile, or whatever.  In the rare cases you DO need
to know, call "GetDeviceCaps" to find out.

>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.
>

The simple way in Window 3.1 is to use the printer common dialog box.  Just
call the "PrintDlg" function, and it returns you a DC.  Easy.

>Would some kind soul send me a minimal program to print the phrase
>"Hello, world!" via Windows?
>

I don't have any code to hand, but, in its simplest form all you do is:

    ... Get Printer DC from common dialog function .....

    StartDoc(....);
    StartPage(.....);

    ... draw to printer DC ....

    EndPage( ... );
    EndDoc( ... );

    DeleteDC( hPrinter );

If you have multiple pages to print, just have StartPage()/EndPage() around
each one.

Chris
-- 
--------------------------------------------------------------------------
| Chris Marriott                           | chris@chrism.demon.co.uk    |
| Warrington, UK                           | BIX: cmarriott              |
| (Still awaiting inspiration              | CIX: cmarriott              |
|  for a witty .sig .... )                 | CompuServe: 100113,1140     |
--------------------------------------------------------------------------
 
Re: printing
#713
Author: John Grant
Date: Sat, 19 Dec 1992 02:45
67 lines
3275 bytes
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
Landscape Mode Printing
#614
Author: Blake Mcneill 281-9391
Date: Tue, 22 Dec 1992 09:50
33 lines
2002 bytes
I have a problem concerning printing in Landscape mode in
Windows 3.1 in a program that I am writing with Borland C++
version 3.1.  What is frustrating about this is that
everything works when I print Portrait mode but nothing
prints under Landscape mode (Laserjet IIIsi or Roland 9
pin).  I'm under the impression that there is no difference
in my code for Portrait and Landscape modes since windows
handles the print orientation.  Could I be wrong??  It
wouldn't be the first time!  I have tried some other source
code (DLGDEMO4 from PC-Magazine July 1992 by Ray Duncan, for
example) and have found that these programs also fail to
print in Landscape mode.

If I use landscape mode the window does not refresh from the
print dialog box and the program hangs on the EndPage
function until I cancel the print job.  Nothing is sent to
the printer.  Something is sent to the Print Spooler (a
StartDoc or StartPage) but no record of anything to
physically print.  If I click anywhere other then the cancel
print job button in my abort print dialog, I might have to
cntrl-alt-del the program to kill it.  I know that my
printer works with Landscape mode since NotePad and other
applications print Landscape mode just fine.  Could my
problem be something that I'm missing or could it be some
undocumented function or what?  

Any help would be greatly appreciated.

Blake McNeill

@cuugnet.cuug.ab.ca

Does a psychic's phone ever ring??
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads