Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

Environment: VC++ 7.0

Sometimes you have to print HTML files from your Visual C++ program. If Microsoft's Internet Explorer is installed, this can be done easily by just calling ShellExecute(hwnd, "print", "my_file.html", 0, 0, SW_SHOW).

Unfortunately, this way you don't have any control over the header/footer lines that the Web browser prints.

Knowledge base article Q236777 (HOWTO: Change Print Settings for Internet Explorer and WebBrowser Control Programmatically) shows some "undocumented" ways of accessing header/footer values using C++ code. Based on this article, "print_html" has been implemented. By using this module, it is possible to print HTML pages without any header/footer lines (provided that Internet Explorer is installed as the default Internet browser).

Just say #include "print_html.h" at the beginning of your cpp file and add "print_html.cpp" to your workspace. Now it is possible to print HTML files with the following lines of code:

C_PrintHtml ph;

You can find "print_html.cpp" and "print_html.h" (as well as a simple example of how to use the module) in the attached zip archive. I used VC++ 7.0 to create the example. The module has been tested with Internet Explorer 6 on Windows NT4 SP6a, Windows 2000 SP2, and Windows XP Professional.

Best regards,
Tilman Kuepper (kuepper@xgraphic.de)


Download source - 28 Kb


  • Printing to network printer

    Posted by Legacy on 12/11/2003 08:00am

    Originally posted by: waqar

    Is there a way to print the html files to the network printer configured for the system.

  • Another solution for user dialog during priting

    Posted by Legacy on 11/18/2003 08:00am

    Originally posted by: Yaron Shkop

    The default printto verb for html files on windows is ofcourse IE.
    IE6 however invoke a pop up dialog for the user during printto opperation. It's nice as long as the application is not a server one.. (no UI).
    It took me a while to understand that this issue is a browser implementation and I was convinsed so after reading many posts about this in google discussion groups searches.
    Most of the people by the way encountered the problem while developing FAX servers using MS FAX services (COM).
    The solution is ofcourse to use other browser.
    Netscape� Communicator 4.79 is the one that does the job silently as expected (NOT netscape 7.02...), it has to be set as the default browser on the machine.
    If you don't want it to be the default browser set the Registry- html files printto only: (HKLM\Software\Classes\htmlfile\shell\printto\) to the values that netscape set them to when it's the default browser. (That way only the printto operation is done through netscape).
    The other solution is to use MS-Word as I've already described in my previous post.

  • User Dialogs Solution

    Posted by Legacy on 11/16/2003 08:00am

    Originally posted by: Yaron Shkop

    Sorry, but your solution doesn't solve the problem of print dialogs.
    The idea was to prevent user dialogs from appearing for server based applications. (No UI!)
    The solution is to edit the printto verb inside "Assaociated File Types" to a program that can do it without dialogs.
    This is not a perfect solution since the program is MS-WORD.
    If you have another software for coverting\printing html without dialogs please add a comment. (A freeware or a built in program in Windows!)


    Application used to ... :
    "C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE" /n /dde %1 %2

    DDE Message:
    [REM _DDE_Minimize][FileOpen("%1")][FilePrintSetup "%2 on p",.DoNotSetAsSysDefault=1][FilePrint 0][DocClose 2][FilePrintSetup ""]


    DDE Application not running:
    [FileOpen("%1")][FilePrintSetup "%2 on p",.DoNotSetAsSysDefault=1][FilePrint 0][FileExit 2]


  • Batch Print - How can i send a html file to the printer without any print dialog

    Posted by Legacy on 07/07/2003 07:00am

    Originally posted by: simon soosai

    I am trying to send more than 1 files straight to the printer from my html page. How would i do that?

  • This method does not work with IE 6.0

    Posted by Legacy on 05/30/2003 07:00am

    Originally posted by: Kyselgov E.N.

    This method does not work with IE 6.0.
    This method based on registry IE settings changing.
    It modify header and footer registry settings, run IE, wait for IE exit, and restore settings back.
    !!! BUT !!! IE 6.0 (and maybe IE 5.5) prints in background (hidden) process. When you run IE 6.0 process for printing HTML page and if you will think that IE 6.0 process completion is signified printing completion than you will MISTAKEN.
    Where is the error?
    Look at process.

    1. Our program change settings.
    2. Our program runs IE 6.0 main process for printing.
    3. IE 6.0 main process runs hidden printing process.
    4. IE 6.0 main process exits.
    5. IE 6.0 hidden process shows print dialog (waits OK).
    6. Our program waits until IE 6.0 main process exits. <-- This is ERROR!
    7. Our program restores settings.
    8. IE 6.0 hidden process read settings (it's restored (not our) settings).
    9. IE 6.0 hidden process prints.
    10. IE 6.0 hidden process exits.

    In 6. our program must wait IE 6.0 hidden process completion but not main process completion!
    !!! BUT !!! There is not way for taking IE 6.0 hidden process handle.

  • Resource leak (handle must be closed)

    Posted by Legacy on 05/29/2003 07:00am

    Originally posted by: Kyselgov E.N.

    Function C_PrintHtml::ExecIE() not close process handle - this is dangerous resource leak.
    Add this code after WaitForSingleObject():

  • BUG...

    Posted by Legacy on 04/19/2003 07:00am

    Originally posted by: Xig

    There is a bug in the code. you need to add this to print_html.cpp:

    WaitForSingleObject(printingResource, INFINITE);

    otherwise, if you close your application while a doc is printing (or in print-setup for example) the app may crash and/or corrupt the registry!


  • Thank god for your soul.

    Posted by Legacy on 04/18/2003 07:00am

    Originally posted by: Fantom Code


    I've been trying to figure this out. Thanks so much for this useful bit of code. You're on the top of my favorite people list as of now. HAH!

    Thanks again,

  • What about rights?

    Posted by Legacy on 02/04/2003 08:00am

    Originally posted by: Piotr

    I think this solution is good only for Administrator.
    What about writing to Registry by user on NT/2000/XP?

  • Multitasking problem

    Posted by Legacy on 12/11/2002 08:00am

    Originally posted by: Erik Rydgren

    If you have more then one instance of this class printing at the same time then you will probably loose the original settings for header and footer.

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date