IE 实现代码示例

IE 是 CE 的一个标准功能,但 很多人想定制 IE 浏览器,以实现某此特殊的需求。

以早以前看过 MS 提供的 IE 示例,研究了一下,现将代码分享出来,大家一起学习。
需要注意的是,IESIMPLE 做为窗体的类名不能修改,详细见代码中的注释。

resource.h 头文件:

 1 //
 2 // Copyright (c) Microsoft Corporation.  All rights reserved.
 3 //
 4 //
 5 // Use of this source code is subject to the terms of the Microsoft end-user
 6 // license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
 7 // If you did not accept the terms of the EULA, you are not authorized to use
 8 // this source code. For a copy of the EULA, please see the LICENSE.RTF on your
 9 // install media.
10 //
11 #define IDC_STATIC                      -1
12
13 #define IDR_ACCELERATOR             100
14
15 #define IDD_OPEN_DIALOG             1000
16
17 #define IDC_URL_EDIT                3000
18 #define IDC_BROWSE              3001
19 #define IDC_NEWWINDOW               3002
20
21 #define IDS_IE                  20000
22 #define IDS_ADDRESS             20001
23 #define IDS_FILESCHEME              20002
24 #define IDS_HYPHEN              20003
25 #define IDS_BROWSEFILTER            20010
26
27 #define ID_VIEW_STOP                500
28 #define ID_VIEW_REFRESH             501
29 #define ID_GO_BACK              502
30 #define ID_GO_FORWARD               503
31 #define ID_FOCUS_URL                504
32 #define ID_OPEN                 505
33 #define ID_GO_HOME              506
34 #define ID_GO_SEARCH                507
35 #define ID_FULLSCREEN               508
36 #define ID_INTERNET_OPTIONS         509
37 #define ID_FIND                 510
38 #define ID_CLOSE                            511
39 #define ID_ZOOMUP                        512
40 #define ID_ZOOMDOWN                  513  

