3,055
社区成员
发帖
与我相关
我的任务
分享
... ...
hr = spFormElement->QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC);
if (hr == S_OK)
{
// Find the connection point.
hr = pCPC->FindConnectionPoint( DIID_HTMLFormElementEvents , &pCP);
if (hr == S_OK)
{
// Advise the connection point.
hr = pCP->Advise((IUnknown*)&pOnWebEvent, &dwCookie);
if ( FAILED( hr ) ) ::AfxMessageBox("bbb");
}
pCPC->Release();
}
//----------------------------------------------------------------------------------
//枚举表单中的元素,找到与input 有关的项,如果发现为 image 类型的按钮,就点击。
CComQIPtr< IHTMLElement > spAllInputElement;
spFormElement->QueryInterface( IID_IHTMLElement , (void**)&spAllInputElement );
CComQIPtr< IDispatch > spCollDisp;
CComQIPtr< IHTMLElementCollection > spCollElement;
spAllInputElement->get_all( (IDispatch**)&spCollDisp );
spCollDisp->QueryInterface( IID_IHTMLElementCollection , (void**)&spCollElement );
long nCollCount = 0;
spCollElement->get_length(&nCollCount);
for( long i = 0 ; i< nCollCount ; i++ )
{
CComQIPtr< IDispatch > MyDisp;
CComQIPtr< IHTMLInputElement > spInputElement;
hr = spCollElement->item( CComVariant(i) , CComVariant() , &MyDisp );
if ( FAILED( hr ) ) continue;
if( !MyDisp )//容错
return;
hr = MyDisp->QueryInterface( IID_IHTMLInputElement , (void**)&spInputElement );
if ( FAILED( hr ) ) continue;
//取得表单域,并且点击按钮
CComBSTR vName,vVal,vType;
hr = spInputElement->get_name( &vName );
if( FAILED( hr ) ) continue;
hr = spInputElement->get_value( &vVal );
if( FAILED( hr ) ) continue;
hr = spInputElement->get_type( &vType );
if( FAILED( hr ) ) continue;
if( !strnicmp(lpType , "image" , 5) )//如果发现 为 image 类型的按钮就点击之
{
CComQIPtr< IHTMLElement > spSingleElement;
hr = spInputElement->QueryInterface( IID_IHTMLElement , (void**)&spSingleElement);
if( FAILED( hr ) ) continue;
hr = spSingleElement->click();
if( FAILED( hr ) ) continue;
}
::CoInitialize(NULL); //初始化 COM 公寓
EnumIE(); //枚举浏览器
::CoUninitialize(); //释放 COM 公寓
hr = spFormElement->put_onsubmit( vEvent );
if( !strnicmp(lpType , "image" , 5) )//如果发现 为 image 类型的按钮就点击之
{
CComQIPtr< IHTMLElement > spSingleElement;
hr = spInputElement->QueryInterface( IID_IHTMLElement , (void**)&spSingleElement);
if( FAILED( hr ) ) continue;
hr = spSingleElement->click();
if( FAILED( hr ) ) continue;
}
hr = spFormElement->put_onsubmit( vEvent );