win32 sdk下调用webbrowser控件

#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; }

你可能感兴趣的:(null,application,callback,include,WebBrowser,winapi)