The. NET Compact Framework obtains htmldocument through managed Win32 code

Source: Internet
Author: User
Tags compact win32

Problem Introduction:

A friend of the project experience of CF must often encounter the problem of background docking with BS, HTML in the BS system has a unique condition, he can be used directly as an interface display, and can be the C # code and JavaScript operations, So in some applications the BS system may take the design of storing HTML forms in the database, for example, some form visual design controls (table Designer) generate HTML, and the benefit of storing HTML directly is to bypass the complexity of parsing the HTML DOM, But in front of the mobile application with the docking of the problem, when my. NET CF program read to the fields containing HTML is very embarrassing, the use of regular expressions to parse HTML generation WINFOM interface is obviously impractical, however. NET CF seems to provide us with only one way, because if you display HTML directly with the Webbroswer (WB) control, it is likely that the user experience is bad because the HTML specs don't fit the PDA screen, and a common problem is that HTML The form is wider than the mobile device screen, and the WB has a horizontal scroll bar, which is not the key to the problem, the key is that you give the HTML to the WB control after you have no control over the The only and HTML interaction that the WebBrowser class provides us with is a property called DocumentText, unfortunately the property is setonly, which means that only the set accessor is available, so it is impossible to get the values entered in the form. This problem does not exist in the full Framework (FF) because the Webbroswer class in FF provides us with the document property, which returns an HTML DOM structure of type HTMLDocument, With this property, you can easily complete HTML interaction tasks. My idea for the above problem is to use the HTML DOM model to interact with HTML, If you have used the Webbroswer.document property to manipulate HTML, you should know that HTMLDocument is simply an object that encapsulates the COM interface IHTMLDocument2, and that most of his functionality is provided in COM, so how does this interface in CF be introduced? This is the problem to be solved in this article.

Way to solve the problem:

Solving these problems does not require the technology to build atomic bombs, but before you read the following, you need to have the basics of Windows COM and the P/invoke in the. NET Compact framework, where you don't need to know the data layout, but at least you need to understand C + + Char* is marshaled as a string, but as a CF developer, I recommend that you study P/invoke, if you do not have the knowledge, then I recommend that you read the following article first:

Http://msdn.microsoft.com/en-us/library/aa446529.aspx

HTTP://MSDN.MICROSOFT.COM/EN-US/LIBRARY/K3F1T3CT (vs.80). aspx

Http://msdn.microsoft.com/en-us/library/aa446497.aspx

When you have mastered this knowledge then congratulate you, you may not need to read all my articles will be able to do what we want to do.

Since the WebBrowser controls in CF do not provide our access to HTMLDocument, let's look at the HTML control in EVC (hereinafter referred to as HC).

I started browsing through a lot of Windows Mobile SDK documents, and even the HTML control API messages topic in the Help document could not find any message to get the HTML inside HC, and finally in a foreign C + + The development forum found some clues, in fact, in the mobile API can actually access the HTMLDocument model, there is such a message can return the HC HTML Document object, that is Dtm_documentdispatch, The interesting thing is that we enter dtm_documentdispatch in the SDK documentation to find the help page with links to the HTML control API messages topics, but the HTML control API Messages Help topic did not introduce Dtm_documentdispatch message, let's look at the description of Dtm_documentdispatch:

The Dtm_documentdispatch message was sent by a application to the HTML Viewer control to request a reference to its IDISPA Tch interface.

Syntax

Dtm_documentdispatch
wParam = 0;
LParam = (LParam) (idispatch*) Ppdisp;

Parameterswparam not used. Pdisp [out] Reference to the HTML Viewer control ' IDispatch interface. Return Values

Returns The HTML Viewer control ' s IDispatch pointer. Use it to call QueryInterface (Iid_ipiehtmldocument, (void**) &phtmldocument) to retrieve the HTML viewer control ' s Ipie HTMLDocument interface.

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.