Created
March 13, 2015 23:10
-
-
Save kumatti1/9d53ccee872d6322024b to your computer and use it in GitHub Desktop.
IHTMLInputElementからのIHTMLWindow2取り出し
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Exdisp.h> | |
#import <shdocvw.dll> | |
#include <mshtml.h> | |
#import <mshtml.tlb> | |
#include <Shlwapi.h> | |
#define URL L"https://www.google.co.jp/?gws_rd=ssl" | |
HRESULT test() | |
{ | |
HRESULT hr = S_OK; | |
try{ | |
SHDocVw::IShellWindowsPtr psw; | |
hr = psw.CreateInstance(__uuidof(SHDocVw::ShellWindows)); | |
if (FAILED(hr)) _com_issue_error(hr); | |
_variant_t varLoc(_bstr_t(URL)); | |
_variant_t VarRoot; | |
long h = 0; | |
IDispatchPtr pDisp = psw->FindWindowSW(&varLoc, &VarRoot, SWC_BROWSER, &h, SWFO_NEEDDISPATCH); | |
SHDocVw::IWebBrowser2Ptr pBrowser(pDisp); | |
MSHTML::IHTMLDocument2Ptr pDoc(pBrowser->Document); | |
MSHTML::IHTMLElementCollectionPtr pCol( pDoc->forms ); | |
MSHTML::IHTMLFormElementPtr pForm( pCol->item( _variant_t( L"f" ) ) ); | |
MSHTML::IHTMLInputElementPtr pInput( pForm->item( _variant_t( L"q") ) ); | |
//pInput->value = L"hoge"; | |
//pForm->submit(); | |
MSHTML::IHTMLWindow2Ptr pWin2; | |
hr = IUnknown_QueryService( pInput, IID_IHTMLWindow2, IID_PPV_ARGS( &pWin2 ) ); | |
if (FAILED(hr)) _com_issue_error(hr); | |
pWin2 && pWin2->navigate( L"http://www.yahoo.co.jp/" ); | |
} | |
catch (_com_error& e) { | |
hr = e.Error(); | |
MessageBoxA(nullptr, (LPCSTR)e.ErrorMessage(), nullptr, MB_OK); | |
} | |
return hr; | |
} | |
int CALLBACK WinMain( | |
_In_ HINSTANCE hInstance, | |
_In_ HINSTANCE hPrevInstance, | |
_In_ LPSTR lpCmdLine, | |
_In_ int nCmdShow | |
) | |
{ | |
CoInitialize(NULL); | |
test(); | |
CoUninitialize(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment