Programming The mshtml Web browser control with C ++

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.