quitely printing a file

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.)
khaledoAsked:
Who is Participating?
 
duneramConnect With a Mentor Commented:

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
 
duneramCommented:
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
 
khaledoAuthor Commented:
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
duneramCommented:
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
 
khaledoAuthor Commented:
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
 
duneramCommented:
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
 
khaledoAuthor Commented:
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
 
duneramCommented:
I am running nt4 and it's there.
0
 
chensuCommented:
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
 
chensuCommented:
Windows 95 does not have a print.exe. The ShellExecute does not need it.
0
 
duneramCommented:
I just tried it on Win98 and it worked fine.  Earlier I was on NT 4 and it also worked fine.
0
 
khaledoAuthor Commented:
It is working.

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

Thanks for duneram and chensu.


0
 
chensuCommented:
duneram,

Post it as an answer so that khaledo can grade it.
0
 
khaledoAuthor Commented:
Thanks
0
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.