?
Solved

quitely printing a file

Posted on 1998-07-22
14
Medium Priority
?
289 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
[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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

752 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