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 areProgramHandle. BelowCodeUse 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:
{
Outputdebugstring (pnmhtmlview-> sztarget );
Break;
}

Case nm_inline_image:
{
Outputdebugstring (text ("nm_inline_image \ r \ n "));
Break;
}

Case nm_inline_sound:
{
Outputdebugstring (text ("nm_inline_sound \ r \ n "));
Break;
}

Case nm_title:
{
Outputdebugstring (text ("nm_title \ r \ n "));
Break;
}

Case nm_meta:
{
Outputdebugstring (text ("nm_meta \ r \ n "));
Break;
}

Case nm_base:
{
Outputdebugstring (text ("nm_base \ r \ n "));
Break;
}

Case nm_contextmenu:
{
Outputdebugstring (text ("nm_contextmenu \ r \ n "));
Break;
}

Case nm_inline_xml:
{
Outputdebugstring (text ("nm_inline_xml \ r \ n "));
Break;
}

Case nm_beforenavigate:
{
Outputdebugstring (text ("nm_beforenavigate \ r \ n "));
Break;
}

Case nm_documentcomplete:
{
Outputdebugstring (text ("nm_documentcomplete \ r \ n "));
Break;
}

Case nm_navigatecomplete:
{
Outputdebugstring (text ("nm_navigatecomplete \ r \ n "));
Break;
}

Case nm_titlechange:
{
Outputdebugstring (text ("nm_titlechange \ r \ n "));
Break;
}

Default:
{
Assert (false );
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.

About nm_htmlview struct

Typedef struct tagnm_htmlview {
Nmhdr;
Lpstr sztarget;
Lpstr szdata;
DWORD dwcookie;
} Nm_htmlview;

The first parameter in the function is a structure of the nmhdr type.

Nmhdr Structure

Contains information about a notification message.

Syntax

Typedef struct tagnmhdr {hwnd hwndfrom; uint_ptr idfrom; uint code;} nmhdr;

Members

Hwndfrom
A window handle to the control sending the message.
Idfrom
An identifier of the control sending the message.
Code
A notification code. This member can be one of the common notification codes (see notifications under general control reference), or it can be a control-specific notification code.

 

 

 

 

Related Article

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.