case WM_CREATE:
GUID guid; 
_Module.Init(NULL, hInst, &guid); 
RECT rc;
GetClientRect(hWnd,&rc);
HRESULT hr;
WinContainer.Create(hWnd,rc,_T("shell.Explorer.2"),WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);    
hr = WinContainer.QueryControl(__uuidof(IWebBrowser2),(void**)&WebBrowser);        
if(FAILED(hr))
{
return -1L;
} VARIANT url;
VARIANT v;
url.vt = VT_BSTR;
url.bstrVal = SysAllocString(BSTR("http://www.qq.com"));
WebBrowser->Navigate2(&url,&v,&v,&v,&v);
break;这部分是message里的wm_Create消息
问题是程序能正常运行,就显示一个白框框给我  里面没有网页内容。
还有我把网页改成"http://www.baidu.com"的时候,那个白框框里就显示该网页不存在。

解决方案 »

  1.   


    // VS2008 下编译
    #include "stdafx.h"
    #include <atlbase.h>
    CComModule _Module;
    #include <atlwin.h>
    #include <windows.h>
    #pragma comment(lib,"atl")
    #pragma comment(lib,"User32.lib")
    LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
    {
    RECT rc;
    IWebBrowser2* iWebBrowser;
    VARIANT varMyURL;
    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.baidu.com"));
    iWebBrowser-> Navigate2(&varMyURL,0,0,0,0);
    VariantClear(&varMyURL); 
    iWebBrowser-> Release(); 
    break;
    case WM_DESTROY:
    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;
    }
    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;
    }
      

  2.   

    楼上的大哥。。 我试了下你的代码  好像也是显示不出网页。
     难道是我用的VS2003?  版本太老了?还是谢谢了。。 
    不知道啥问题 我下个VS2005看看?