cppwebbrowser基础问题
<td><input id="offlineMailNoYTO" class="mailNo:offline" type="text" value='' /></td><td></td><td><button id="YTO" class="confirm logis:offlineConfirm">确认</button></td>
if(pDisp==CppWebBrowser1->DefaultDispatch)
{
VARIANT id, index, id1, index1;
IDispatch *spDispatch=0;
IHTMLDocument2 *pDoc2=NULL;
IHTMLElement *pElement=0;
IHTMLElementCollection *pElementCol=0;
IHTMLFormElement *pFormElement=0;
IHTMLInputElement *pInputElement=0;
if (!CppWebBrowser1->Busy && CppWebBrowser1->Document &&
AnsiString(CppWebBrowser1->LocationURL) != "about:blank" )
if (SUCCEEDED(CppWebBrowser1->Document->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&pDoc2)))
if ( SUCCEEDED ( pDoc2->get_forms ( &pElementCol ) ) ) // 得到form
{
long p = 0;
if ( SUCCEEDED ( pElementCol->get_length ( &p ) ) )
{ // 哪一个form
if ( p != 0 )
{
for ( long i = 0; i <= p-1; i++ )
{
V_VT ( &id ) = VT_I4;
V_I4 ( &id ) = i;
V_VT ( &index ) = VT_I4;
V_I4 ( &index ) = 0;
if ( SUCCEEDED ( pElementCol->item ( id, index, &spDispatch ) ) )
{
if
(
SUCCEEDED ( spDispatch->QueryInterface ( IID_IHTMLFormElement,
( void ** ) &pFormElement ) )
)
{
long q = 0;
if ( SUCCEEDED ( pFormElement->get_length ( &q ) ) )
{ // 得到form中的控件个数
for ( long j = 0; j <= (q - 1); j++ )
{
V_VT ( &id ) = VT_I4;
V_I4 ( &id ) = j;
V_VT ( &index ) = VT_I4;
V_I4 ( &index ) = 0;
if ( SUCCEEDED ( pFormElement->item ( id, index, &spDispatch ) ) )
{
if
(
SUCCEEDED ( spDispatch->QueryInterface ( IID_IHTMLElement,
( void ** ) &pElement ) )
)
{
if
(
SUCCEEDED ( spDispatch->QueryInterface ( IID_IHTMLInputElement,
( void ** ) &pInputElement ) )
)
{
// AfxMessageBox("已经获取IHTMLInputTextElement");
BSTR Value;
BSTR Type;
BSTR Id;
BSTR Name;
pInputElement->get_type ( &Type ); // 获取类型
//
// pInputElement->get_value(&
// Value); //获取值
//
pElement->get_id ( &Id ); // 获取Id的方法不一样
///
//
// pInputElement->get_name(&
// Name); //获取它的名字
//
AnsiString tempID,tempName;
tempID = AnsiString ( Id ).UpperCase ();
tempName = AnsiString ( Type ).UpperCase ();
if
(
tempName != NULL
&& ((tempName.Trim ()).Length () > 0)
)
{
// tempName = AnsiString ( Type ).UpperCase ();
if ( tempName == "TEXT" ) // 获取和设置文本框的值
{
if ( tempID == "USERNAME" ) ///
{
// WideString temp = SValue;
pInputElement->put_value ( (WideString) Form1->sUserName );
}
}
else if ( tempName == "PASSWORD" ) // 获取和设置密码框的值
{
if ( tempID == "PASSWORD" ) ///
{
pInputElement->put_value ( (WideString) Form1->sPassword );
}
}
else if ( tempName == "RADIO" ) // 获取和设置单选的值
///
{
pElement->click (); // 模拟单击
}
else if ( tempName == "CHECKBOX" ) // 获取和设置多选框的值
///
{
pElement->click (); // 模拟单击
// pInputElement->put_checked(j);
}
else if ( tempName == "BUTTON" ) // 非提交按钮
{
pElement->click(); //模拟单击
}
else if ( tempName == "SUBMIT" ) // 提交按钮
{
pElement->click(); //模拟单击
}
// break;
} // 如果不符,则不做处理
///
pInputElement->Release ();
}
else // 不是input框
{
}
pElement->Release ();
} // if pelement
spDispatch->Release ();
}
}
}
pFormElement->Release ();
}
spDispatch->Release ();
}
}
}
}
}
if ( pDoc2 )
pDoc2->Release ();
}