Handling different windows

Hi,

This question is related to my previous post, but now the situation is a little bit different (hopefully it's easier for you). I am now printing a file from VB code with the ShellExecute function. The program that the file comes from (for example .doc is from Word) is opened and it's print method is invoked. Now I am still using a file printer (that prints to a file) and so a dialog box with a textbox is displayed, where I am supposed to fill in the output file name. Now I found this article on the net:

http://www.ml-consult.co.uk/foxst-26.htm

There is says that the ShellExecute function returns a handle for the newly started program. Would that be the print dialog box in my case? And if so, how could I use the handle returned by ShellExecute to manipulate the printer dialog box?

Very, very grateful for help!
[871 byte] By [Striver] at [2007-11-19 23:59:00]
# 1 Re: Handling different windows
My guess would be no. The value that ShellExecute returns would be tied to the application it launched (in this case, Word) and not the printer dialog box (which, if I'm reading you correctly, is a part of a printer installation and not the launching application).

What I think would be happening is that you call ShellExecute, which in turn launches Word in the specified style (in your case, for printing). ShellExecute would, at this point, return the handle. Then, Word then sends the document to the printer, and the printer would then launch the dialog box, which, as far as I know, is it's own process at this point.
ChaosTheEternal at 2007-11-9 19:58:32 >
# 2 Re: Handling different windows
Yeah I also think the same...:(

Do you have any idea on how one could find out the handle for the print process, so that maybe one then can manipulate the print dialog box? Or do you have any idea of solving that print problem that I have?

That is the main goal, to hide the dialog box from appearing and immediately generating an output file that I specify by a variable in the VB code. Has maybe every program (as for example Word) a special bin or dll file representing the printing function it uses when one wants to print a file?
Striver at 2007-11-9 19:59:38 >
# 3 Re: Handling different windows
For most applications, once it has finished spooling a document to the printer, the application that sent the document to the printer has no hand in the printing process.

Word, as well as any Office application, have no forward method to capture anything happening from the printer after spooling, mainly because they don't need to. Once they send the document to the printer, the idea is that the printer will handle the rest, and any problems with the printer should (and will) have no effect on the application that printed the document.

If the printer doesn't have a way to automate printing from a backend (like reading registry keys or an INI file or something), you will probably have to create a watcher application. All it does is wait for the dialog to show up (probably with a Timer and calling FindWindow or FindWindowEx), and when it gets one, it finds the text field, enters the information, and simulates a click or enter press on the Save button.

It's a lot messier, and if the printer dialog is the same as most Save File dialogs (including the caption), it gets a lot harder to capture the right window. Unless, of course, users won't run anything else while that application is printing and capturing the dialogs.
ChaosTheEternal at 2007-11-9 20:00:41 >
# 4 Re: Handling different windows
If you are just printing to a file, then why not print to a PDF format? You could use PDFCreator, which is free, that you can program the location it prints to.

You could set it to the default printer, also.
dglienna at 2007-11-9 20:01:41 >
# 5 Re: Handling different windows
ChaosTheEternal...that sounds like a very nice way of doing it...but as I am still a beginner to VB, it would be very nice if you could provide me some nice links to that stuff or if you could somehow guide me on how to write that code...I would really appreciate it (I just lack the knowledge on what the functions are called and what should be their parameters, otherwise I know how to program well :)). Thanks in advance!
Striver at 2007-11-9 20:02:40 >
# 6 Re: Handling different windows
Also, regarding dgliennas post...I have installed the PDFCreator and it prints nicely. The thing is that in my application I first have to print some files and them combine them in a big pdf file. So how could one in this case combine several PDF documents? Is there some free script that does that? I have downloaded the JoinPDF script (or something like that), but it could only combine up to 8 PDF documents :S
Striver at 2007-11-9 20:03:43 >
# 7 Re: Handling different windows
Hello,

I found this interesting article that might be able to solve my problem!
http://www.freevbcode.com/ShowCode.asp?ID=2836

The thing is, when I run the code, I get an overflow on the SendDlgItemMessage line. Any idea on what it might be?

Thanks in advance
Striver at 2007-11-9 20:04:42 >