Utilizing Pocket IE Functionality in Mobile Applications

Most PDAs come with prewired Internet Explorer. Its versions may be different, or a vendor may decide that its device doesn't need it al all. But, when it does exist, it's just natural to use its capabilities, isn't it? In this article, we will discuss how to do it on different types of PDA and WinCE flavors.

Using HtlmControl

Even on very old devices with OS Palm Size PC 2.11, you have htmlview.dll (and respectively, htmlview.lib). This stuff is continuing to appear on all Pocket PC devices, such as PPC 2000, PPC 2002, and so forth. Well, not all devices with 1/4 VGA screens are from the "Pocket PC" family, but we will discuss them later in this article. Coming back to HtmlControl, below are the steps you need to complete to obtain browser functionality:

  • Include htmlctrl.h to your project
  • Initialize the HTML control by calling the InitHTMLControl function
  • Create a window for the HTML control by calling the CreateWindow function with DISPLAYNAME as a window class name parameter
  • Handle WM_NOTIFY messages for NM_HOTSPOT and NM_INLINE_IMAGE codes
  • Link your application with htmlview.lib

As you may guess, there is nothing too complicated here. The stuff that is not mentioned above is downloading data from Web sites according to links and displaying images on the screen. And besides, don't expect any support for JScript, frames, and analogous features. HTML Control provides just basic browser functionality. All the rest is up to you.

But, that's enough theory. Let's take a look at a simple code sample to illustrate HTML Control usage. Below are parts of a sample project. For simplicity, the HTML Control object is inherited from CStatic class.

// Initialize HTML Control
BOOL CHtmlCtrlApp::InitInstance()
{
     InitHTMLControl(AfxGetInstanceHandle());
     CHtmlCtrlDlg dlg;
     m_pMainWnd    = &dlg;
     int nResponse = dlg.DoModal();
     return FALSE;
}

// Create Html Control Window and make some initialization
void CHtmlView::CreateHtmlWindow(CRect& rect)
{
     DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS;
     CString sInfo;

     m_hwndHtml = ::CreateWindow (DISPLAYCLASS,//DISPLAYCLASS,
                                  NULL,
                                  dwStyle,
                                  rect.left,
                                  rect.top,
                                  rect.right,
                                  rect.bottom,
                                  m_hWnd,
                                  0,
                                  AfxGetInstanceHandle(),
                                  NULL);

     ::SetWindowLong(m_hwndHtml,GWL_ID,12321);
     ::SetFocus (m_hwndHtml);
     ::SendMessage(m_hwndHtml,WM_SETTEXT,0,(LPARAM)(LPCTSTR)_T(""));
}
// Handle notification messages
LRESULT CHtmlView::WindowProc(UINT message, WPARAM wParam,
                              LPARAM lParam)
{
   switch(message)
   {
   case WM_NOTIFY:
      NM_HTMLVIEW * pnmHTML = (NM_HTMLVIEW *) lParam;
      LPNMHDR pnmh = (LPNMHDR) &(pnmHTML->hdr);

      switch(pnmh->code)

      {
      case NM_HOTSPOT:
         OnLink(pnmHTML->szTarget);
      break;
      case NM_INLINE_IMAGE:
           OnInlineImage(pnmHTML->szTarget,pnmHTML->dwCookie);
      }
   }

   return CStatic::WindowProc(message, wParam, lParam);
}

// Download html page from selected target site
void CHtmlView::OnLink(const CString &strHref)
{
   TCHAR *szHtml = NULL;
   
   // Here you actually put the code to download HTML page into
   // szHtml
   ...
   
   // And finally command HTML Control to show it
   ::SendMessage(m_hwndHtml, WM_SETTEXT, 0, (LPARAM)(LPCTSTR)NULL);
   ::SendMessage(m_hwndHtml, DTM_ADDTEXTW, FALSE,
                (LPARAM)(LPCTSTR)szHtml);
   ::SendMessage(m_hwndHtml, DTM_ENDOFSOURCE, 0, 0);
}

