Solved

quitely printing a file

Posted on 1998-07-22
14
244 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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 100 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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. …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

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