大家好,我用下面方法给网页一个元素fire onclick消息,返回值都是成功的,但是实际上没有操作效果,问题出在哪里呢?请大家支招,谢谢!CComQIPtr<IHTMLDocument2> spDoc2;
CComQIPtr<IDispatch> spDoc2Disp;
spEle->get_document(&spDoc2Disp);
if(spDoc2Disp == NULL)
return 1;spDoc2 = spDoc2Disp;CComQIPtr<IHTMLDocument4> spDoc4 = spDoc2;
if(spDoc4 == NULL)
return 1;CComPtr<IHTMLEventObj> spEvent;
CComVariant var;
spDoc4->createEventObject(&var, &spEvent);CComQIPtr<IHTMLEventObj2> spEvent2(spEvent);
CComBSTR eventName = "onclick";
spEvent2->put_type(eventName); CComQIPtr<IHTMLElement3, &IID_IHTMLElement3> spEle3(spEle);
VARIANT_BOOL varbResult;
CComVariant varEvent = spEvent; hr = spEle3->fireEvent(eventName, &varEvent, &varbResult);
CComQIPtr<IDispatch> spDoc2Disp;
spEle->get_document(&spDoc2Disp);
if(spDoc2Disp == NULL)
return 1;spDoc2 = spDoc2Disp;CComQIPtr<IHTMLDocument4> spDoc4 = spDoc2;
if(spDoc4 == NULL)
return 1;CComPtr<IHTMLEventObj> spEvent;
CComVariant var;
spDoc4->createEventObject(&var, &spEvent);CComQIPtr<IHTMLEventObj2> spEvent2(spEvent);
CComBSTR eventName = "onclick";
spEvent2->put_type(eventName); CComQIPtr<IHTMLElement3, &IID_IHTMLElement3> spEle3(spEle);
VARIANT_BOOL varbResult;
CComVariant varEvent = spEvent; hr = spEle3->fireEvent(eventName, &varEvent, &varbResult);
2. IHTMLElement有click方法,直接用就是了.何必多此一举?
=======================================================
FreeLaxy, your backup.
=======================================================
=======================================================
FreeLaxy, your backup.
=======================================================
=======================================================
FreeLaxy, your backup.
=======================================================
=======================================================
FreeLaxy, your backup.
=======================================================
我进行了如下测试,正确获取了Internet Explorer_sever 句柄HWND,正确获取了元素在客户区的坐标,如果网页在前端,下面消息发送是正确的,可以正确点击。但是如果页面没有在前端,就无法模拟,
上回朋友所说的“根据试验, 即使窗口不在前台(focus/foreground), 仍然会傻乎乎地接受鼠标和键盘消息”,这个是怎么实现的?难道是我下面发送消息的模式不对,还是我忽略什么关键地方?请指正!非常感谢!::SendMessage(hIEServer,WM_LBUTTONDOWN,NULL,MAKELONG(pt.x,pt.y));
::SendMessage(hIEServer,WM_LBUTTONUP,NULL,MAKELONG(pt.x,pt.y));