// Loading images
void CHtmlView::OnInlineImage(const CString &strHref, DWORD dwCookie)
{
   // Here handle image loading
   ...
   // Set image if all is OK
   if ( bImageLoadedOK )
   {
   INLINEIMAGEINFO imageInfo;
   imageInfo.dwCookie    = dwCookieValue;
   imageInfo.bOwnBitmap  = FALSE;
   imageInfo.hbm         = (HBITMAP)(*pBitmap);
   CSize size            = pBitmap->GetBitmapDimension();
   imageInfo.iOrigWidth  = size.cx;
   imageInfo.iOrigHeight = size.cy;
   ::SendMessage(m_hwndHtml, DTM_SETIMAGE, 0, (LPARAM)
                (INLINEIMAGEINFO*)&imageInfo);
   }
   // Otherwise, send failure message
   else
      ::SendMessage(m_hwndHtml, DTM_IMAGEFAIL, 0, (LPARAM)
                   (LPINLINEIMAGEINFO)dwCookieValue);
}

...
// And finally ...
BOOL CHtmlCtrlDlg::OnInitDialog()
{
   ...
   // m_htmlView is pointer to CHtmlView class
   if (m_htmlView->SubclassDlgItem(IDC_HTMLVIEW,this))
   {
      // do some initialization if needed
   }
   ...
}

Well, the code above initiates and creates CHtmlView object, and creates HtmlView window. By calling the SubclassDlgItem function, it's connected to the Static control's window. Thus, that's a convenient way to use a placeholder in the Resource editor. After a HTML Control window is created, it is able to display HTML pages. Also, it receives notifications when the user taps on links or some image should be shown. All details regarding downloading pages or images are ommited in this sample, so you may implement it as is more comfortable for you. For images, you may think about some kind of cache, to avoid odd network traffic for the same data. The following picture presents the resulting output of this sample:

IWebBrowser2 interface

For PDA devices running Windows CE.NET (not from Pocket PC family), e.g. Fujitsu iPAD, there is an opportunity to use the IWebBrowser2 interface. That's good news because this interface takes care of a lot of things. If you have used it on a PC, you'll feel pretty comfortable here. A code snippet below shows how to create an instance of IWebBrowser2:

...
#include <exdisp.h>
// an instance of IWebBrowser2
IWebBrowser2 *m_pBrowserApp;
...
void CBrowser::Init(CRect rect,CWnd *pWnd)
{
   //Create the control window
   if(!CreateControl(CLSID_WebBrowser, NULL, WS_VISIBLE|WS_CHILD,
      rect,pWnd,AFX_IDW_PANE_FIRST))
   {
      m_pBrowserApp=NULL;
      DestroyWindow();
   }
   LPUNKNOWN lpUnk = GetControlUnknown();
   HRESULT hr = lpUnk->QueryInterface(IID_IWebBrowser2, (void**)
           &m_pBrowserApp);
   if(!SUCCEEDED(hr))
   {
      m_pBrowserApp = NULL;
      DestroyWindow();
   }
}

With this interface, you get most of a desktop browser's functionality. "Most"—because of regular WinCE restrictions. If you need to capture events from a browser, you may implement the DWebBrowserEvents2 interface. There are a lot of articles on the Web about IWebBrowser-related stuff, so I will not enter into these issues. In any case, you life is easy enough in such an environment.

Conclusions

Using either HTML Control or IWebBrowser2, you may make your applications much more powerful and attracive. Have fun!

About the Author

Alex Gusev started to play with mainframes at the end of the 1980s, using Pascal and REXX, but soon switched to C/C++ and Java on different platforms. When mobile PDAs seriously rose their heads in the IT market, Alex did it too. Now, he works at an international retail software company as a team leader of the Mobile R department, making programmers' lives in the mobile jungles a little bit simpler.



