Printing in Windows 95

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 EbdenAsked:
Who is Participating?
nietodConnect With a Mentor Commented:
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)

      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);

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?
A Console Application or a GUI Application?
Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Mark EbdenAuthor Commented:
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?

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.

Mark EbdenAuthor Commented:
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.

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.
Can you call CommonDialog a PRINTDLG to get Printer DC?
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.  
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  It is worth spending some time on making the right decision here rather than proceeding in the wrond direction.
Mark EbdenAuthor Commented:
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.

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.
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.