mainwnd.h  头文件:

  1 //
  2 // Copyright (c) Microsoft Corporation.  All rights reserved.
  3 //
  4 //
  5 // Use of this source code is subject to the terms of the Microsoft end-user
  6 // license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
  7 // If you did not accept the terms of the EULA, you are not authorized to use
  8 // this source code. For a copy of the EULA, please see the LICENSE.RTF on your
  9 // install media.
 10 //
 11 /*++
 12 THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
 13 ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
 14 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 15 PARTICULAR PURPOSE.
 16
 17 Module Name:  mainwnd.h
 18
 19 Abstract:  Implements the main window, the container for the webbrowser
 20
 21 Functions:
 22
 23 Notes: This class implements the container and its interaction with the webbrowser control,
 24         commandbar, statusbar etc.
 25
 26
 27 --*/
 28
 29 #ifndef _MAINWND_H
 30 #define _MAINWND_H_
 31
 32 #include "mshtmhst.h"
 33 #include "interned.h"
 34
 35 #define MAX_URL  2048
 36
 37 class CMainWnd :
 38     public IOleContainer,
 39     public IOleClientSite,
 40     public IOleInPlaceSite,
 41     public IServiceProvider,
 42     public DWebBrowserEvents2,
 43     public IDocHostUIHandler,
 44     public IDocHostShowUI,              // msgbox, help window
 45     public IHTMLOMWindowServices   // for window move, resize events
 46 {
 47
 48 public:
 49     CMainWnd();
 50     ~CMainWnd();
 51
 52     BOOL Create();
 53
 54     //IUnknown methods
 55     STDMETHOD(QueryInterface) (REFIID riid, LPVOID * ppv)
 56     {
 57         if ((riid == IID_IOleContainer) || (riid == IID_IUnknown))
 58         {
 59             *ppv = (IOleContainer *) this;
 60         }
 61         else if (riid == IID_IOleClientSite)
 62         {
 63             *ppv = (IOleClientSite *)this;
 64         }
 65         else if (riid == IID_IOleInPlaceSite)
 66         {
 67             *ppv = (IOleInPlaceSite *)this;
 68         }
 69         else if (riid == IID_IOleWindow)
 70         {
 71             *ppv = (IOleWindow *)this;
 72         }
 73         else if ((riid == DIID_DWebBrowserEvents2) || (riid == IID_IDispatch))
 74         {
 75             *ppv = (DWebBrowserEvents2 *)this;
 76         }
 77         else if(riid == IID_IServiceProvider)
 78         {
 79             *ppv = (IServiceProvider *)this;
 80         }
 81         else if (riid == IID_IDocHostUIHandler)
 82         {
 83             *ppv = (IDocHostUIHandler *)this;
 84         }
 85         else if (riid == IID_IDocHostShowUI)
 86         {
 87             *ppv = (IDocHostShowUI *)this;
 88         }
 89         else if (riid == IID_IHTMLOMWindowServices)
 90         {
 91             *ppv = (IHTMLOMWindowServices *)this;
 92         }
 93         else
 94         {
 95             *ppv = NULL;
 96             return E_NOINTERFACE;
 97         }
 98         AddRef();
 99         return S_OK;
100     }
101
102     STDMETHOD_(ULONG, AddRef) (void)
103     {
104         InterlockedIncrement((LONG*)&m_unRefs);
105         return m_unRefs;
106     }
107
108     STDMETHOD_(ULONG, Release) (void)
109     {
110         ULONG ulRefs = m_unRefs;
111         if (InterlockedDecrement((LONG*)&m_unRefs) == 0)
112         {
113             delete this;
114             return 0;
115         }
116         return ulRefs - 1;
117     }
118
119     // IOleContainer methods
120     STDMETHOD(ParseDisplayName)(IBindCtx *, LPOLESTR, ULONG *, IMoniker **) { return E_NOTIMPL;}
121     STDMETHOD(EnumObjects)(DWORD, IEnumUnknown **)
122     {
123         return E_NOTIMPL;
124     }
125     STDMETHOD(LockContainer)(BOOL)                          { return S_OK;}
126
127     // IOleClientSite methods
128     STDMETHOD(SaveObject) (void)                            { return E_NOTIMPL;}
129     STDMETHOD(GetMoniker) (DWORD dwAssign, DWORD dwWhichMoniker, LPMONIKER * ppmk) { return E_NOTIMPL;}
130     STDMETHOD(GetContainer) (LPOLECONTAINER * ppContainer)
131     {
132         return E_NOINTERFACE;
133     }
134     STDMETHOD(ShowObject) (void)                            { return E_NOTIMPL;}
135     STDMETHOD(OnShowWindow) (BOOL fShow)                    { return E_NOTIMPL;}
136     STDMETHOD(RequestNewObjectLayout) (void)                { return E_NOTIMPL;}
137
138     // IOleWindow methods
139     STDMETHOD(GetWindow)(HWND *phwnd)
140     {
141         *phwnd = m_hWndMain;
142         return S_OK;
143     }
144     STDMETHOD(ContextSensitiveHelp)(BOOL fEnterMode)        { return E_NOTIMPL;}
145
146     // IOleInPlaceSite methods
147     STDMETHOD(CanInPlaceActivate)   (void)                  { return S_OK;}
148     STDMETHOD(OnInPlaceActivate)    (void)
149     {
150         m_bInPlaceActive = TRUE;
151         return S_OK;
152     }
153
154     STDMETHOD(OnUIActivate)         (void)                  { return E_NOTIMPL;}
155     STDMETHOD(GetWindowContext) (
156                                 LPOLEINPLACEFRAME FAR *     lplpFrame,
157                                 LPOLEINPLACEUIWINDOW FAR *  lplpDoc,
158                                 LPRECT                      lprcPosRect,
159                                 LPRECT                      lprcClipRect,
160                                 LPOLEINPLACEFRAMEINFO       lpFrameInfo)
161     {
162
163         GetClientRect(m_hWndMain, lprcPosRect);
164         GetClientRect(m_hWndMain, lprcClipRect);
165
166         return S_OK;
167     }
168
169     STDMETHOD(Scroll)               (SIZE scrollExtent)     { return E_NOTIMPL;}
170     STDMETHOD(OnUIDeactivate)       (BOOL fUndoable)        { return E_NOTIMPL;}
171     STDMETHOD(OnInPlaceDeactivate)  (void)
172     {
173         m_bInPlaceActive = FALSE;
174         return S_OK;
175     }
176
177     STDMETHOD(DiscardUndoState)     (void)                  { return E_NOTIMPL;}
178     STDMETHOD(DeactivateAndUndo)    (void)                  { return E_NOTIMPL;}
179     STDMETHOD(OnPosRectChange)      (LPCRECT lprcPosRect)   { return E_NOTIMPL;}
180
181     // IServiceProvider
182
183     STDMETHOD(QueryService)(REFGUID guidService, REFIID riid, void **ppvObj)
184     {
185                 if(guidService == IID_IHTMLOMWindowServices)
186                 {
187                     return QueryInterface(riid, ppvObj);
188                 }
189                 else
190                     return E_FAIL;
191     }
192
193     //DWebBrowserEvents
194     //IDispatch methods
195     STDMETHOD(GetTypeInfoCount)(UINT FAR* pctinfo)          { return E_NOTIMPL;}
196
197     STDMETHOD(GetTypeInfo)(UINT itinfo,LCID lcid,ITypeInfo FAR* FAR* pptinfo)   { return E_NOTIMPL;}
198
199     STDMETHOD(GetIDsOfNames)(REFIID riid,OLECHAR FAR* FAR* rgszNames,UINT cNames,
200                              LCID lcid, DISPID FAR* rgdispid)                  { return E_NOTIMPL;}
201
202     STDMETHOD(Invoke)(DISPID dispidMember,REFIID riid,LCID lcid,WORD wFlags,
203                       DISPPARAMS FAR* pdispparams, VARIANT FAR* pvarResult,
204                       EXCEPINFO FAR* pexcepinfo,UINT FAR* puArgErr);
205
206     // IDocHostUIHandler methods
207     STDMETHOD(EnableModeless)(BOOL fEnable) { return E_NOTIMPL; }
208     STDMETHOD(FilterDataObject)(IDataObject *pDO, IDataObject **ppDORet) { return E_NOTIMPL; }
209     STDMETHOD(GetDropTarget)(IDropTarget *pDropTarget, IDropTarget **ppDropTarget) { return E_NOTIMPL; }
210     STDMETHOD(GetExternal)(IDispatch **ppDispatch) { return E_NOTIMPL; }
211     STDMETHOD(GetHostInfo)(DOCHOSTUIINFO *pInfo);
212     STDMETHOD(GetOptionKeyPath)(LPOLESTR *pchKey, DWORD dw) { return E_NOTIMPL; }
213     STDMETHOD(HideUI)(void) { return E_NOTIMPL; }
214     STDMETHOD(OnDocWindowActivate)(BOOL fActivate) { return E_NOTIMPL; }
215     STDMETHOD(OnFrameWindowActivate)(BOOL fActivate) { return E_NOTIMPL; }
216     STDMETHOD(ResizeBorder)(LPCRECT prcBorder, IOleInPlaceUIWindow *pUIWindow, BOOL fFrameWindow) { return E_NOTIMPL; }
217     STDMETHOD(ShowContextMenu)(DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved, IDispatch *pdispReserved) { return E_NOTIMPL; }
218     STDMETHOD(ShowUI)(DWORD dwID, IOleInPlaceActiveObject *pActiveObject,
219             IOleCommandTarget *pCommandTarget, IOleInPlaceFrame *pFrame,
220             IOleInPlaceUIWindow *pDoc) { return E_NOTIMPL; }
221     STDMETHOD(TranslateAccelerator)(LPMSG lpMsg, const GUID *pgudCmdGroup, DWORD nCmdID) { return E_NOTIMPL; }
222     STDMETHOD(TranslateUrl)(DWORD dwTranslate, OLECHAR *pchURLIn, OLECHAR **ppchURLOut) { return E_NOTIMPL; }
223     STDMETHOD(UpdateUI)(void) { return E_NOTIMPL; }
224
225     // IDocHostShowUI methods
226     STDMETHOD(ShowHelp)( HWND hwnd, LPOLESTR pszHelpFile, UINT uCommand,
227                         DWORD dwData, POINT ptMouse, IDispatch *pDispatchObjectHit)
228                         { return E_NOTIMPL; }
229
230
231     STDMETHOD(ShowMessage)( HWND hwnd, LPOLESTR lpstrText, LPOLESTR lpstrCaption, DWORD dwType,
232                             LPOLESTR lpstrHelpFile, DWORD dwHelpContext, LRESULT *plResult)
233     {
234         int iRes = MessageBox(hwnd, lpstrText, lpstrCaption, dwType);
235         if(plResult)
236         *plResult = iRes;
237         return S_OK;
238     }
239
240    // IHTMLOMWindowServices methods
241     STDMETHOD(moveTo)( LONG x, LONG y);
242     STDMETHOD(moveBy)( LONG x, LONG y);
243     STDMETHOD(resizeTo)( LONG x,LONG y);
244     STDMETHOD(resizeBy)( LONG x, LONG y);
245
246
247 public:
248     BOOL                    PreTranslateMessage(LPMSG pMsg);
249     VOID                    Close();
250     HWND                    GetWindow() {   return m_hWndMain;}
251     LRESULT                 HandleCommand(WPARAM wParam, LPARAM lParam);
252
253     HANDLE                  m_hEvent;
254     IWebBrowser2            *m_pBrowser;
255
256
257
258     static LRESULT  CALLBACK MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
259
260 protected:
261
262
263
264     //Added for HTML Find Dialogs
265     HRESULT                 FindString();
266
267     VOID CMainWnd::ChangeFontSize(BOOL fInit);
268
269     BOOL                    RegisterMainWnd();
270     HWND                    CreateBrowser();
271     HRESULT                 Activate(IOleObject *pObject);
272     HRESULT                 InitEvents();
273
274
275 public:
276     LPTSTR                 m_lpszUrl;
277     BOOL                   m_bEmpty;
278     BOOL                   m_bFullScreen;
279     RECT                   m_rcWnd;
280 protected:
281     HACCEL                  m_hAccelTbl;            //a handle to the accelerator table
282     HWND                    m_hWndMain;         //the main window
283
284     ULONG                   m_unRefs;            //reference count for the interfaces supported by the container
285
286     HWND                    m_hWndBrowser;       //handle to the browser window
287
288     IOleObject              *m_pObject;
289     IConnectionPoint        *m_pCP;
290     IOleInPlaceActiveObject *m_pIPActiveObj;
291     BOOL                    m_bInPlaceActive;
292     DWORD                   m_dwEventCookie;
293
294     TCHAR                   m_tcTitle[MAX_URL];   //title of the current document
295     HWND                    m_hWndProgress;          // progress bar
296     RECT                    m_rcProgress;
297
298     int                     m_iZoom;
299     int                     m_iDLCCounter;
300
301 };
302
303 #endif  //_MAINWND_H_  

mainwnd.cpp  源文件:

   1 /*++
   2
   3 Module Name:  mainwnd.cpp
   4
   5 Abstract:  Implements the main window, the container for the webbrowser
   6
   7 Functions:
   8
   9 Notes: Most of the code resides here. The container and its interaction with the webbrowser control,
  10 commandbar, statusbar etc.
  11
  12
  13 --*/
  14 #include <windows.h>
  15 // Include the automation definitions...
  16 #include <exdisp.h>
  17 #include <exdispid.h>
  18 #include <mshtmdid.h> // AMBIENT_DLCONTROL
  19
  20 #include <objbase.h>
  21
  22 #include <tchar.h>
  23
  24 #include <wininet.h>
  25 #include <afdfunc.h>  //ras stuff
  26 #include <pkfuncs.h>  // GetOwnerProcess
  27 #include <mshtml.h>
  28 #include <commctrl.h>
  29 #include <commdlg.h>
  30 #include "MainWnd.h"
  31 #include "resource.h"
  32
  33 #define INITGUID
  34 #include "initguid.h"
  35 #include <hshell.h>
  36
  37 #define START_FULLSCREEN // Remove this if you don‘t want IESIMPLE to be full-screen at startup
  38
  39 DEFINE_GUID(CLSID_WebBrowser,       0x8856F961L, 0x340A, 0x11D0, 0xA9, 0x6B, 0x00, 0xC0, 0x4F, 0xD7, 0x05, 0xA2);
  40 DEFINE_GUID(IID_IWebBrowser,        0xEAB22AC1L, 0x30C1, 0x11CF, 0xA7, 0xEB, 0x00, 0x00, 0xC0, 0x5B, 0xAE, 0x0B);
  41 DEFINE_GUID(IID_IWebBrowser2,       0xD30C1661L, 0xCDAF, 0x11D0, 0x8A, 0x3E, 0x00, 0xC0, 0x4F, 0xC9, 0xE2, 0x6E);
  42 DEFINE_GUID(DIID_DWebBrowserEvents, 0xEAB22AC2L, 0x30C1, 0x11CF, 0xA7, 0xEB, 0x00, 0x00, 0xC0, 0x5B, 0xAE, 0x0B);
  43 DEFINE_GUID(DIID_DWebBrowserEvents2, 0x34A715A0L, 0x6587, 0x11D0, 0x92, 0x4A, 0x00, 0x20, 0xAF, 0xC7, 0xAC, 0x4D);
  44 DEFINE_GUID(IID_IWebBrowserApp,     0x0002DF05L, 0x0000, 0x0000, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
  45
  46 const GUID SID_SDocHost = { 0xc6504990, 0xd43e, 0x11cf, { 0x89, 0x3b, 0x00, 0xaa, 0x00, 0xbd, 0xce, 0x1a}};
  47
  48 #define MAX(a,b)  (a > b) ? a : b
  49 #define MIN(a,b)  (a > b) ? b : a
  50
  51 LONG        glThreadCount   = 0;
  52 HWND        ghWndAddressEdit= NULL;
  53 HANDLE      ghExitEvent     = NULL;
  54 HINSTANCE   g_hInstance     = NULL;
  55 DWORD      g_dwMainWindowStackSize = 0x20000;
  56
  57 void GetProxyOption();
  58
  59
  60 static HRESULT FindString();
  61 HRESULT HandleNewWindow2(LPTSTR lpszUrl, DISPPARAMS FAR* pdparams);
  62 BOOL RegisterMainWnd();
  63
  64
  65 DWORD WINAPI NewWindow(LPVOID pParam)
  66 {
  67     CMainWnd *pWnd = (CMainWnd *)pParam;
  68     MSG msg;
  69     BOOL fRet;
  70
  71     HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  72
  73     fRet = pWnd->Create();
  74
  75     SetEvent(pWnd->m_hEvent);
  76
  77     if(!fRet)
  78     {
  79         pWnd->m_pBrowser = NULL;
  80         return 0;
  81     }
  82
  83     while(GetMessage( &msg, NULL, 0, 0 ) )
  84     {
  85         if(msg.message == WM_QUIT)
  86             break;
  87
  88         if(!pWnd->PreTranslateMessage(&msg) && !(msg.message == WM_CHAR && msg.wParam == VK_TAB))
  89         {
  90             TranslateMessage(&msg);
  91             DispatchMessage(&msg);
  92         }
  93     }
  94
  95     pWnd->Release();
  96
  97     CoUninitialize();
  98
  99     InterlockedDecrement(&glThreadCount);
 100     SetEvent(ghExitEvent);
 101
 102     return msg.wParam;
 103 }
 104
 105 int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPTSTR lpCmdLine, int nCmdShow)
 106 {
 107     INITCOMMONCONTROLSEX iccsex;
 108     HKEY hKey;
 109     DWORD dwSize = sizeof(DWORD);
 110     MSG msg;
 111
 112     // HKCU is where IE\Main settings are
 113     if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("SOFTWARE\\Microsoft\\Internet Explorer\\Main"), 0, 0, &hKey))
 114     {
 115         RegQueryValueEx(hKey, TEXT("StackRes"), NULL, NULL, (LPBYTE)&g_dwMainWindowStackSize, &dwSize);
 116         RegCloseKey(hKey);
 117     }
 118
 119     // provide a default stack size if the one given is too small or too large.
 120     if(g_dwMainWindowStackSize < 0x10000 || g_dwMainWindowStackSize > 0x80000)
 121     {
 122         // default to 128k
 123         g_dwMainWindowStackSize = 0x20000;
 124     }
 125     RETAILMSG(1,(L"IESIMPLE Using Stack size: 0x%x\r\n", g_dwMainWindowStackSize));
 126
 127     HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
 128     if(FAILED(hr))
 129     {
 130         return FALSE;
 131     }
 132
 133     if(!RegisterMainWnd())
 134     {
 135         return FALSE;
 136     }
 137
 138     ghExitEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
 139     if(!ghExitEvent)
 140     {
 141         return FALSE;
 142     }
 143
 144     iccsex.dwSize = sizeof(INITCOMMONCONTROLSEX);
 145     iccsex.dwICC = ICC_COOL_CLASSES;
 146
 147     InitCommonControlsEx(&iccsex);
 148
 149     g_hInstance = hInst;
 150
 151     // Create a message queue on this thread
 152     PeekMessage(&msg, NULL, 0,0,PM_NOREMOVE);
 153
 154     if(FAILED(HandleNewWindow2(lpCmdLine, NULL)))
 155     {
 156         goto Cleanup;
 157     }
 158
 159     while(glThreadCount > 0)
 160     {
 161         WaitForSingleObject(ghExitEvent, INFINITE);
 162     }
 163
 164 Cleanup:
 165     CoUninitialize();
 166
 167     RETAILMSG(1, (L"IESIMPLE exited. Cmdline was: %s\r\n",lpCmdLine ? lpCmdLine : L""));
 168
 169     return TRUE;
 170 }
 171
 172
 173 CMainWnd::CMainWnd()
 174 {
 175     m_unRefs = 1;
 176     m_hWndMain = NULL;
 177     m_pBrowser = NULL;
 178     m_pObject = NULL;
 179     m_pCP = NULL;
 180     m_lpszUrl = NULL;
 181     m_bFullScreen = FALSE;
 182     m_bEmpty = FALSE;
 183     m_tcTitle[0] = 0;
 184
 185     m_iZoom = 2; // default zoom
 186     m_iDLCCounter = 0; // counter for Download Completes
 187
 188 }
 189
 190 CMainWnd::~CMainWnd()
 191 {
 192     RETAILMSG(1,(L"IESIMPLE Exiting ~CMainWnd\r\n"));
 193
 194     if(m_pBrowser)
 195         m_pBrowser->Release();
 196 }
 197
 198 BOOL RegisterMainWnd()
 199 {
 200     WNDCLASS        wc;
 201     wc.style         = 0;
 202     wc.lpfnWndProc   = (WNDPROC)CMainWnd::MainWndProc;
 203     wc.cbClsExtra    = 0;
 204     wc.cbWndExtra    = 0;
 205     wc.hInstance     = g_hInstance;
 206     wc.hIcon         = NULL; // LoadIcon(g_hInstance, MAKEINTRESOURCE(IDI_IE));
 207     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
 208     wc.hbrBackground = (HBRUSH)GetSysColorBrush(COLOR_WINDOW);
 209     wc.lpszMenuName  = NULL;
 210     wc.lpszClassName = TEXT("IESIMPLE");
 211
 212     if(!(RegisterClass(&wc)))
 213         return FALSE;
 214
 215     return TRUE;
 216 }
 217
 218
 219 BOOL CMainWnd::Create()
 220 {
 221     RECT rcArea;
 222     DWORD dwTick;
 223
 224     DWORD dwStyle = WS_VISIBLE | WS_OVERLAPPED | WS_THICKFRAME | WS_SYSMENU;
 225         /*|WS_OVERLAPPED|WS_BORDER|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX*/
 226     DWORD dwExStyle = 0/*WS_EX_OVERLAPPEDWINDOW*/;
 227
 228     HMENU hMenu = NULL;
 229
 230     SystemParametersInfo(SPI_GETWORKAREA, 0, &rcArea, 0);
 231
 232     m_hWndMain = ::CreateWindowEx(dwExStyle,
 233         TEXT("IESIMPLE"),       // Add ZH  - Leo 不能修改此名称,否则创建窗体失败
 234         (WCHAR *)LoadString(g_hInstance, IDS_IE, NULL, 0),
 235         dwStyle,
 236         rcArea.left + 20,
 237         rcArea.top + 20,
 238         rcArea.right - rcArea.left - 40,
 239         rcArea.bottom - rcArea.top - 30,
 240         NULL, hMenu, g_hInstance, 0);
 241     if(!m_hWndMain)
 242     {
 243         return FALSE;
 244     }
 245
 246     SetWindowLong(m_hWndMain, GWL_USERDATA, (DWORD)this);
 247     GetWindowRect(m_hWndMain, &m_rcWnd);
 248
 249     // create a progress bar
 250     m_rcProgress.left = 5;
 251     m_rcProgress.right = m_rcProgress.left + (m_rcWnd.right - m_rcWnd.left)/3;
 252     m_rcProgress.top = 5;
 253     m_rcProgress.bottom = m_rcProgress.top  + 15;
 254
 255     m_hWndProgress = CreateWindowEx(WS_EX_NOACTIVATE, PROGRESS_CLASS, _T(""), WS_CHILD|PBS_SMOOTH|WS_BORDER,
 256         m_rcProgress.left, m_rcProgress.top, m_rcProgress.right-m_rcProgress.left, m_rcProgress.bottom-m_rcProgress.top,
 257         m_hWndMain, NULL, g_hInstance, NULL);
 258     if(m_hWndProgress)
 259     {
 260         SendMessage(m_hWndProgress, PBM_SETRANGE32, 0, 1000);
 261     }
 262     // /progress bar
 263
 264     dwTick = GetTickCount();
 265     if(!(m_hWndBrowser = CreateBrowser()))
 266         return FALSE;
 267     RETAILMSG(1,(L"Create browser tick count: %d\r\n",GetTickCount() - dwTick));        // 约 2 秒
 268
 269     // LONG lStyle = GetWindowLong(_hWndBrowser, GWL_STYLE);
 270     // SetWindowLong(_hWndBrowser, GWL_STYLE, lStyle|WS_BORDER);
 271
 272     SetFocus(m_hWndMain);
 273
 274     m_hAccelTbl = LoadAccelerators(g_hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR));
 275
 276 #ifdef START_FULLSCREEN
 277     HandleCommand( ID_FULLSCREEN, 0 );
 278 #endif
 279
 280     return TRUE;
 281 }
 282
 283
 284
 285 void GetProxyOption()
 286 {
 287     INTERNET_PER_CONN_OPTION_LIST   iOptionList;
 288     INTERNET_PER_CONN_OPTION        iOptions[3];
 289     ULONG                           uSize = sizeof(iOptionList);
 290
 291     iOptionList.dwSize          = uSize;
 292     iOptionList.pszConnection   = NULL;
 293     iOptionList.dwOptionCount   = 3;
 294     iOptionList.pOptions        = iOptions;
 295
 296     // set proxy type direct or proxy server
 297     iOptions[0].dwOption    = INTERNET_PER_CONN_FLAGS;
 298     iOptions[1].dwOption    = INTERNET_PER_CONN_PROXY_SERVER;
 299     iOptions[2].dwOption    = INTERNET_PER_CONN_PROXY_BYPASS;
 300
 301     if(InternetQueryOption(NULL,INTERNET_OPTION_PER_CONNECTION_OPTION ,(LPVOID)(&iOptionList),&uSize))
 302     {
 303         GlobalFree(iOptionList.pOptions[1].Value.pszValue);
 304         GlobalFree(iOptionList.pOptions[2].Value.pszValue);
 305     }
 306 }
 307
 308 HWND CMainWnd::CreateBrowser()
 309 {
 310     HRESULT hr;
 311     IUnknown *pUnk = NULL;
 312     IOleObject *pObject = NULL;
 313
 314     if(!m_pBrowser)
 315     {
 316         GetProxyOption();
 317         hr = CoCreateInstance(CLSID_WebBrowser, NULL,
 318             CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER,
 319             IID_IUnknown, (LPVOID *)(&pUnk));
 320         if(FAILED(hr))
 321             return FALSE;
 322
 323         hr = pUnk->QueryInterface(IID_IOleObject, (LPVOID *)(&pObject));
 324         if(FAILED(hr))
 325             goto Cleanup;
 326
 327         DWORD dwFlags;
 328         hr = pObject->GetMiscStatus(DVASPECT_CONTENT, &dwFlags);
 329         if(FAILED(hr))
 330             goto Cleanup;
 331
 332         if(dwFlags & OLEMISC_SETCLIENTSITEFIRST)
 333         {
 334             IOleClientSite *pClientSite;
 335             hr = QueryInterface(IID_IOleClientSite, (LPVOID *)(&pClientSite));
 336             if(FAILED(hr))
 337                 goto Cleanup;
 338
 339             hr = pObject->SetClientSite(pClientSite);
 340             pClientSite->Release();
 341             if(FAILED(hr))
 342                 goto Cleanup;
 343         }
 344
 345         hr = Activate(pObject);
 346         if(FAILED(hr))
 347             goto Cleanup;
 348
 349         hr = m_pObject->QueryInterface(IID_IWebBrowser2, (void **)&m_pBrowser);
 350         if(FAILED(hr))
 351             goto Cleanup;
 352
 353         // See if there might be a url in lpszUrl
 354         hr = pUnk->QueryInterface(IID_IOleInPlaceActiveObject, (LPVOID *)(&m_pIPActiveObj));
 355         if(FAILED(hr))
 356             m_pIPActiveObj = NULL;
 357
 358         hr = S_FALSE;
 359
 360         if(m_bEmpty)
 361         {
 362             // Leo Test: m_lpszUrl = L"http://www.baidu.com";
 363
 364             BSTR bstrURL = SysAllocString(m_lpszUrl);
 365             if(bstrURL && bstrURL[0])
 366                 m_pBrowser->Navigate(bstrURL, NULL, NULL, NULL, NULL);
 367             else
 368                 m_pBrowser->GoHome();
 369
 370             SysFreeString(bstrURL);
 371
 372         }
 373         hr = InitEvents();
 374     }
 375
 376 Cleanup:
 377     if(pUnk)
 378         pUnk->Release();
 379     if(pObject)
 380         pObject->Release();
 381
 382     IOleWindow *pWnd = NULL;
 383     HWND hwndBrowser = NULL;
 384
 385     if(m_pBrowser)
 386     {
 387         hr = m_pBrowser->QueryInterface(IID_IOleWindow, (LPVOID *)(&pWnd));
 388         if(FAILED(hr))
 389             return NULL;
 390     }
 391
 392     if(pWnd)
 393     {
 394         hr = pWnd->GetWindow(&hwndBrowser);
 395         pWnd->Release();
 396     }
 397     return hwndBrowser;
 398 }
 399
 400 HRESULT CMainWnd::Activate(IOleObject *pObject)
 401 {
 402     m_pObject = pObject;
 403     m_pObject->AddRef();
 404
 405     RECT rc;
 406     ::GetClientRect(m_hWndMain, &rc);
 407
 408     HRESULT hr;
 409     hr    =    m_pObject->DoVerb(   OLEIVERB_UIACTIVATE,    NULL,    this,    0,    m_hWndMain,    &rc);
 410
 411     if(FAILED(hr))
 412         goto Cleanup;
 413
 414 Cleanup:
 415     return hr;
 416 }
 417
 418 HRESULT CMainWnd::InitEvents()
 419 {
 420     HRESULT                     hr;
 421     IConnectionPointContainer  *pCPCont = NULL;
 422     DWebBrowserEvents          *pEvents = NULL;
 423
 424     if(!m_pBrowser)
 425         return S_FALSE;
 426     hr = m_pBrowser->QueryInterface(IID_IConnectionPointContainer, (LPVOID *)&pCPCont);
 427     if(FAILED(hr))
 428         return S_FALSE;
 429     hr = pCPCont->FindConnectionPoint(DIID_DWebBrowserEvents2, &m_pCP);
 430     if(FAILED(hr))
 431     {
 432         m_pCP = NULL;
 433         goto Cleanup;
 434     }
 435
 436     hr = QueryInterface(DIID_DWebBrowserEvents2, (LPVOID *)(&pEvents));
 437     if(FAILED(hr))
 438         goto Cleanup;
 439     hr = m_pCP->Advise(pEvents, &(m_dwEventCookie));
 440     if(FAILED(hr))
 441         goto Cleanup;
 442
 443
 444 Cleanup:
 445     if(pCPCont)
 446         pCPCont->Release();
 447     if(pEvents)
 448         pEvents->Release();
 449     return hr;
 450 }
 451
 452
 453
 454 HRESULT HandleNewWindow2(LPTSTR lpszUrl, DISPPARAMS FAR* pdparams)
 455 {
 456     HANDLE hThread;
 457     CMainWnd *pNewWnd;
 458     IDispatch *pDispatch;
 459     HRESULT hr = S_OK;
 460     DWORD dwThreadID = 0;
 461
 462     pNewWnd = new CMainWnd;
 463
 464     if(!pNewWnd)
 465     {
 466         return E_OUTOFMEMORY;
 467     }
 468
 469     pNewWnd->m_lpszUrl = lpszUrl;
 470     if(!pdparams)
 471         pNewWnd->m_bEmpty = TRUE;
 472
 473     pNewWnd->m_hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
 474
 475     if(!pNewWnd->m_hEvent)
 476     {
 477     }
 478
 479     InterlockedIncrement(&glThreadCount);
 480
 481     hThread = CreateThread(NULL, g_dwMainWindowStackSize, NewWindow, (LPVOID)pNewWnd, STACK_SIZE_PARAM_IS_A_RESERVATION, &dwThreadID);
 482     if(!hThread)
 483     {
 484         delete pNewWnd;
 485         InterlockedDecrement(&glThreadCount);
 486         return E_OUTOFMEMORY;
 487     }
 488     RETAILMSG(1,(L"[HandleNewWindow2]Create thread,ID is: 0x%x\r\n",dwThreadID));
 489
 490     WaitForSingleObject(pNewWnd->m_hEvent, INFINITE);
 491     CloseHandle(hThread);
 492     if(pdparams)
 493     {
 494         if(pNewWnd->m_pBrowser)
 495         {
 496             hr = pNewWnd->m_pBrowser->QueryInterface(IID_IDispatch, (LPVOID *)(&pDispatch));
 497         }
 498         else
 499         {
 500             hr = E_FAIL;
 501             pDispatch = NULL;
 502         }
 503
 504         *(pdparams->rgvarg[0].pboolVal) = 0;
 505         *(pdparams->rgvarg[1].ppdispVal) = pDispatch;
 506     }
 507     return hr;
 508 }
 509
 510
 511 STDMETHODIMP CMainWnd::GetHostInfo(DOCHOSTUIINFO *pInfo)
 512 {
 513
 514     pInfo->cbSize = sizeof(DOCHOSTUIINFO);
 515     //pInfo->dwFlags = DOCHOSTUIFLAG_NO3DBORDER|DOCHOSTUIFLAG_FLAT_SCROLLBAR;
 516     //pInfo->dwFlags |= DOCHOSTUIFLAG_SCROLL_NO;
 517
 518     return S_OK;
 519
 520 }
 521
 522 STDMETHODIMP CMainWnd::Invoke (
 523                                DISPID dispidMember,
 524                                REFIID riid,
 525                                LCID lcid,
 526                                WORD wFlags,
 527                                DISPPARAMS FAR* pdparams,
 528                                VARIANT FAR* pvarResult,
 529                                EXCEPINFO FAR* pexcepinfo,
 530                                UINT FAR* puArgErr
 531                                )
 532 {
 533     switch (dispidMember)
 534     {
 535     case DISPID_AMBIENT_DLCONTROL:
 536         if(pvarResult)
 537         {
 538             V_VT(pvarResult) = VT_I4;
 539             // always set these three unless they should be disabled
 540             pvarResult->lVal = DLCTL_DLIMAGES|DLCTL_VIDEOS|DLCTL_BGSOUNDS;
 541
 542             // put the browser in download only mode
 543             // pvarResult->lVal |= DLCTL_DOWNLOADONLY;
 544         }
 545         break;
 546
 547     case DISPID_STATUSTEXTCHANGE:
 548         {
 549         }
 550         break;
 551
 552     case DISPID_SETSECURELOCKICON:
 553         {
 554         }
 555         break;
 556
 557     case DISPID_PROGRESSCHANGE:
 558         {
 559             LONG lProgMax = pdparams->rgvarg[0].lVal;
 560             LONG lProg = pdparams->rgvarg[1].lVal;
 561             UINT nPos = (lProg == -1) ? 999 : ((lProg-1)%1000);
 562
 563             SendMessage(m_hWndProgress, PBM_SETPOS, nPos, 0);
 564         }
 565         break;
 566
 567         // notification for file download
 568     case DISPID_FILEDOWNLOAD:
 569         break;
 570
 571
 572     case DISPID_NAVIGATECOMPLETE2:
 573         break;
 574
 575     case DISPID_COMMANDSTATECHANGE:
 576         break;
 577
 578     case DISPID_TITLECHANGE:
 579         if(pdparams && pdparams->rgvarg[0].vt == VT_BSTR)
 580         {
 581             TCHAR szTitle[85];
 582             int len = wcslen(pdparams->rgvarg[0].bstrVal);
 583
 584             _tcsncpy(m_tcTitle, pdparams->rgvarg[0].bstrVal, MAX_URL-1);
 585             _tcsncpy(szTitle, pdparams->rgvarg[0].bstrVal, 80);
 586             if(len > 80)
 587                 _tcscat(szTitle, L"...");
 588
 589             SetWindowText(m_hWndMain, szTitle);
 590         }
 591         break;
 592
 593     case DISPID_ONQUIT:
 594         PostMessage(m_hWndMain, WM_CLOSE, 0, 0L);
 595         break;
 596
 597     case DISPID_DOWNLOADBEGIN:
 598         m_iDLCCounter++;
 599         SetWindowPos(m_hWndProgress, HWND_TOP, 0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_SHOWWINDOW);
 600         break;
 601     case DISPID_DOWNLOADCOMPLETE:
 602     case DISPID_DOCUMENTCOMPLETE:
 603         m_iDLCCounter--;
 604         if(m_iDLCCounter <= 0)
 605         {
 606             SetWindowPos(m_hWndProgress,NULL, 0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_HIDEWINDOW);
 607             ChangeFontSize(TRUE);
 608             m_iDLCCounter = 0;
 609         }
 610         break;
 611
 612     case DISPID_NEWWINDOW2:
 613         //pdparams->rgvarg[1].boolVal = VARIANT_TRUE;
 614         //break;
 615         return HandleNewWindow2(NULL, pdparams);
 616         break;
 617
 618
 619     case DISPID_PROPERTYCHANGE:
 620     case DISPID_BEFORENAVIGATE2:
 621         break;
 622     default:
 623         return DISP_E_MEMBERNOTFOUND;
 624     }
 625     return S_OK;
 626 }
 627
 628
 629 STDMETHODIMP CMainWnd::moveTo( LONG x, LONG y)
 630 {
 631     SetWindowPos(m_hWndMain, NULL, x, y, 0, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE);
 632     return S_OK;
 633 }
 634
 635 STDMETHODIMP CMainWnd::moveBy( LONG x, LONG y)
 636 {
 637     RECT rcWindow;
 638
 639     GetWindowRect(m_hWndMain, &rcWindow);
 640
 641     SetWindowPos(m_hWndMain, NULL, rcWindow.left + x, rcWindow.top + y, 0, 0,
 642         SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE);
 643     return S_OK;
 644 }
 645
 646
 647 STDMETHODIMP CMainWnd::resizeTo( LONG x, LONG y)
 648 {
 649     // We do not want the size to be less then 100 for top level windows in browser
 650     if(x < 100)
 651         x = 100;
 652
 653     if(y < 100)
 654         y = 100;
 655
 656     SetWindowPos(m_hWndMain, NULL, 0, 0, x, y, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
 657
 658     return S_OK;
 659 }
 660
 661 STDMETHODIMP CMainWnd::resizeBy( LONG x, LONG y)
 662 {
 663     RECT rcWindow;
 664     long w, h;
 665
 666     GetWindowRect(m_hWndMain, &rcWindow);
 667
 668     w = rcWindow.right - rcWindow.left + x;
 669     h = rcWindow.bottom - rcWindow.top + y;
 670
 671     if(w < 100)
 672         w = 100;
 673
 674     if(h < 100)
 675         h = 100;
 676
 677     SetWindowPos(m_hWndMain, NULL, 0, 0, w, h, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
 678     return S_OK;
 679 }
 680
 681
 682 EXTERN_C const GUID CGID_MSHTML;
 683 extern "C" BOOL APIENTRY OpenURLDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam);
 684
 685 LRESULT CMainWnd::HandleCommand(WPARAM wParam, LPARAM lParam)
 686 {
 687     UINT nID = LOWORD(wParam);
 688     switch (nID)
 689     {
 690     case ID_INTERNET_OPTIONS:
 691         {
 692             SHELLEXECUTEINFO sei;
 693             sei.cbSize = sizeof(sei);
 694             sei.fMask = SEE_MASK_FLAG_NO_UI;
 695             sei.hwnd = m_hWndMain;
 696             sei.lpVerb = NULL;
 697             sei.lpFile = L"ctlpnl";
 698             sei.lpParameters = L"inetcpl.cpl";
 699             sei.lpDirectory = NULL;
 700             sei.nShow = SW_SHOWNORMAL;
 701
 702             ShellExecuteEx(&sei);
 703         }
 704         break;
 705     case ID_FIND:
 706         FindString();
 707         break;
 708     case ID_GO_BACK:
 709         m_pBrowser->GoBack();
 710         return 0;
 711     case ID_GO_FORWARD:
 712         m_pBrowser->GoForward();
 713         return 0;
 714     case ID_GO_HOME:
 715         m_pBrowser->GoHome();
 716         return 0;
 717     case ID_GO_SEARCH:
 718         m_pBrowser->GoSearch();
 719         return 0;
 720     case ID_VIEW_REFRESH:
 721         m_pBrowser->Refresh();
 722         return 0;
 723     case ID_VIEW_STOP:
 724         m_pBrowser->Stop();
 725         return 0;
 726
 727     case ID_ZOOMUP:
 728         m_iZoom++;
 729         if(m_iZoom > 4)
 730             m_iZoom = 4;
 731         ChangeFontSize(FALSE);
 732         return 0;
 733
 734     case ID_ZOOMDOWN:
 735         m_iZoom--;
 736         if(m_iZoom < 0)
 737             m_iZoom = 0;
 738         ChangeFontSize(FALSE);
 739         return 0;
 740     case ID_CLOSE:
 741         m_pBrowser->ExecWB(OLECMDID_CLOSE, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
 742         return 0;
 743     case ID_FOCUS_URL:
 744     case ID_OPEN:
 745         {
 746             WCHAR *szURL = new TCHAR[MAX_URL];
 747             if(szURL)
 748             {
 749                 int nRet = 0;
 750                 BSTR bstrURL = NULL;
 751                 m_pBrowser->get_LocationURL(&bstrURL);
 752                 nRet = StringCchCopy(szURL, MAX_URL, (LPCTSTR)bstrURL);
 753                 SysFreeString(bstrURL);
 754
 755                 nRet =  DialogBoxParam(g_hInstance, MAKEINTRESOURCE(IDD_OPEN_DIALOG), m_hWndMain, OpenURLDlgProc, (long)szURL);
 756                 bstrURL = SysAllocString(szURL);
 757                 if(nRet == 1)
 758                 {
 759                     m_pBrowser->Navigate(bstrURL, NULL, NULL, NULL, NULL);
 760                 }
 761                 else if(nRet == 2)
 762                 {
 763                     HandleNewWindow2(bstrURL,NULL);
 764                 }
 765                 SysFreeString(bstrURL);
 766                 delete[] szURL;
 767             }
 768         }
 769         return 0;
 770     case ID_FULLSCREEN:
 771         {
 772             DWORD dwStyle = GetWindowLong(m_hWndMain, GWL_STYLE);
 773             if(m_bFullScreen)
 774             {
 775                 dwStyle |= (WS_OVERLAPPED | WS_SYSMENU | WS_THICKFRAME);
 776                 SetWindowLong(m_hWndMain, GWL_STYLE, dwStyle);
 777                 SetWindowPos(m_hWndMain,NULL,  m_rcWnd.left, m_rcWnd.top, m_rcWnd.right-m_rcWnd.left, m_rcWnd.bottom-m_rcWnd.top, SWP_NOZORDER);
 778                 m_bFullScreen = FALSE;
 779             }
 780             else
 781             {
 782                 RECT rcWorkArea;
 783
 784                 SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWorkArea, 0);
 785                 m_bFullScreen = TRUE;
 786                 dwStyle &= ~(WS_OVERLAPPED | WS_SYSMENU | WS_THICKFRAME);
 787
 788                 SetWindowLong(m_hWndMain, GWL_STYLE, dwStyle);
 789                 SetWindowPos(m_hWndMain,NULL,  rcWorkArea.left, rcWorkArea.top, rcWorkArea.right-rcWorkArea.left, rcWorkArea.bottom-rcWorkArea.top, SWP_NOZORDER);
 790
 791             }
 792         }
 793         return 0;
 794     }
 795     return 0;
 796 }
 797
 798
 799
 800
 801
 802 EXTERN_C const GUID CGID_ShellDocView;
 803
 804 LRESULT CALLBACK CMainWnd::MainWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 805 {
 806     CMainWnd *pMainWnd = (CMainWnd*)GetWindowLong(hwnd, GWL_USERDATA);
 807
 808     if(pMainWnd)
 809     {
 810         switch (message)
 811         {
 812         case WM_CLOSE:
 813         case WM_DESTROY:
 814             if(pMainWnd)
 815                 pMainWnd->Close();
 816             SetWindowLong(hwnd, GWL_USERDATA, (DWORD)0);
 817             ::PostQuitMessage(0);
 818             break;
 819         case WM_SETFOCUS:
 820             if(pMainWnd->m_pIPActiveObj)
 821             {
 822                 pMainWnd->m_pIPActiveObj->OnFrameWindowActivate(LOWORD(wParam) != WA_INACTIVE);
 823             }
 824             return 0;
 825         case WM_SIZE:
 826             {
 827                 RECT rcWnd;
 828                 GetClientRect(hwnd, &rcWnd);
 829                 SetWindowPos(pMainWnd->m_hWndBrowser,
 830                     NULL,
 831                     0,
 832                     0,
 833                     rcWnd.right-rcWnd.left,
 834                     rcWnd.bottom - rcWnd.top,
 835                     SWP_NOZORDER);
 836             }
 837             // FALL THROUGH
 838         case  WM_MOVE:
 839             if(!pMainWnd->m_bFullScreen)
 840                 GetWindowRect(hwnd, &pMainWnd->m_rcWnd);
 841             break;
 842         case WM_COMMAND:
 843             return pMainWnd->HandleCommand(wParam, lParam);
 844             break;
 845
 846         case WM_NOTIFY:
 847             break;
 848
 849         case WM_INITMENUPOPUP:
 850             break;
 851
 852         case WM_SETTINGCHANGE:
 853             if(wParam == SPI_SETWORKAREA)
 854             {
 855                 if(pMainWnd->m_bFullScreen)
 856                 {
 857                     RECT rcWorkArea;
 858                     // no need to change the window style here, just adjust for the new work-area.
 859                     SystemParametersInfo(SPI_GETWORKAREA, 0, &rcWorkArea, 0);
 860                     SetWindowPos(pMainWnd->m_hWndMain,NULL,  rcWorkArea.left, rcWorkArea.top, rcWorkArea.right-rcWorkArea.left, rcWorkArea.bottom-rcWorkArea.top, SWP_NOZORDER);
 861                 }
 862             }
 863             break;
 864         default:
 865             break;
 866         }
 867     }
 868     return DefWindowProc(hwnd, message, wParam, lParam);
 869 }
 870
 871 BOOL CMainWnd::PreTranslateMessage(LPMSG pMsg)
 872 {
 873     if(::TranslateAccelerator(m_hWndMain, m_hAccelTbl, pMsg))  //first shot to the main frame
 874         return TRUE;
 875
 876     //then to mshtml
 877     if(m_pIPActiveObj && pMsg->message >= WM_KEYFIRST && pMsg->message <= WM_KEYLAST)
 878     {
 879         HRESULT hr = m_pIPActiveObj->TranslateAccelerator(pMsg);
 880         return (hr != S_FALSE);
 881     }
 882     return FALSE;
 883 }
 884
 885 VOID CMainWnd::ChangeFontSize(BOOL fInit)
 886 {
 887     VARIANT vaSize;
 888     vaSize.vt = VT_I4;
 889
 890     if(fInit) {
 891         // Setting initial value
 892         vaSize.vt = 0;
 893         HRESULT hr = m_pBrowser->ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
 894             NULL, &vaSize);
 895         m_iZoom = vaSize.lVal;
 896     } else {
 897         vaSize.lVal = m_iZoom;
 898         HRESULT hr = m_pBrowser->ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
 899             &vaSize, NULL);
 900     }
 901 }
 902
 903 VOID CMainWnd::Close()
 904 {
 905     RETAILMSG(1,(L"IESIMPLE CMainWnd::Close"));
 906
 907     // Tell the shell to die off
 908     SendMessage(m_hWndBrowser, WM_CLOSE, 0,0);
 909
 910
 911     if(m_pIPActiveObj)
 912     {
 913         m_pIPActiveObj->Release();
 914     }
 915     m_pIPActiveObj = NULL;
 916     if(m_pCP)
 917     {
 918         m_pCP->Unadvise(m_dwEventCookie);
 919         m_pCP->Release();
 920     }
 921     m_pCP = NULL;
 922     if(m_pObject)
 923     {
 924         m_pObject->Close(FALSE);
 925         m_pObject->Release();
 926     }
 927     m_pObject = NULL;
 928     if(m_pBrowser)
 929         m_pBrowser->Release();
 930     m_pBrowser = NULL;
 931
 932 }
 933
 934
 935
 936
 937 HRESULT CMainWnd::FindString()
 938 {
 939     LPDISPATCH pDisp = NULL;
 940     LPOLECOMMANDTARGET pCmdTarg = NULL;
 941     HRESULT sts = S_OK;
 942     VARIANTARG var;
 943
 944 #define GOERROR_S(bNotCond)  {if(!(bNotCond)) goto errorS; }
 945
 946     if(!m_pBrowser)
 947         return S_OK;
 948     sts = m_pBrowser->get_Document(&pDisp);
 949     GOERROR_S(pDisp);
 950     sts = pDisp->QueryInterface(IID_IOleCommandTarget, (LPVOID*)&pCmdTarg);
 951     GOERROR_S(pCmdTarg);
 952
 953     var.vt   = VT_I4;
 954     var.lVal = 0;
 955     sts = pCmdTarg->Exec(
 956         NULL,
 957         OLECMDID_FIND,
 958         MSOCMDEXECOPT_PROMPTUSER,
 959         NULL,
 960         &var);
 961
 962 errorS:
 963     if(pCmdTarg)
 964         pCmdTarg->Release(); // release document‘s command target
 965     if(pDisp)
 966         pDisp->Release();    // release document‘s dispatch interface
 967     return sts;
 968 }
 969
 970
 971
 972
 973 BOOL HandleBrowse(HWND hwndOwner, WCHAR *szURL);
 974
 975 extern "C" BOOL APIENTRY OpenURLDlgProc (HWND hDlg, UINT message, UINT wParam, LONG lParam)
 976 {
 977
 978     WCHAR *szURL = (WCHAR *)GetWindowLong(hDlg,DWL_USER);
 979     int         nRet = 4;
 980
 981     switch(message)
 982     {
 983
 984     case WM_INITDIALOG:
 985         {
 986             if(!lParam)
 987             {
 988                 EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
 989                 EnableWindow(GetDlgItem(hDlg, IDC_BROWSE), FALSE);
 990             }
 991             else
 992             {
 993                 szURL = (WCHAR *)lParam;
 994                 SetWindowLong(hDlg, DWL_USER, (LONG)szURL);
 995                 SendMessage(GetDlgItem(hDlg, IDC_URL_EDIT), EM_LIMITTEXT, MAX_URL-1, 0);
 996                 if(szURL[0])
 997                 {
 998
 999                     SetDlgItemText(hDlg, IDC_URL_EDIT, szURL);
1000                 }
1001             }
1002
1003         }
1004         return TRUE;
1005
1006     case WM_COMMAND:
1007         switch (LOWORD(wParam))
1008         {
1009
1010         case IDOK:
1011             {
1012                 GetDlgItemText(hDlg, IDC_URL_EDIT, szURL, MAX_URL-1);
1013                 BOOL bNewWnd = SendMessage(GetDlgItem(hDlg, IDC_NEWWINDOW), BM_GETCHECK, 0L, 0L);
1014                 nRet = (bNewWnd) ? 2 : 1;
1015             }
1016         case IDCANCEL:
1017             EndDialog(hDlg, nRet);
1018             return TRUE;
1019
1020
1021         case IDC_BROWSE:
1022             if(HandleBrowse(hDlg, szURL))
1023             {
1024                 SetDlgItemText(hDlg, IDC_URL_EDIT, szURL);
1025             }
1026
1027         default:
1028             return (TRUE);
1029         }
1030         break;
1031
1032     case WM_DESTROY:
1033         SetWindowLong(hDlg, DWL_USER, 0);
1034         break;
1035
1036     }
1037     return (FALSE);
1038
1039
1040 }
1041
1042
1043 extern HINSTANCE   g_hInstance;
1044 BOOL HandleBrowse(HWND hwndOwner, WCHAR *szURL)
1045 {
1046
1047     OPENFILENAME    ofn;
1048     WCHAR           wchFilter[MAX_PATH];
1049     WCHAR           wchFile[MAX_PATH+8];
1050     int             cbLen;
1051
1052
1053     // Initialize ofn struct
1054     memset(&ofn, 0, sizeof(ofn));
1055     ofn.lStructSize     = sizeof(ofn);
1056     ofn.hwndOwner       = hwndOwner;
1057     ofn.Flags           = OFN_FILEMUSTEXIST |
1058         OFN_PATHMUSTEXIST   |
1059         OFN_OVERWRITEPROMPT |
1060         OFN_HIDEREADONLY;
1061
1062     cbLen = LoadString(g_hInstance, IDS_BROWSEFILTER,
1063         wchFilter, MAX_PATH-2);
1064
1065     if(cbLen>0)
1066     {
1067         for (; cbLen >= 0; cbLen--)
1068         {
1069             if(wchFilter[cbLen]== L‘@‘)
1070             {
1071                 wchFilter[cbLen] = 0;
1072             }
1073         }
1074     }
1075     else
1076     {
1077         return FALSE;
1078     }
1079
1080
1081     ofn.lpstrFilter = wchFilter;
1082     ofn.nFilterIndex = 1;
1083     wcscpy(wchFile, L"file://");
1084
1085     ofn.lpstrFile = wchFile+wcslen(wchFile);  // prefix the string with "file://"
1086     ofn.nMaxFile = MAX_PATH;
1087     if(GetOpenFileName(&ofn))
1088     {
1089         wcsncpy(szURL, wchFile, MAX_URL-1);
1090         return TRUE;
1091     }
1092
1093     return FALSE;
1094
1095 }  
时间: 2024-10-11 00:31:11