Comments

  • Summary piece of writing uncovers the unquestionable info regarding chloe as well as how it may have a bearing on your company.

    Posted by emeseesip on 05/06/2013 08:43pm

    One Of The Most Detailed gucci Guide You Ever Read Otherwise Your Money Back [url=http://www.guccija.biz/]グッチ キーケース[/url] Omg, awesome service. You got to have a look at adidas immediately while it's still available for sale ! ! [url=http://www.guccija.biz/]グッチ 財布 メンズ[/url] adidas can help all of us by simply integrating several distinctive functions and functions. Its a unvaluable thing for all enthusiast of nike. [url=http://www.guccija.biz/]グッチ トートバッグ[/url] Third party report displays Unique completely new stuff regarding nike that no one is speaking about. [url=http://www.chanelja.biz/]シャネル 財布[/url] Exactly why no company is bringing up nike and therefore precisely what one should accomplish straight away. [url=http://www.chanelja.biz/]chanel バッグ[/url] All new questions on gucci addressed and in addition the reason why you ought to browse through each term in this study. [url=http://www.chanelja.biz/]財布 chanel[/url] Fundamental principles of the nike that you can profit by starting today.[url=http://www.nikeja.biz/]ナイキ[/url] Strategies about how to discover all sorts of things there is to know regarding nike in three basic steps.

    Reply
  • Rare blog post supplies the important points over mizuno which experts claim a few buyers know of.

    Posted by icoppyapedcap on 04/25/2013 07:07am

    JlqNfwQqvLtd [url=http://www.nikeyasuijp.com/]ナイキスニーカー[/url]NawBrlInoIcj [url=http://www.nikeyasuijp.com/nike-air-force1エアフォース1-c-14.html]ナイキ フリ[/url]ColVsaHevKkx [url=http://www.nikeyasuijp.com/nike-air-maxエアマックス-c-12.html]ナイキ エアマックス[/url]QagSxjYzpArd [url=http://www.nikeyasuijp.com/nike-air-jordanエア-ジョーダン-c-13.html]ナイキランニング[/url]MfuPfePgoOey

    Reply
  • htmlview.dll

    Posted by pwraustin on 06/01/2006 04:15pm

    Hi I'm using .net Compact Framework and I wonder if you maybe can help me. I'm doing something like the example below, but on the OnLink method I tried to do nothing, to see if the navigation to the href doesn't get place. But still navigating and loading the page under href URL. Do you know how prevent to navigate or meybe stop it. Thanks

    Reply
  • Can I refere to html elements from the control ?

    Posted by piyushc on 07/08/2005 05:33am

    Hi, Can I refere to the html controls from the HTML Control that you have mentioned ? I want to get the values entered by the user in these cotntrols. Thanks and Regards, Piyush

    • Re: Can I refere to html elements from the control ?

      Posted by alex_gusev on 07/10/2005 06:18am

      Hi, Html Control described in this article has no options to access to document controls. You can try to get it via interfaces defined in webvw.h header file in SDK

      Reply
    Reply
  • wheres the line to create the htmlviewer ?

    Posted by risnandar on 01/25/2005 01:04am

    wheres the line to create the htmlviewer ? i cannot find that which cause an ASSERT when attach window

    • RE: wheres the line to create the htmlviewer ?

      Posted by alex_gusev on 01/25/2005 01:29am

      CreateHtmlWindow function has CreateWindow call with DISPLAYCLASS as window class name. Besides, InitHtmlControl is called from InitInstance method

      Reply
    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • It's not unusual for a company to use a variety of formal and informal file-sharing methods. Many methods are fraught with significant operational, financial, and legal risks in addition to other potentially negative business consequences. Strategic managed file transfer (MFT) software and services help connect the business "dots" between the various ad hoc and more systematic ways that files are moved. Read this white paper to learn how the right MFT solution, can bring order, structure, and, importantly, …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds