1 #include <atlbase.h>
2 CComModule _Module;
3 #include <atlwin.h>
4 #include <windows.h>
5 #pragma comment(lib,"atl")
6 #pragma comment(lib,"User32.lib")
7
8
9 LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
10 {
11 RECT rc;
12 IWebBrowser2* iWebBrowser;
13 VARIANT varMyURL;
14 static CAxWindow WinContainer;
15 LPOLESTR pszName=OLESTR("shell.Explorer.2");
16 GetClientRect(hWnd, &rc);
17 switch(message)
18 {
19 case WM_CREATE:
20 WinContainer.Create(hWnd, rc, 0,WS_CHILD |WS_VISIBLE);
21 WinContainer.CreateControl(pszName);
22 WinContainer.QueryControl(__uuidof(IWebBrowser2),(void**)&iWebBrowser);
23 VariantInit(&varMyURL);
24 varMyURL.vt = VT_BSTR;
25 varMyURL.bstrVal = SysAllocString(_T("http://www.baidu.com"));
26 iWebBrowser-> Navigate2(&varMyURL,0,0,0,0);
27 VariantClear(&varMyURL);
28 iWebBrowser-> Release();
29 break;
30 case WM_DESTROY:
31 PostQuitMessage(0);
32 break;
33 default:
34 return (int)DefWindowProc(hWnd,message,wParam,lParam);
35 }
36 return 0;
37 }
38
39
40 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
41 {
42 static TCHAR szAppName[]=TEXT("WebBrowser");
43 static TCHAR szClassName[]=TEXT("WebBrowser");
44 HWND hWnd;
45 MSG msg;
46 WNDCLASS wndclass;
47 wndclass.style=CS_HREDRAW | CS_VREDRAW;
48 wndclass.lpfnWndProc=WndProc;
49 wndclass.cbClsExtra=0;
50 wndclass.cbWndExtra=0;
51 wndclass.hInstance=hInstance;
52 wndclass.hIcon=LoadIcon(hInstance, IDI_APPLICATION);
53 wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
54 wndclass.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
55 wndclass.lpszMenuName=NULL;
56 wndclass.lpszClassName=szClassName;
57
58
59 if(!RegisterClass(&wndclass))
60 {
61 MessageBox(NULL,TEXT("Error!"),szAppName,MB_ICONERROR);
62 return 0;
63 }
64
65
66 hWnd=CreateWindow(szClassName,szAppName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,
67 0,CW_USEDEFAULT,0,NULL,NULL,hInstance,NULL);
68 ShowWindow(hWnd,nShowCmd);
69 UpdateWindow(hWnd);
70
71 while(GetMessage(&msg, NULL, 0, 0))
72 {
73 TranslateMessage(&msg);
74 DispatchMessage(&msg);
75 }
76 return msg.wParam;
77 }