お世話になっております
C++ で IE上の セレクトボックスの値を 選択したいのですが
上手くいきません
C++
1#include <windows.h> 2#include <tchar.h> 3#include <atlbase.h> 4#include <mshtml.h> 5#include <cstdio> 6#include <stdio.h> 7#include <string.h> 8#include <string> 9#include <iostream> 10#include <atlstr.h> 11#include <wchar.h> 12#include <stdlib.h> 13#include <stdio.h> 14 15#import <mshtml.tlb> 16using namespace std; 17 18#import <shdocvw.dll> 19#import <mshtml.tlb> 20 21#import "libid:EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B" no_namespace named_guids 22 23 24int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 25 PSTR szCmdLine, int iCmdShow) 26{ 27 28 HRESULT hr = ::CoInitialize(NULL); 29 if (FAILED(hr)) { 30 return -1; 31 } 32 33 34 IWebBrowser2* pIE; 35 hr = CoCreateInstance( 36 CLSID_InternetExplorer, 37 NULL, 38 CLSCTX_LOCAL_SERVER, 39 IID_IWebBrowser2, 40 (VOID**)&pIE 41 ); 42 43 44 VARIANT_BOOL pBool = VARIANT_TRUE; 45 hr = pIE->put_Visible(pBool); 46 47 48 pIE->Navigate("http://www.jma.go.jp/jp/yoho/"); 49 50 51 while (pIE->Busy == VARIANT_TRUE || 52 pIE->ReadyState != READYSTATE_COMPLETE) 53 ::Sleep(100); 54 55 56 57 58 MSHTML::IHTMLDocument3Ptr pDoc = pIE->GetDocument(); 59 CComQIPtr<IHTMLElementCollection> elements = pDoc->getElementsByTagName("option"); 60 61 long len; 62 elements->get_length(&len); 63 64 for (long i = 0; i < len; ++i) { 65 CComPtr<IDispatch> pDispath; 66 elements->item(CComVariant(i), CComVariant(0), &pDispath); 67 CComQIPtr<IHTMLElement> pElement = pDispath; 68 CComBSTR inner; 69 pElement->get_innerText(&inner); 70 71 72 pElement->put_innerText(_bstr_t(inner)); 73 74 } 75 76 pDoc.Release(); 77 pIE->Quit(); 78 pIE->Release(); 79 80 ::CoUninitialize(); 81 82 exit(0); 83 84} 85 86```get_innerText で 値が取得できているので 87put_innerText で 選択できると考えたのですが 88思うようにいきません 89 90回答 お願い致します 91 92******************************* 93 開発環境 94******************************* 95 96Visual Studio Community 2017 に 97 98MFC と ATL のサポート (X86 と X64) 99Windows 8.1 SDK 100Windows Universal CRT SDK 101標準ライブラリモジュール 102 103をインストールしています 104(その他も?)
回答1件
あなたの回答
tips
プレビュー