In some special applications, we would like to have a similar function of IE modules, customized their own functions.
The HTML control now opens its arms to us. Oddly enough, it does not fully support the WAP protocol. It seems that IE has done its own analysis.
First, we want to register the controls. Include the Htmlctrl.h, call the Inithtmlcontrol () function, and the argument inside is the application handle. The following code is used in MFC:
VERIFY (Inithtmlcontrol (AfxGetInstanceHandle ()));
DWORD dwstyle = Ws_child | ws_visible | Ws_clipsiblings;
RECT RECT;
GetClientRect (&rect);
M_hhtmlwnd =:: CreateWindow (Displayclass,
Null
Dwstyle,
Rect.left,
Rect.top,
Rect.right,
Rect.bottom,
M_hwnd,
0,
:: AfxGetInstanceHandle (),
NULL);
:: SetWindowLong (M_hhtmlwnd, gwl_id, 12321);
:: SetFocus (M_hhtmlwnd);
:: SendMessage (M_hhtmlwnd, Wm_settext, 0, (LPARAM) (LPCTSTR) _t (""));
Here, M_hhtmlwnd is an HWND-type member variable for a dialog.
Then, in the dialog WindowProc function, use the following method:
Switch (message)
{
Case WM_NOTIFY:
{
WCHAR wszurl[1000] = {0};
nm_htmlview* Pnmhtmlview = (nm_htmlview*) LParam;
Switch (Pnmhtmlview->hdr.code)
{
Case nm_hotspot://Click URL
Break
Case nm_documentcomplete://Document Display end
Break
Case nm_inline_image://Display Picture
return TRUE;
}
}
Break
Default
Break
}
In the above several key points, Nm_hotspot is the user clicks the webpage link, through the visit pnmhtmlview->sztarget may obtain the webpage content. SendMessage can assign the resulting content to the control, which resolves its own page elements. If there is a picture link, the Nm_inline_image action will be triggered. At this time also need to visit pnmhtmlview->sztarget to get pictures. If you get the contents of the picture, you can use the following code to display:
Inlineimageinfo Imageinfo;
Imageinfo.dwcookie = pnmhtmlview->dwcookie;
Imageinfo.bownbitmap = FALSE;
IMAGEINFO.HBM = Hbitmap;
BITMAP MInfo;
GetObject (hbitmap, sizeof (BITMAP), (LPBYTE) &minfo);
Imageinfo.iorigwidth = Minfo.bmwidth;
Imageinfo.iorigheight = Minfo.bmheight;
:: SendMessage (Pnmhtmlview->hdr.hwndfrom, Dtm_setimage, 0, (LPARAM) (inlineimageinfo*) &imageinfo);
The above code hbitmap the picture bitmap handle.
When I was working on the picture, the problem was. After using the Shloadimagefile function, you use the DeleteObject function to free the handle memory. Otherwise there will be a memory leak. MSDN did not mention this phenomenon.
If you do not get the picture content, you want to display a fork in the appropriate location of the page, the Dtm_setimage parameter should be changed to Dtm_imagefail.
It is worth noting that if we process nm_hotspot or nm_inline_image messages, we need to return ture or FALSE, otherwise the control itself will be processed again.