Click to See Complete Forum and Search --> : Print Dialog hidden behind application on ShellexecuteEx


mahoneyk
March 21st, 2006, 02:53 PM
I need to print an html file from within my application. I am using ShellexecuteEx with the "print" verb and the html file passed to it. The problem is that there is a slight delay between the function being called, and the print properties dialog being displayed.
As a result, if the user clicks anywhere in this time, the main window will regain focus, and the print dialog will appear behind the applications window. Since the print properties dialog window doesn't appear in the task bar it appears to the user as if nothing has happened. The print dialog is only noticed when the application is closed or is the window is moved.

Is there anything I can do about this?

The code I have used is as follows:


SHELLEXECUTEINFO ShExecInfo;

ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = NULL;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = "print";
ShExecInfo.lpFile = "bob\\readme.htm"; // a fully qualified path
ShExecInfo.lpParameters = NULL;
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_MAXIMIZE;
ShExecInfo.hInstApp = NULL;

ShellExecuteEx(&ShExecInfo);


I have also tried to use WaitForSingleObject() on the SHELLEXECUTEINFO.hProcess, hoping that this would prevent the function from returning until either the print dialog was shown, or until the same was closed:


as above except:
...
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
...

if((ShellExecuteEx(&ShExecInfo)) && (ShExecInfo.hProcess != NULL)){
WaitForSingleObject(ShExecInfo.hProcess, INFINITE);
}


WaitForSingleObject returns pretty much immediately - certainly before the print dialog appears.


Any help on this matter would be greatly appreciated.

VladimirF
March 21st, 2006, 04:58 PM
I would try to set ShExecInfo.hwnd to your window's handle...

mahoneyk
March 21st, 2006, 07:37 PM
Ok.
I tried that, and it hasn't changed anything.

What I've done is changed the function so that it minimizes the application window when the file is printed. Hardly ideal, but at least it works. I'd still be interested in hearing a more elegant solution though.