使用windows API函數呼叫瀏覽器組件

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   使用   os   io   

#include <atlbase.h>#include <atlwin.h>#include <windows.h>#include <tchar.h>#pragma comment(lib,"atl")#pragma comment(lib,"User32.lib")CComModule _Module;const TCHAR *URL[9] = {    _T("http://www.csdn.net/"),    _T("http://www.zol.com.cn/"),    _T("http://www.cnblogs.com/"),    _T("http://pal5q.baiyou100.com/2501000.asp"),    _T("http://www.yinyuetai.com/"),    _T("http://v.youku.com/v_show/id_XMzgwMjkyMTc2.html?f=17540585"),    _T("http://social.msdn.microsoft.com/Forums/zh-CN/0631bed7-8b7e-4c0b-a666-90aa38e98075/win32-sdkwebbrowsercomatl"),    _T("http://blog.csdn.net/geniusice18/article/details/16369499"),    _T("http://cricode.com/1494.html")};LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam){    RECT rc;    IWebBrowser2* iWebBrowser;    VARIANT varMyURL;    static int i = 0;    static CAxWindow WinContainer;    LPOLESTR pszName=OLESTR("shell.Explorer.2");    GetClientRect(hWnd, &rc);    switch(message)    {    case WM_CREATE:        WinContainer.Create(hWnd, rc, 0,WS_CHILD |WS_VISIBLE);        WinContainer.CreateControl(pszName);        WinContainer.QueryControl(__uuidof(IWebBrowser2),(void**)&iWebBrowser);         VariantInit(&varMyURL);        varMyURL.vt = VT_BSTR;         varMyURL.bstrVal = SysAllocString(_T("http://www.163.com/"));        iWebBrowser-> Navigate2(&varMyURL,0,0,0,0);        VariantClear(&varMyURL);         iWebBrowser->put_Silent(VARIANT_TRUE);//        iWebBrowser-> Release();         SetTimer(hWnd,0,10000,NULL);        break;    case WM_SIZE:        break;    case WM_TIMER:        {            WinContainer.QueryControl(__uuidof(IWebBrowser2),(void**)&iWebBrowser);             VariantInit(&varMyURL);            varMyURL.vt = VT_BSTR;             varMyURL.bstrVal = SysAllocString(URL[i++]);            iWebBrowser-> Navigate2(&varMyURL,0,0,0,0);            VariantClear(&varMyURL); //            iWebBrowser-> Release();             break;        }    case WM_DESTROY:        iWebBrowser->Quit();        _Module.Term();        PostQuitMessage(0);        break;    default:        return (int)DefWindowProc(hWnd,message,wParam,lParam);    }    return 0;}int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){    static TCHAR szAppName[]=TEXT("WebBrowser");    static TCHAR szClassName[]=TEXT("WebBrowser");    HWND hWnd;    MSG msg;    WNDCLASS wndclass;    wndclass.style=CS_HREDRAW | CS_VREDRAW;    wndclass.lpfnWndProc=WndProc;    wndclass.cbClsExtra=0;    wndclass.cbWndExtra=0;    wndclass.hInstance=hInstance;    wndclass.hIcon=LoadIcon(hInstance, IDI_APPLICATION);    wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);    wndclass.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);    wndclass.lpszMenuName=NULL;    wndclass.lpszClassName=szClassName;    if(!RegisterClass(&wndclass))    {        MessageBox(NULL,TEXT("Error!"),szAppName,MB_ICONERROR);        return 0;    }    //HRESULT hRes = _Module.Init(NULL, hInstance);    GUID guid;     HRESULT hRes = _Module.Init(NULL, hInstance, &guid);    hWnd=CreateWindow(szClassName,szAppName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,0,CW_USEDEFAULT,0,NULL,NULL,hInstance,NULL);    ShowWindow(hWnd,nShowCmd);    UpdateWindow(hWnd);    while(GetMessage(&msg, NULL, 0, 0))    {        TranslateMessage(&msg);        DispatchMessage(&msg);    }    return msg.wParam;}
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.