Use HTML controls in Windows Mobile

Source: Internet
Author: User

In some special applications, we really want a module similar to the IE function to customize our own functions.

The HTML control is open to us now. It is slightly strange that it does not fully support the WAP protocol. It seems that IE has made its own parsing.

First, register the control. Include htmlctrl. h and call the inithtmlcontrol () function. The parameters in the function are application handles. Use the following code in MFC:

Verify (inithtmlcontrol (AfxGetInstanceHandle ()));
 
DWORD dwstyle = ws_child | ws_visible | ws_clipsiblings;
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 (""));

M_hhtmlwnd is the hwnd member variable of a dialog.

Then, use the following method in the windowproc function of dialog:

Switch (Message)
{
Case wm_notify:
{
Wchar wszurl [1000] = {0 };
Nm_htmlview * pnmhtmlview = (nm_htmlview *) lparam;

Switch (pnmhtmlview-> HDR. Code)
{
Case nm_hotspot: // click the URL
Break;

Case nm_documentcomplete: // The End Of The document display
Break;

Case nm_inline_image: // display image
Return true;
}
}
Break;

Default:
Break;
}

In the preceding key points, nm_hotspot allows you to click the webpage link and access pnmhtmlview> sztarget to obtain the webpage content. Sendmessage can assign the obtained content to the control, and the control will parse the webpage elements by itself. If an image link exists, the nm_inline_image action is triggered. In this case, you also need to access pnmhtmlview-> sztarget to get the image. If you get the image content, you can use the following code to display it:

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 );

In the above Code, hbitmap is the image bitmap handle.

The problem I encountered when processing images is. After using the shloadimagefile function, you must use the deleteobject function to release the handle memory. Otherwise, memory leakage may occur. Msdn does not mention this phenomenon.

If you do not get the image content and want to display a cross at the corresponding position on the webpage, The dtm_setimage parameter should be changed to dtm_imagefail.

It is worth noting that if we process the message nm_hotspot or nm_inline_image, we need to return true or false, otherwise the control will process it again.

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.