Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launching Acrobat Reader 10.0 from C#: how to minimize?

I am launching Reader 10.0 to send a PDF file to a printer from a C# program on a Win 7 system. Here's what I am doing now:

startInfo.FileName = adobeReaderPath;
string args = String.Format("/t \"{0}\" \"{1}\"", this.pdfFileName, this.printerName);
startInfo.Arguments = args;
startInfo.CreateNoWindow = true;
startInfo.ErrorDialog = false;
startInfo.UseShellExecute = false;
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
Process process = Process.Start(startInfo);

I noticed that launching Reader like this (or from command prompt) actually starts 2 AcroRd32.exe executables. Neither of them is minimized. I also tried ProcessWindowStyle.Hidden with the same result.

Is there a way of forcing Reader to start minimized?

Thanks!

like image 894
I Z Avatar asked Oct 08 '22 11:10

I Z


2 Answers

After launching the process, you can get the MainWindowHandle of it and use P/Invoke to minimize it:

[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

//..
ShowWindow(process.MainWindowHandle, 11);  //11 is ForceMinimized
like image 139
Steve Danner Avatar answered Oct 13 '22 21:10

Steve Danner


Try it with inclduding /h in your command line. This launches an Adobe Reader instance minimized to the taskbar. There is however no "nice" option to hide it completly (To my knowledge). Other than hack some unpredictable stuff with the Win32 API. The more generic approach to start some app minimized is over the API. See Steve's post.

This should do:

string args = String.Format("/h /t \"{0}\" \"{1}\"", this.pdfFileName, this.printerName);
like image 45
Alex Avatar answered Oct 13 '22 21:10

Alex