Solved

Output to printer ?

Posted on 1998-10-09
6
315 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

762 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

20 Experts available now in Live!

Get 1:1 Help Now