ShellEjecutar, "Imprimir"

I am using ShellExecute through C and that seem's work OK except one issue.

ShellExecute(NULL, "print", "C:\\index.html", NULL, NULL, SW_HIDE);

With this I would like to get print dialog for press OK for start printing but instead of that MS Word opens with file C:\index.html loaded.

How to get print functionality on html files with ShellExecute?

If is important to note, IE is not my default internet browser.

preguntado el 17 de mayo de 13 a las 09:05

1 Respuestas

You are relying on the shell's associations to print the file, but that's a terribly brittle approach. If you right click on the file and select Imprimir you'll observe the same behaviour as your call to ShellExecute.

Entonces, si quieres usar ShellExecute con el Imprimir verb you will need to change your machine's configuration. You need to make sure that the machine's associations are configured to handle the Imprimir verb on a .html file in a way that suits you. You could do that for your machine but you cannot expect to do it for other people's machines.

Instead you could run this command to be sure that the HTML file will be printed:

rundll32.exe %windir%\system32\mshtml.dll,PrintHTML "C:\index.html"

You can translate that readily into a ShellExecute llamada.

contestado el 17 de mayo de 13 a las 09:05

That sound's very good. Please help in translation to ShellExecute. My approach: ShellExecute(NULL, "open", "rundll32.exe %windir%\system32\mshtml.dll,PrintHTML", myfile, NULL, SW_NORMAL); seems don't work at all. - Vino también

You'll need to substitute the actual system directory because ShellExecute won't expand the path for you. And it seems that the filename needs to be quoted. So, this will work: ShellExecute(0, NULL, "rundll32.exe", "C:\\windows\\system32\\mshtml.dll,PrintHTML \"C:\\index.html\"", NULL, SW_NORMAL); - David Heffernan

Thank you David, works excellent, just as expected! sprintf(sfile, "%s%s%s%s", "mshtml.dll,PrintHTML \"", cwd, afile, "\""); ShellExecute(NULL, "open", "rundll32.exe", sfile, NULL, SW_SHOWNORMAL); - Vino también

Is here any chance to get popped dialog in center of screen? - Vino también

Well, not easily. What you would need to do would be install a CBT_HOOK, and use that to detect that the dialog was about to show. And then you could re-position it. - David Heffernan

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.