Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ShellExecute API function

Status
Not open for further replies.

danahn

Programmer
Jul 27, 2003
2
IL
I would like to ask how should I call for direct print without open the require doc file first?

Or if it must be open before printing, how can I force it to be open by WordPad only?
 
HINSTANCE ShellExecute(
HWND hwnd,
LPCTSTR lpOperation,
LPCTSTR lpFile,
LPCTSTR lpParameters,
LPCTSTR lpDirectory,
INT nShowCmd
);

According the documentation, To prints the document file, lpFile parameters must be a document file. If lpFile is not a document file, the function will fail.

So you can print it like this:

ShellExecute(0, "print", "c:\test.doc", NULL, NULL, SW_HIDE)

The command will open & print the doc file using default association program


To open with Wordpad,
- specify lpFile with EXE file (Wordpad)
- specify lpParameters with fullpath & filename, or just the filename and specify fullpath in lpDirectory

ShellExecute(0, NULL, "Wordpad", "C:\test.doc", NULL, SW_SHOWNORMAL)
- or -
ShellExecute(0, NULL, "Wordpad", "test.doc", "C:\", SW_SHOWNORMAL)

Hope it helps



-- AirCon --
 
Thank you for your reply,
I tried your first option to send my doc which is rtf doc directly to printer by calling "SW_HIDE" but it did not solve, anyway the file was loaded for several seconds right after sent to printer. I also tried your second option to load it but force it to be open by WordPad as you wrote, but it actually displaid the WordPad for editing without loading my rtf doc and never sent it to printer eventually.

I would be greatful for your answer.

 
danahn,

ShellExecute(0, "print", "c:\test.rtf", NULL, NULL, SW_HIDE)

The method worked. I'm not sure what you mean with "did not solve"
I tested with rtf file. It worked and printed using default association file (MS WORD). Yes, Word itself still opening for a few seconds (only for the first time, it is much faster after that). And then it close itself.


If you want you can try like this:

; *** Open MS Word, Hide the window
ShellExecute(0, NULL, "Winword", NULL, NULL, SW_HIDE)

; *** Print
ShellExecute(0, "print", "c:\test.rtf", NULL, NULL, SW_HIDE)

By using the method above, you have to close Winword yourself. Because it still open (hidden)


For the second method, it should open the rtf doc in Wordpad (worked for me). But it just open the document. You have to print it using Wordpad menu.

ShellExecute(0, "Open", "Wordpad", "C:\test.rtf", NULL, SW_SHOWNORMAL)


Try again. Come back if you still can't get it to work and post some of your code


-- AirCon --
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top