This article introduces how to use mshtml to implement browser instances in C ++.
Http://www.adp-gmbh.ch/win/misc/mshtml/
It is possible to render HTML in an ordinary windows program
Mshtml. This makes it possible to have a web look and feel in a program. because I think this is quite interesting, I decided to write some C ++ classes that make it possible to use mshtml in an easy way. I found some ideas on how to do that with embed an HTML control in your own window using plain C. test programthis test programm displays a simple HTML document in a window. the HTML document consists of three links. these links are fully operational. mshtmltest. CPP
#include <windows.h>#include "HTMLWindow.h"int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE /*unused__*/, LPSTR /*lpszCmdLine*/, int /*nCmdShow*/) { HTMLWindow* html_window = new HTMLWindow ( // Parameter html_or_url: "Parameter title "MSHTMLTest", hInstance, false // indicates: this not an url, but html ); MSG msg; while (GetMessage(&msg, 0, 0, 0)) { TranslateMessage(&msg); if (msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST) { ::SendMessage(html_window->hwnd_, msg.message, msg.wParam, msg.lParam); } DispatchMessage(&msg); } return 0;}
Displaying an HTML documentthe following program displayes an URL. So, it can be called like:
DisplayHTML.exe www.your-favorite-url.zzz
If the URL happens to be an HTML file on the harddisk, call it like so:
DisplayHTML.exe file://c:/path/to/your/document.html
Displayhtml. cpp
#include <windows.h>#include "HTMLWindow.h"int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) { if (__argc < 2) { ::MessageBox(0, "DisplayHTML.exe html-document", "Specify HTML document to be displayed", 0); return -1; } HTMLWindow* html_window = new HTMLWindow ( __argv[1], "DisplayHTML", hInstance, true // it is an url ); MSG msg; while (GetMessage(&msg, 0, 0, 0)) { TranslateMessage(&msg); if (msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST) { ::SendMessage(html_window->hwnd_, msg.message, msg.wParam, msg.lParam); } DispatchMessage(&msg); } return 0;}
Downloading mshtmltestthe sources (including makefile) as well as the exes can be downloaded here: mshtmltest. I compiled