In my previous post (Windows Mobile 6.5 Web Browser Control: Enabling Gesture support), I discussed how you can enable the built-in gesture support of the web browser control in Windows Mobile 6.5. Basically you disable selection support when creating the control, and the gesture support is enabled. But what if you want to select within the control. It seems that selection and gestures are mutually exclusive.
Yes. You can’t select and use gestures at the same time. However you can switch into ‘selection mode’ when needed. The following video shows the how this is used in the Windows Mobile messaging application:
In this video, I use gestures (flick) to scroll down the email message to locate a block of text I want to copy.
To get into ‘selection mode’, I press Menu | Make Selection. I then select the block of text, tap and hold to bring up the context menu and press Copy.
To add this functionality to your Web Browser control application, we will need access to the controls COM interface. Fortunately the ‘HTML control’ provides access to this via the DTM_BROWSERDISPATCH message. The following code demonstrates how to access the IBrowser3::put_SelectionEnabled method to enable / disable ‘selection mode’:
HRESULT SetSelectionMode(HWND hWndHtml, BOOL bSelect)
// Get the dispatch interface
SendMessage(hWndHtml, DTM_BROWSERDISPATCH , 0, (LPARAM) &pDisp);
// The put_SelectionEnabled method is included in the IBrowser3 interface
IBrowser3 * pBrowser3;
HRESULT hRes = pDisp->QueryInterface(IID_IBrowser3, (LPVOID*)&pBrowser3);
hRes = pBrowser3->put_SelectionEnabled(bSelect ? VARIANT_TRUE: VARIANT_FALSE );
So where does the IBrowser3 interface come from? This was supported in an earlier version of the browser, but has since been deprecated. However, the control is still using this interface. The interface definition is located in
C:\Program Files\Microsoft Visual Studio 9.0\SmartDevices\SDK\PocketPC2003\Include\webvw.h
I copied this over to my project directory and renamed it: webwv2.h
You can download the BrowserWithGestures sample code project (VS2008) here.
Note that the information above is not documented by Microsoft and is therefore not supported. (i.e. if you call Microsoft Developer Support you may be turned away since only documented / published APIs are supported.)