最近在弄个程序,是关于自动点击的,发现那个网页上给mousedown事件设置了监听,直接调用element->Click,会被判断为直接打开连接,而不是由网页点击进去了,来源信息没有了,于是放狗搜索,搜了2天时间,始终没有发现能用的代码,最后,终于被我发现了一段能用的代码,bcb使用的话,要增加
#include "atl//atlbase.h"
....
CComQIPtr<IHTMLDocument2>spDoc2;
CComQIPtr<IDispatch>spDoc2Disp;
pElement->get_document(&spDoc2Disp);
if (spDoc2Disp == NULL)
return;
spDoc2 = spDoc2Disp;
CComQIPtr<IHTMLDocument4>spDoc4;
spDoc4 = spDoc2;
if (spDoc4 == NULL)
return;
CComPtr<IHTMLEventObj>spEvent;
CComVariant var;
spDoc4->createEventObject(&var, &spEvent);
CComQIPtr<IHTMLEventObj2>spEvent2(spEvent);
String eventname="onmousedown";
CComBSTR eventName = eventname.w_str() ;
spEvent2->put_type(eventName);
CComQIPtr<IHTMLElement3, &IID_IHTMLElement3>spEle3(pElement);
VARIANT_BOOL varbResult;
CComVariant varEvent;
varEvent = spEvent;
spEle3->fireEvent(eventName, &varEvent, &varbResult);