Suvarna's Weblog on Development for Mobile Devices

Software Design Engineer, Mobile Devices

Blogs

HTML Control on Windows Mobile 5.0

  • Comments 8
  • Likes

There have been a lot of queries on my weblog "Extracting Content out from HTML Windows on Pocket PC" and windows mobile 5.0. While the example code in the blog works for Pocket PC 2003, it fails for Windows Mobile 5.0.

There is a slight difference in the way we code for WM 5.0. We need to use the IPIEHTMLWindow2 interface instead of IPIEHTMLDocument2 for WM 5.0

IDispatch *pDisp;
IPIEHTMLDocument2 *pHTMLDocument;
IPIEHTMLDivElement *pHTMLDivElement;
IPIEHTMLWindow2    *pHTMLWindow; // WM 5.0
BSTR bText = SysAllocStringLen(0, 256);
WCHAR szText[256];
OLECHAR FAR* szTemp;
DISPID id;


SendMessage( DTM_DOCUMENTDISPATCH, (WPARAM)0, (LPARAM)&pIDisp );
if( NULL != pIDisp)
{
    pDisp->QueryInterface( __uuidof(IPIEHTMLDocument2), (void**)&pHTMLDocument);
}

hr = pHTMLDocument->get_parentWindow(&pHTMLWindow); //WM 5.0

szTemp= szText;
StringCchPrintf(szText, 256, "divid%ld", ID); //This is the div tag that we are looking for
pHTMLWindow->GetIDsOfNames(IID_NULL, &szTemp, 1,  LOCALE_USER_DEFAULT, &id);

VARIANT varResult;
varResult.vt = VT_DISPATCH;
VARIANT FAR *pVarResult = &varResult;
DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};


pHTMLWindow->Invoke( id, ID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, &dispparamsNoArgs, pVarResult, NULL, NULL);

if ( NULL != pVarResult->pdispVal)
{
    pVarResult->pdispVal->QueryInterface( __uuidof(IPIEHTMLDivElement), (void **) &pHTMLDivElement);
}


if ( NULL != pHTMLDivElement)
{
    pHTMLDivElement->get_innerHTML(&bText); // To get html content
    pHTMLDivElement->get_innerText(&bText); // To get text only content
}

Disclaimer : This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

Comments
  • I'm a C# .NET programmer.  Can this be done in C#?  I've done a bit of looking for the IPIEHTMLWindow2 class/Struct and can't find more than one or two references (mostly yours).  Can you give me a hand?

  • Hi,

    Is there anyway I can execute scripts on the Pocket IE browser?

    I use IHTMLWindow2's execScript to execute script in desktop internet explorer.

    For Pocket IE, I need to use IPIEHTMLWindow2 interface, which doesnt support execScript method.

    Is there any other API exposed for such purpose?

    Thanks in advance for the help

    Suudhan

  • There is no support for running scripts on the Pocket IE browser

    -Suvarna

  • What is the value of ID in the:

    StringCchPrintf(szText, 256, "divid%ld", ID);

    Thx... Alex

  • PingBack from http://vdeohplus.com/web-design-resources/html-control-on-windows-mobile-50/

  • Hi. I am not able to get this code to work. I have few questions about this line

    SendMessage( DTM_DOCUMENTDISPATCH, (WPARAM)0, (LPARAM)&pIDisp );

    I guess firstly the first parameter needs to be an HWND. I am writing a BHO to hit the submit button on IE page. For this I need to get handle to the form of that page and then do a submit. I passed the HWND of that page to the above SendMessage line, but it gives an "Children could not be evaluated" error. Please help

  • Hi Suvarna,

    Do you know how I can retrieve a IWebBrowser2 intreface ?

    I tried the following code but it doesn't work :

    IDispatch *pDisp = 0;

    IWebBrowser2* pWB2 = 0;

    m_omaHtmlWnd.GetBrowserDispatch(&pDisp);

    HRESULT hr = pDisp->QueryInterface(IID_IWebBrowser2, (void**)&pWB2);

    I get a E_NOINTERFACE ...

    Actually I am developping in WTL and using a CHTmlCtrl derived control. What I would like to do is to enable what is called "Desktop mode" in PocketIE.

    Actually webpage are displayed with an horizontal scrollbar and I thought that I could do it with the

    IWebBrowser2 interface.

  • PingBack from http://www.keyongtech.com/1802764-ipiehtmldocument2-interface-needed

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment