屏蔽WebBrowser控件的手势

kagula@2014-12-20

Test environment is win8.1-64bits+VS2010SP1

Step1:Prepare

Ccat8637_priceComparingSystemDlg *g_pDlg = NULL;

std::map<HWND,WNDPROC> m_mapPROC;

void Ccat8637_priceComparingSystemDlg::DocumentCompleteExplorer1(LPDISPATCH pDisp, VARIANT* URL)
{
	InitWebBrowserHook();
}

Step2:subclass

void Ccat8637_priceComparingSystemDlg::InitWebBrowserHook()
{
	static bool bInit = false;

	if (bInit==false)
	{
		CWnd *pWnd = &m_webBrowser;
		// just get instance of webbrowsrer control
		while (pWnd = pWnd->GetWindow(GW_CHILD))
			// and find specific window between children
		{
			CString strClass;
			GetClassName(pWnd->m_hWnd, strClass.GetBuffer(64), 64);
			strClass.ReleaseBuffer();
			if (strClass == _T("Internet Explorer_Server") )
			{
				//SetWindowLongPtr(pWnd->GetSafeHwnd(), GWL_USERDATA, (LONG_PTR)this);
				m_mapPROC[pWnd->GetSafeHwnd()] = (WNDPROC)(SetWindowLongPtr(pWnd->GetSafeHwnd(), GWL_WNDPROC, (LONG_PTR)WebBrowserProc));
				bInit = true;
				break;
			}
		}//end while
	}
}


Step3:Window procedure

static LRESULT CALLBACK WebBrowserProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	bool bHandled = false;
	if (g_pDlg!=NULL)
	{
		if (g_pDlg->m_mapPROC.find(hwnd)!=g_pDlg->m_mapPROC.end())
		{
			if (g_pDlg->m_mapPROC[hwnd]!=NULL)
			{
				if (uMsg==WM_GESTURE)
				{
					GESTUREINFO gi;  

					ZeroMemory(&gi, sizeof(GESTUREINFO));

					gi.cbSize = sizeof(GESTUREINFO);

					BOOL bResult  = GetGestureInfo((HGESTUREINFO)lParam, &gi);

					if (bResult){
						// now interpret the gesture
						switch (gi.dwID){
						case GID_ZOOM:
							// Code for zooming goes here     
							bHandled = true;
							break;
						case GID_PAN:
							// Code for panning goes here
							bHandled = false;
							break;
						case GID_ROTATE:
							// Code for rotation goes here
							bHandled = true;
							break;
						case GID_TWOFINGERTAP:
							// Code for two-finger tap goes here
							bHandled = true;
							break;
						case GID_PRESSANDTAP:
							// Code for roll over goes here
							bHandled = false;
							break;
						default:
							// A gesture was not recognized
							break;
						}
					}else{
						DWORD dwErr = GetLastError();
						if (dwErr > 0){
							MessageBoxW(hwnd, L"Error!", L"Could not retrieve a GESTUREINFO structure.", MB_OK);
						}
					}
					if (bHandled){
						return 0;
					}else{
						return CallWindowProc(g_pDlg->m_mapPROC[hwnd], hwnd, uMsg, wParam, lParam);
					}
				}//end filter gesture
				return CallWindowProc(g_pDlg->m_mapPROC[hwnd], hwnd, uMsg, wParam, lParam);
			}
		}//end if	
	}//end if

	return DefWindowProc(hwnd, uMsg, wParam, lParam);
}


Step1:Unsubclass

void Ccat8637_priceComparingSystemDlg::OnDestroy()
{
	std::map<HWND,WNDPROC>::iterator iter = m_mapPROC.begin();
	while(iter!=m_mapPROC.end())
	{
		SetWindowLongPtr( iter->first, GWL_WNDPROC, (LONG_PTR)iter->second );
		iter++;
	}
	m_mapPROC.clear();

	CDialogEx::OnDestroy();
}


你可能感兴趣的:(屏蔽WebBrowser控件的手势)