Solved

Output to printer ?

Posted on 1998-10-09
6
316 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now