Partager via


Creating HTML Control

4/8/2010

By using the HTML control, developers can allow their applications to display HTML pages that are either obtained locally or downloaded dynamically from the Internet or an intranet.

These pages can use all the features of Internet Explorer Mobile , including scripting, ActiveX® controls, and XML.

Note

The Windows Mobile SDK includes two Win32 samples, Browse and HTMLHost, that show how to use the HTML control.

The HTML Control API is extended to include a DTM_NAVIGATE message (shown in the following code) that causes the control to download and display a specific URL. Therefore, developers can now wrap the functionality of the mobile Internet browser directly into their applications.

Code Example

The following code example shows how to create an HTML control.

Note

To make the following code example easier to read, security checking and error handling are not included. This code example should not be used in a release configuration unless it is modified to include them.

#include <htmlctrl.h>

// Create the control. 
m_hwndHTML = CreateWindow(WC_HTML,  NULL, 
             WS_CHILD | WS_VISIBLE | HS_NOSCROLL,
             0, 0, 100, 100, m_hwndContainer,
             NULL, HINST_RESDLL, NULL);
if (m_hwndHTML == NULL)
{
    // CreateWindow failed.
    MessageBox(NULL, _T("Cannot create window."),
               _T("Warning"), MB_OK);
    exit(0);  // Replace with specific error handling.
}
if (!SendMessage(m_hwndHTML, DTM_ENABLESCRIPTING, 0, 0))
{
    // SendMessage failed.
    MessageBox(NULL, _T("Cannot send message."),
               _T("Warning"), MB_OK);
    exit(0);  // Replace with specific error handling.
}
if (!SendMessage(m_hwndHTML, DTM_ZOOMLEVEL, 0, 1))
{
    // SendMessage failed.
    MessageBox(NULL, _T("Cannot send message."),
              _T("Warning"), MB_OK);
    exit(0);  // Replace with specific error handling.
}
if (fWantToAddHtmlContent) {
    // This inserts HTML directly.
    if (!SendMessage(m_hwndHTML, DTM_ADDTEXTW, FALSE,
        (LPARAM)pszHTMLContent))
    {
        // SendMessage failed.
        MessageBox(NULL, _T("Cannot send message."),
                   _T("Warning"), MB_OK);
        exit(0);  // Replace with specific error handling.
    }
    if (!SendMessage(m_hwndHTML, DTM_ENDOFSOURCE, 0, 0))
    {
        // SendMessage failed.
        MessageBox(NULL, _T("Cannot send message."),
                   _T("Warning"), MB_OK);
        exit(0);  // Replace with specific error handling.
    }
} else {
    // This navigates to a URL (including RES:).
    if (!)
    {
        // SendMessage failed.
        MessageBox(NULL, _T("Can't send message."),
                   _T("Warning"), MB_OK);
        exit(0);  // Replace with specific error handling.
    }
}

See Also

Reference

Other Resources

Creating Windows Mobile Controls