Solved

Output to printer ?

Posted on 1998-10-09
6
323 Views
Last Modified: 2012-05-05
C++ ( CodeWarrior, PMac ), how do I direct output to the printer instead of the screen ?
0
Comment
Question by:ianscott
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 3

Expert Comment

by:elfie
ID: 1174713
Don't know code warrior , but try a freopen of stdout.
0
 
LVL 3

Accepted Solution

by:
NullTerminator earned 50 total points
ID: 1174714
Start by creating a CPrintDialog object.  do a do modal on it.  Then get relevant printer information from it.

CPrintDialog pdlg;
pdlg.DoModal();
CString strDriver, strDevice, strPort;
strDriver = pdlg.GetDriverName();
strDevice = pdlg.GetDeviceName();
strPort = pdlg.GetPortName();

// Then create a DC, in my case a member variable, (persistent scope)
LPDEVMODE lpDevMode = NULL;
lpDevMode = (LPDEVMODE)GlobalLock(pd.hDevMode);

if (!m_CDC.CreateDC(strDriver, strDevice, strPort, lpDevMode) )      {
        iOK = MessageBox(NULL, "Cannot print to device", "Print Parameters",
              MB_OK | MB_ICONINFORMATION);          
        GlobalFree(lpDevMode);
        return FALSE;
}
GlobalFree(lpDevMode);

//  Now that you have DC,
m_CDC.StartDoc();
m_CDC.StartPage()
m_CDC.TextOut(various params);
// eject
m_CDC.EndPage();
m_CDC.StarPage();
m_CDC.TextOut(more stuff);
m_CDC.EndPage();
m_CDC.EndDoc().

///////////////////////////////////////////////////////////////////////////////////
// Moving & Drawing - Default to calling parent class functions
// BOOL CPTPrinter::LineTo(CPoint ptPoint);
// NOTE INVERTED Y COORDINATES
// Some MapModes have inverted coordinate systems

BOOL CPTPrinter::LineTo(int x, int y)
{
      return m_CDC.LineTo(x, -y);
}        
CPoint CPTPrinter::MoveTo(int x, int y)
{  
       return m_CDC.MoveTo(x, -y);
}  

//  if your first few tries to print feed out blank pages, try a loop which increments the y value from minus 5000 to plus 5000, step by 100's,  print some text and the Y value for reference.  Study the various SetMapMode() choices.  I prefer high english in .001 of inch.  Origin is upper left,  postive x to the right,  negative Y moves downward,

// (Quirk in VC,  RESET MAPMODE after every StartPage() )

'\0'

0
 
LVL 3

Expert Comment

by:NullTerminator
ID: 1174715
Followup,  Sorry if I assumed windows and VC++,

If you are just doing console stuff,  real easy way is to use
fprintf(stdprn, "My String of stuff with %s", "Args As Desired");

'\0'
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ianscott
ID: 1174716
I *am* just doing console stuff - is :
 
fprintf(stdprn, "My String of stuff with %s", "Args As Desired");

- standard C++ o/p to printer ?

Could you clarify what the commands do ?

fprintf=?
stdprn=?

Also, what are the args ?

Thanks,
0
 
LVL 3

Expert Comment

by:NullTerminator
ID: 1174717
fprintf is a standard library function that formats text and outputs it to a FILE stream buffer.  In this case I use the predefined system FILE stream represented by stdprn.  Other standards are stderr, stdout, stdin.

for more information on args, study the specification for printf and format specifiers

fprintf writes to the first argument,  instead of to stdout like printf

You can also use sprintf which writes to a character stream

char s[80];
int i = 10;
sprintf(s, "some Text with number %d", i);  // %d is replace with value of i
//  contents of s is now
//  "some Text with number 10"

'\0'

'\0'
0
 
LVL 3

Expert Comment

by:NullTerminator
ID: 1174718
PS
#include <stdio.h>
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Find Visual Studio Tools 2 134
Embarcadero WebBroker REST server endpoint parameters 2 115
C++ help/ Toy problem 19 69
what type of pointer is this pointer? 3 31
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question