[C++] 纯文本查看 复制代码 #include <windows.h>
#include <exdisp.h>
#include <mshtml.h>
#include <atlbase.h>
using namespace ATL;
CComPtr<IWebBrowser2> spBrowser;
CoInitialize(NULL);
CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_SERVER, IID_IWebBrowser2, (void**)&spBrowser);
spBrowser->Navigate(CComVariant(L"http://www.example.com"), CComVariant(0), CComVariant(), CComVariant(), CComVariant());
VARIANT_BOOL bDone = VARIANT_FALSE;
while (!bDone)
{
Sleep(1000);
spBrowser->get_ReadyState(&bDone);
}
CComPtr<IDispatch> spDisp;
spBrowser->get_Document(&spDisp);
CComQIPtr<IHTMLDocument2> spDoc(spDisp);
UINT_PTR nTimerId = SetTimer(NULL, 0, 5000, (TIMERPROC)TimerProc);
void CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
spDoc->location->reload(VARIANT_TRUE);
}
#include <windows.h>
#include <exdisp.h>
#include <mshtml.h>
#include <atlbase.h>
using namespace ATL;
CComPtr<IHTMLDocument2> spDoc;
void CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
spDoc->location->reload(VARIANT_TRUE);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
CComPtr<IWebBrowser2> spBrowser;
CoInitialize(NULL);
CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_SERVER, IID_IWebBrowser2, (void**)&spBrowser);
spBrowser->Navigate(CComVariant(L"http://www.example.com"), CComVariant(0), CComVariant(), CComVariant(), CComVariant());
VARIANT_BOOL bDone = VARIANT_FALSE;
while (!bDone)
{
Sleep(1000);
spBrowser->get_ReadyState(&bDone);
}
CComPtr<IDispatch> spDisp;
spBrowser->get_Document(&spDisp);
spDoc = CComQIPtr<IHTMLDocument2>(spDisp);
UINT_PTR nTimerId = SetTimer(NULL, 0, 5000, (TIMERPROC)TimerProc);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
KillTimer(NULL, nTimerId);
CoUninitialize();
return 0;
}
|