Solved

Printing in Windows 95

Posted on 1998-08-26
13
196 Views
Last Modified: 2010-04-01
This goes hand-in-hand with my previous question, Q.10075158.

Please provide specific lines of code in Visual C++ for the following task.  I will only accept specific lines of code.

Print a char variable, say "firstname", in a particular place on the page, say 1.2 inches from the top and 3 inches from the left of an 8.5 x 11 inch paper.  The paper is run through a LaserJet 5L printer running from a Windows 95 PC.  Don't hesitate to ask if you need more details.


Thank you,

Mark
0
Comment
Question by:Mark Ebden
13 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1171269
Mark do you want to stick with the "writing to the printer file" approach.  (i.e. the wrong way).
Or are you looking to change to the Windows way?
0
 
LVL 23

Expert Comment

by:chensu
ID: 1171270
A Console Application or a GUI Application?
0
 

Author Comment

by:Mark Ebden
ID: 1171271
Am I right in thinking that the "writing to the printer file" way is easier?  If so, then let's make a quick fix.  However if the correct, Windows, way is not too much of a transformation, let's go with that.  It's your call -- thanks!

To answer chensu's question, I think it is a GUI application, but I'm not sure what the difference is.  I use windows -- doesn't that make it GUI automatically?

0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 22

Expert Comment

by:nietod
ID: 1171272
Actually, it has to be your call.  Do you have existing code that used to write directly to the printer?.  If so it may be easier to stay on that same approach.

However, if you are not working with existing code, or if you know you have to make the change eventually, then I would follow the windows approach.

continues.
0
 

Author Comment

by:Mark Ebden
ID: 1171273
Yes, I have existing code for Windows NT, available for perusal in Q.10075158, my previous question.  If the surgery is minor, please operate on that.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1171274
If you want to go the "writing directly to the printer approach" you code will not be very flexible.  It will have to work with a specific type of printer (or printers if you get little fancy).  You can probalby do ordinarly looking at specific locations on the page, but more complex things like different fonts and graphics are going to get very hard.  Everything you do will require knowing printer control codes.  You will need to look up the code for the specific model printer you are using.  

If you go with the windows approach, your code will work with any printer attached to the computer. Thus you don't have to worry about supporting a specific model printer.  You can do text in all sorts of fonts and styles and positioned precisely.  You can do graphics just as easily as you can do text.  You don't have to know any printer control codes.  Windows takes care of it for you.  In the unlikely case that you try to use a feature that is not available for a printer, windows will do its best to simulate that feature or will just ignore what you are doing.
0
 
LVL 12

Expert Comment

by:migel
ID: 1171275
Can you call CommonDialog a PRINTDLG to get Printer DC?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1171276
Mark that code is so short you can easily change it to use the windows method.  The question is do you have thousands of lines of code that would have to be converted.  If that was it, no debate go to windows.  
0
 
LVL 22

Expert Comment

by:nietod
ID: 1171277
If you can (and want to) send me a copy of the program I might be able to give you a better idea of which way to go.  My e-mail address is nietod@theshop.net.  It is worth spending some time on making the right decision here rather than proceeding in the wrond direction.
0
 

Author Comment

by:Mark Ebden
ID: 1171278
I don't think my last comment was added properly.  I restarted Internet Explorer and I'll retype it.

I like the idea of being able to print from any printer.  My printing involves only text -- placing about a dozen pieces of information (first name, birth date, etc.) in particular boxes of a form fed through the printer.  There are not thousands of lines to change, but the Windows way seems better -- the printer versatility you mentioned is desirable.

Oh I must go now but I can send the code later in the day.  Many thanks in advance for looking it over.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1171279
Settled then.  Windows it is.  Ignore the code I posted to the other question then.  

Now where to begin.  First of all, I think someone already asked this, but how do you want to select the printer to print to.  The typical windows way is to let the user chose the printer etc ind a dialog (built-in to windows).  You obviously weren't doing it that way before.  Do you want to now?  If not we can still print to a specific printer, but I would think that the dialog is a better way to go.
0
 
LVL 22

Accepted Solution

by:
nietod earned 400 total points
ID: 1171280
Here is a start.  We'll need to tweak it (a lot).  

      PRINTDLG  pd;
      HDC       DCHnd;
      memset (&pd,0,sizeof(PRINTDLG));
      pd.lStructSize = sizeof(PRINTDLG);
      pd.hwndOwner   = ghwndMain;  // You will want to specify you window handle here.
      pd.Flags       = PD_RETURNDC;
      pd.hInstance   = NULL;

      PrintDlg(&pd); // display the printer dialog.
      DCHnd = pd.hDC; // Save handle to DC to print in.

      if (pd.hDevMode)
        GlobalFree(pd.hDevMode);

      if (pd.hDevNames)
        GlobalFree (pd.hDevNames);

  StartDoc  (DCHnd, &di);
  StartPage (DCHnd);
  TextOut (DCHnd, 5, 5, (LPCTSTR) "A blank page!", sizeof("A blank page!"));
  EndPage   (DCHnd);
  EndDoc    (DCHnd);
  DeleteDC  (DCHnd);


0
 
LVL 22

Expert Comment

by:nietod
ID: 1171281
By the way, I answered this to prevent others from answering.  I think you already paid for an answer in the other question.  If you like, when we are done, you can reject my answer and after 21 days the question will be deleted and you will get back your points.
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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…
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 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…

773 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