IE 实现代码示例的相关文章

计算DXFReader中多边形的面积代码示例

在DXFReader中, 一般的多边形的面积计算绝对值 其中K表是顶点的数目,它们的坐标,用于在求和和, 所以用下面的代码就可以计算出一个封闭的多段线的区域: view source print? 01 Dim Vertex As Object 02 Dim Entity As Object 03 Dim k As Long 04 Dim i As Long 05 Dim Area As Single 06 07 With DXFReader1 08 09  For Each Entity In

代码示例:一些简单技巧优化JavaScript编译器工作详解,让你写出高性能运行的更快JavaScript代码

告诉你一些简单的技巧来优化JavaScript编译器工作,从而让你的JavaScript代码运行的更快.尤其是在你游戏中发现帧率下降或是当垃圾回收器有大量的工作要完成的时候. 单一同态: 当你定义了一个两个参数的函数,编译器会接受你的定义,如果函数参数的类型.个数或者返回值的类型改变编译器的工作会变得艰难.通常情况下,单一同态的数据结构和个数相同的参数会让你的程序会更好的工作. function example(a, b) { // 期望a,b都为数值类型 console.log(++a * +

jquery操作单选钮代码示例

jquery操作单选钮代码示例:radio单选按钮是最重要的表单元素之一,下面介绍一下常用的几个jquery对radio单选按钮操作.一.取消选中: $(".theclass").each(function(){ if($(this).attr('checked')) { $(this).attr('checked',false); } }); 以上代码可以将class属性值为theclass的被选中单选按钮取消选中.二.获取被选中的单选按钮的值: var val=$('.thecla

Python实现各种排序算法的代码示例总结

Python实现各种排序算法的代码示例总结 作者:Donald Knuth 字体:[增加 减小] 类型:转载 时间:2015-12-11我要评论 这篇文章主要介绍了Python实现各种排序算法的代码示例总结,其实Python是非常好的算法入门学习时的配套高级语言,需要的朋友可以参考下 在Python实践中,我们往往遇到排序问题,比如在对搜索结果打分的排序(没有排序就没有Google等搜索引擎的存在),当然,这样的例子数不胜数.<数据结构>也会花大量篇幅讲解排序.之前一段时间,由于需要,我复习了

领域驱动开发推荐代码示例 — Microsoft NLayerApp

简介: Microsoft NLayerApp是由微软西班牙团队出品的基于.NET 4.0的“面向领域N层分布式架构”代码示例,在codeplex上的地址是:http://microsoftnlayerapp.codeplex.com/. 架构图: 点击查看大图 代码下载:http://microsoftnlayerapp.codeplex.com/releases/view/56660 所用到的软件: - Microsoft Visual Studio 2010  - Microsoft Ex

Aspectj快速上手代码示例之Before,After,Around

本文不打算解释AOP的相关专业名词和概念,仅通过几个代码示例来展示Aspectj(对AOP实现的)的基本使用,并且使用的Aspectj是目前最新版本. 1.搭建环境 本文使用Maven来构建工程,通过aspectj-maven-plugin插件来编译*.aj文件至.class. Maven的具体配置: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>aspectj-maven-plugin&

jxl创建Excel文件java代码示例

记得要下载 并 导入 jxl.jar 包,免积分下载地址:http://download.csdn.net/detail/u010011052/7561041 package Test; import java.io.*; import jxl.*; import jxl.format.Colour; import jxl.write.*; public class JXLTest { private static WritableWorkbook book; private static Wr

java 翻盖hashCode()深入探讨 代码示例

package org.rui.collection2.hashcode; /** * 覆盖hashcode * 设计HashCode时最重要的因素 就是:无论何时,对同一个对象调用HashCode都应该产生同样的值, * 如果你的HashCode方法依赖于对象中易变的数据,用户就要当心了,因为此数据发生变化 时 * HashCode就会生成一个不同的散列码,相当于产生一个不同的健 * 此外 也不应该使HashCode依赖于具有唯一性的对象信息,尤其是使用this的值,这只能很糟糕, * 因为这

python 之初学者的代码示例(短小精悍)(一)

学习Python也有个把月了,最近整理自己初学的代码示例,一个是为了增加自己对细节的把握,一个是让像我一样的初学者能够熟练地使用基础,基础的重要性就不说了,我希望自己能够把这些精巧的小而短的示例分享给大家,共同进步 #help(execfile) Help on built-in function execfile in module __builtin__: execfile(...) execfile(filename[, globals[, locals]]) Read and execu

Unity构造函数注入代码示例

Unity构造函数注入代码示例 如果使用 Unity 实例化一个类,该类的构造函数依赖一个或多个其他类,则 Unity 会为构造函数自动创建参数中指定的被依赖的类的实例.例如,下面的代码展示了一个名为 "CustomerService" 的类,其构造函数的入参依赖于一个名为 "LoggingService" 的类. public class CustomerService { public CustomerService(LoggingService log) {