Windows2000 SP4 IE6 VC++6.0SP5で開発をしています。
IEのボタンをアプリ側から自動に押して別ページに飛ばしたいのですが、
やり方がわかりません。
現在、CHtmlViewを使って、IHTML...から操作しようと考えています。
以下のように記述して、INPUTタグを検索し、submitを実行してみようと
思いました。
IHTMLDocument2* pDocument2;
IDispatch* pDispatch = NULL;
pDispatch = GetHtmlDocument ( );
pDispatch->QueryInterface ( IID_IHTMLDocument2, (void**)&pDocument2 );
IHTMLElementCollection* pCollection;
pDocument2->get_all ( &pCollection );
long length;
pCollection->get_length ( &length );
if ( length > 0 ) {
USES_CONVERSION;
for ( long l=0 ; l<length ; l++ ) {
VARIANT varIndex;
varIndex.vt = VT_UINT;
varIndex.lVal = l;
VARIANT var2;
VariantInit ( &var2 );
IDispatch* pDisp;
pCollection->item ( varIndex, var2, &pDisp ); // Get an element
IHTMLElement* pElement;
pDisp->QueryInterface ( IID_IHTMLElement, (void**)&pElement );
BSTR bstrButton;
if ( (pElement->get_tagName(&bstrButton)==S_OK) && (bstrButton!=NULL) ) {
CString strTag = bstrButton;
if ( strTag.CompareNoCase("input") == 0 ) { // Input タグを検索
IHTMLInputButtonElement* pButton;
pDisp->QueryInterface ( IID_IHTMLInputButtonElement, (void**)&pButton );
IHTMLFormElement* pForm;
if ( pButton->get_form(&pForm) == S_OK ) {
pForm->submit ( );
l=length;
pForm->Release ( );
}
pButton->Release ( );
}
}
pElement->Release ( );
}
pCollection->Release ( );
}
http://www.codeproject.com/com/DHTML_Interfaces.asp
を参考にしています。また、ボタンですが、以下のページのサンプルにある
onclickによって画面を変更するものを対象に考えています。
http://www.hajimeteno.ne.jp/dhtml/dist/js69.html
INPUTタグを検索するところまではできるのですが、
pDisp->QueryInterface ( IID_IHTMLInputButtonElement, (void**)&pButton );
で、pButtonに値が入りません。
また、値がとれたとして、pForm->submit()で良いのかも疑問です。
どのようにしてアプリ上から自動でボタンを押させるようにするのか
お教えください。よろしくお願いいたします。
ツイート | ![]() |