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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using ShellExecute to print a PDF to specific printer 2

Status
Not open for further replies.

KarenLloyd

Programmer
Nov 23, 2005
141
GB
Hi Gurus

With reference to so many threads (thread184-698845, thread184-1485500 and thread184-1485500 to name but a few...) I needed to print a PDF from VFP6 and I thank you for your tips for ShellExecute, which I am finding increasingly useful for different things - file case naming etc.

I have had to pull together a few different elements so that I can print a VFP6 report (a) to the desired printer, (b) to a PDF and then (c) using PDFTK to watermark the PDF. (I know that I should look to VFP9 for these features such as watermarking... but I also need to figure out the installation side of VFP9 - such as is it a DLL distribution or an each machine registry issue...) Anyway - both the invoice report FRX and the filecopy/watermarked PDF need to go to a printer that is not the default printer.

Bearing in mind that I am still in VFP6 - please can you give me examples of how to manage this, even if I have to add in delay time to do so. It must need to set the windows default printer in another way - as SET PRINTER TO NAME ThePrinterName is not doing the job. The VFP report goes to the right one, but the PDF sent by ShellExecute still goes to the original default printer - even though SET("Printer",3) has recognised the change. It's mildly frustrating so far...

Sorry about the long winded post - I would really be grateful for any advice you can offer...

Thanks

Karen
 
I don't see you using ShellExecute here, you use RUN.

With Shellexecute you can determine tthe action "open" or "print" with the PDF file and if you Shellexecute a PDF with the "print" action it should print and not leave the PDF reader open.

Otherwise you need to use soem API to kill the process, eg use SendMessage with the hWnd you use to quit the application.

It seems SendMessage(hWnd, 0x10, 0, 0) shoudl do that. Try 0x12 insread, WM_QUIT. 0x10 is WM_CLOSE.

Bye, Olaf.
 
Olaf said:
With Shellexecute you can determine tthe action "open" or "print" with the PDF file and if you Shellexecute a PDF with the "print" action it should print and not leave the PDF reader open.

Actually, I have found that using ShellExecute() with "print" does leave the reader open. I couldn't find any easy solution to that. The only good thing is that, if you do multiple calls (that is, to print several different PDFs), only one instance is opened, but that doesn't solve the problem.

It was several years ago that I did this, so it's possible that things have changed with more recent versions.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Well, I didn't tried. I just remembered Word called with "print" action would really just print and then quit again, as soon as the print job is done and the spooler is fed, but I may also be wrong about that.

There would always be the option to use WMI to find a process of any exe and KillProcess, eg see
Bye, Olaf.
 
I am testing as we speak but what I have found to work is...
Code:
	* find its hwnd
DECLARE INTEGER FindWindow IN user32;
    STRING lpClassName, STRING lpWindowName

nHwnd = FindWindow(NULL, "Adobe Reader")
DECLARE INTEGER ShowWindow IN user32;
    INTEGER hwnd,;
    INTEGER nCmdShow
ShowWindow(nHwnd, 0)

DDEChan = DDEInitiate("Acroview", "Control")
=DDEExecute(DDEChan, '[CloseAllDocs()]')
=DDEEXECUTE(ddechan,'[AppExit]')

CLEAR DLLS [FindWindow, ShowWindow]

Added this to the end of the code and it now will close the program. (This is from parts of code you guys helped me with a couple years ago.)

You are right Olaf, I have abandoned the ShellExecute in favor of Run because if the Reader did not get shut down (or is not yet down) when the next process calling for the Reader fires, it hangs the application. With Run, it will continue on its happy way and use the open program.
 
I was just about to think of and mention I may have confused the ShellEecute "print" action with a similar DDE print action sent to Word or another app via DDE. It actually is closely related, as the shellexec actions are DDE actions, but you hvae some DDE functions in foxpro, too.

Glad you already found DDEEXEC in your knowledgebase, too.

Bye, Olaf.
 
I just remembered Word called with "print" action would really just print and then quit again, as soon as the print job is done and the spooler is fed, but I may also be wrong about that.

I would think that would be normal behaviour for most applications. It's just the Acrobat viewer that has this problem, as far as I know.

Pat: Interesting that it works with DDEExecute(). I wouldn't have thought of that.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top