3,245
社区成员
发帖
与我相关
我的任务
分享
#include <atlcom.h>
#include <atlbase.h>
#include <mshtml.h>
#include "stdafx.h"
#include "web_UTU.h"
#include "web_UTUDoc.h"
#include "web_UTUView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CComModule _Module;
bool CWeb_UTUView::putStr(CString cs)
{
IHTMLDocument2 *pIHTMLDocument2 =(IHTMLDocument2*)GetHtmlDocument();
if( pIHTMLDocument2)
{
HRESULT hr;
CComQIPtr< IHTMLElementCollection > spElementCollection;
hr = pIHTMLDocument2->get_forms( &spElementCollection ); //取得表单集合
long nFormCount=0; //取得表单数目
hr = spElementCollection->get_length( &nFormCount );
if ( FAILED( hr ) )
{
return false;
}
for(long i=0; i<nFormCount; i++)
{
IDispatch *pDisp = NULL; // 取得第i项表单
hr = spElementCollection->item( CComVariant( i ), CComVariant(), &pDisp );
if ( FAILED( hr ) ) continue;
CComQIPtr< IHTMLFormElement > spFormElement = pDisp;
pDisp->Release();
long nElemCount=0; //取得表单中 域 的数目
hr = spFormElement->get_length( &nElemCount );
if ( FAILED( hr ) ) continue;
for(long j=0; j<nElemCount; j++)
{
CComDispatchDriver spInputElement; //取得第 j 项表单域
hr = spFormElement->item( CComVariant( j ), CComVariant(), &spInputElement );
if ( FAILED( hr ) ) continue;
CComVariant vName; //取得表单域的名
hr = spInputElement.GetPropertyByName( L"name", &vName );
if( FAILED( hr ) ) continue;
if(vName=="wd")
{
spInputElement.PutPropertyByName(str,vName);//写入str
}
}
//提交这个表单
pForm->submit();
}
}
pIHTMLDocument2->Release();
}
else return FALSE;
}