网页模拟点击(非鼠标,消息模拟)

代码是我的网页类的一部分,只要取得IWebBrowser2了就可以用。

IWebBrowser2 *m_pIWebBrowser2

 

BOOL CXWebBrowser::ClickElementByID(PWCHAR pID)
{
	BOOL bRet = FALSE;
	IDispatch *pDispatch = NULL;
	IHTMLDocument3 *htmlDoc3 = NULL;
	IHTMLElement *pElement = NULL;

	if (pID == NULL) return bRet;
	__try
	{
		if (m_pIWebBrowser2->get_Document(&pDispatch) != ERROR_SUCCESS) __leave;
		if (pDispatch == NULL) __leave;
		if (pDispatch->QueryInterface(IID_IHTMLDocument3, (void**)&htmlDoc3) != ERROR_SUCCESS) __leave;
		if (htmlDoc3 == NULL) __leave;
		htmlDoc3->getElementById(pID, &pElement);
		if (pElement == NULL) __leave;
		pElement->click();
		bRet = TRUE;
	}
	__finally
	{
		if (pElement) pElement->Release();
		if (htmlDoc3) htmlDoc3->Release();
		if (pDispatch) pDispatch->Release();
	}
	return bRet;
}


 

你可能感兴趣的:(网页模拟点击(非鼠标,消息模拟))