#include <windows.h> #include <tchar.h> #import <shdocvw.dll> #import <mshtml.tlb> int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HRESULT hr = ::CoInitialize(NULL); //COMを使うときのお約束 if (FAILED(hr)) { return -1; } NewIE(); //新しいIEを開く HWND hwnd = ::FindWindow(NULL, _T("Google - Microsoft Internet Explorer")); if (hwnd != NULL) { SHDocVw::IWebBrowser2Ptr pIE = FindIE(hwnd); //WebBrowserを取得する GoogleSearch(pIE); //Googleに入力してみる } else { ::OutputDebugString(_T("not found Google window\n")); } EventTest(); //WebBrowserのイベントを捕捉してみる ::CoUninitialize(); //COM使用終了 return 0; } void NewIE() { SHDocVw::IWebBrowser2Ptr pIE; //IEの起動 HRESULT hr = pIE.CreateInstance(__uuidof(SHDocVw::InternetExplorer)); // HRESULT hr = pIE.CreateInstance(_T("InternetExplorer.Application")); if(FAILED(hr)){ TCHAR str[256]; wsprintf(str, _T("NewIE#CreateInstance error:%x\n"), hr); ::OutputDebugString(str); return; } //IEの表示 pIE->PutVisible(VARIANT_TRUE); pIE->Navigate(_T("http://www.ne.jp/asahi/hishidama/home/tech/vcpp/index.html")); while (pIE->Busy == TRUE || pIE->GetReadyState() < READYSTATE_COMPLETE) { Sleep(100); } }