?
Solved

quitely printing a file

Posted on 1998-07-22
14
Medium Priority
?
298 Views
Last Modified: 2013-11-20
How can I send a file to the default printer without opening its application or the printer dialog? The file type is known to the shell (ex. *.doc)

Details of the question:
1.Do I need to have this file saved in a special format?
(When I checked the option SaveToFile in my printer dialog, I got the file in *.prn format. )
2. Does *.prn format depend on the printer selected when the file is printed_to_file?
3. How to make my application send this file (or original file *.doc for example) to the printer
4. How to make my application prevent opening the printer dialog but make sure that I am using the default printer.
5. How to get the result of the printing job (success, fail,..etc.)
0
Comment
Question by:khaledo
  • 6
  • 5
  • 3
14 Comments
 
LVL 2

Expert Comment

by:duneram
ID: 1319642
If you are running on 95/98 or NT you can drag the file onto the top of the printer icon.  That will auto print the file without starting any applications.

If you wish to do it from within a program, you can always resort to the simple method (if its a text file) of

1)   build a command string of the form

     "notepad /p myfile.txt"

(if you have to build the text file yourself, you
   a. create it
   b. close it. )
2) run WinExec("notepad /p myfile.txt", SW_HIDE);

That willl spawn the notepad program, tell it to automatically print to the default printer, and 3 hide the window.

perhaps this will provide a quick method?

0
 

Author Comment

by:khaledo
ID: 1319643
Thanks, but this will not work unless the file original application accept a command line parameter. Not all applications accept /p parameter. plus it includes opening the file's original program which I want to avoid.

Is there a general solution or a way for me to send a file to the default printer from my program without needing its original application ?
0
 
LVL 2

Expert Comment

by:duneram
ID: 1319644
Notepad.exe does accept a /p parameter and it ships with windows.  Its the default text editor for text file.    using the SW_HIDE, hides the application as it runs and prints the file.  After it is done, the application automatically closes.  Its  a back door.

If you just want to spool a file to the printer without this quick and easy back door, you need to take a look at microsoft's article Q111010  or Q119113   they present api methods to do this without routing thru the printer....

To get there, go to http://support.microsoft.com/support/c.asp?FR=0 and enter Q111010 as the keyword to search on (choose all products). and then press find.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:khaledo
ID: 1319645
microsoft's articles Q111010  and Q119113 provide solutions for local printers only.

Is it possible to just make my application send *.prn to the default printer (which can be network printer)? If yes, then I need some answers to my original question. If no, then I need another back door if possible.
 
Thnaks
0
 
LVL 2

Expert Comment

by:duneram
ID: 1319646
You can use the ShellExecute API to accomplish this task.

there is a 'print.exe' that ships with windows.  and it will route it to the default printer automatically.

If you did a ShellExecute(hwnd, "print", "filename.prn", "c:\", SW_HIDE);

That should do the trick
0
 

Author Comment

by:khaledo
ID: 1319647
Cannot find any print.exe on my HDD nor on my Window CD
Does it come with any Window's version?
My Window is 4.00.950 C
0
 
LVL 2

Expert Comment

by:duneram
ID: 1319648
I am running nt4 and it's there.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1319649
khaledo,

Have you tried what duneram suggested? I think the following should work.

ShellExecute(hwnd, _T("print"), _T("readme.txt"), NULL, NULL, SW_HIDE);

0
 
LVL 23

Expert Comment

by:chensu
ID: 1319650
Windows 95 does not have a print.exe. The ShellExecute does not need it.
0
 
LVL 2

Expert Comment

by:duneram
ID: 1319651
I just tried it on Win98 and it worked fine.  Earlier I was on NT 4 and it also worked fine.
0
 

Author Comment

by:khaledo
ID: 1319652
It is working.

ShellExecute(hwnd, _T("print"), _T("readme.txt"), NULL, NULL, SW_HIDE);

Thanks for duneram and chensu.


0
 
LVL 23

Expert Comment

by:chensu
ID: 1319653
duneram,

Post it as an answer so that khaledo can grade it.
0
 
LVL 2

Accepted Solution

by:
duneram earned 400 total points
ID: 1319654

You can use the ShellExecute API to accomplish this task.

     there is a 'print.exe' that ships with windows.  and it will route it to the default printer
     automatically.

     If you did a ShellExecute(hwnd, "print", "filename.txt", "c:\", SW_HIDE);

     That should do the trick
0
 

Author Comment

by:khaledo
ID: 1319655
Thanks
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

862 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