?
Solved

Output to printer ?

Posted on 1998-10-09
6
Medium Priority
?
326 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 200 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
Independent Software Vendors: 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

764 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