Solved

Printing in Windows 95

Posted on 1998-08-26
13
199 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
[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
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
Industry Leaders: 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!

 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

  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 …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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.

738 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