Share via


Creating HTML Control

Send Feedback

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 Extensible Markup Language (XML).

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

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

Code Example

The following code example demonstrates 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 has been 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("Can't 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("Can't 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("Can't 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("Can't 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("Can't send message."),
                   _T("Warning"), MB_OK);
        exit(0);  // Replace with specific error handling.
    }
} else {
    // This navigates to a URL (including RES:).
    if (!SendMessage(m_hwndHTML, DTM_NAVIGATE, 0, 
        (LPARAM)m_sbi.pszContent))
    {
        // SendMessage failed.
        MessageBox(NULL, _T("Can't send message."),
                   _T("Warning"), MB_OK);
        exit(0);  // Replace with specific error handling.
    }
}

See Also

Creating Windows Mobile Controls

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.