1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
|
// Win32++ Version 7.2
// Released: 5th AUgust 2011
//
// David Nash
// email: dnash@bigpond.net.au
// url: https://sourceforge.net/projects/win32-framework
//
//
// Copyright (c) 2005-2011 David Nash
//
// Permission is hereby granted, free of charge, to
// any person obtaining a copy of this software and
// associated documentation files (the "Software"),
// to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify,
// merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom
// the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice
// shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
// ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
//
////////////////////////////////////////////////////////
#ifndef _WIN32XX_WEBBROWSER_H_
#define _WIN32XX_WEBBROWSER_H_
#include <exdisp.h>
#include <ocidl.h>
namespace Win32xx
{
///////////////////////////////////////////////////
// Declaration of the CAXWindow class
// This class implements an ActiveX control container
class CAXWindow : public IOleClientSite, public IOleInPlaceSite, public IOleInPlaceFrame,
public IOleControlSite, public IDispatch
{
public:
CAXWindow();
virtual ~CAXWindow();
virtual void Activate(BOOL fFocus);
virtual void CreateControl(BSTR bstrClsid);
virtual void CreateControl(CLSID clsid);
virtual void Remove();
virtual void SetParent(HWND hWndParent);
virtual void SetLocation(int x, int y, int width, int height);
virtual void SetVisible(BOOL fVisible);
virtual void SetStatusWindow(HWND hWndStatus);
virtual void TranslateKey(MSG msg);
IDispatch* GetDispatch();
IUnknown* GetUnknown();
// IUnknown Methods
STDMETHODIMP QueryInterface(REFIID riid, void** ppvObject);
STDMETHODIMP_(ULONG) AddRef();
STDMETHODIMP_(ULONG) Release();
// IOleClientSite Methods
STDMETHODIMP SaveObject();
STDMETHODIMP GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, LPMONIKER* ppMk);
STDMETHODIMP GetContainer(LPOLECONTAINER* ppContainer);
STDMETHODIMP ShowObject();
STDMETHODIMP OnShowWindow(BOOL fShow);
STDMETHODIMP RequestNewObjectLayout();
// IOleWindow Methods
STDMETHODIMP GetWindow(HWND* phwnd);
STDMETHODIMP ContextSensitiveHelp(BOOL fEnterMode);
// IOleInPlaceSite Methods
STDMETHODIMP CanInPlaceActivate();
STDMETHODIMP OnInPlaceActivate();
STDMETHODIMP OnUIActivate();
STDMETHODIMP GetWindowContext(IOleInPlaceFrame** ppFrame, IOleInPlaceUIWindow** ppDoc, LPRECT lprcPosRect, LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo);
STDMETHODIMP Scroll(SIZE scrollExtent);
STDMETHODIMP OnUIDeactivate(BOOL fUndoable);
STDMETHODIMP OnInPlaceDeactivate();
STDMETHODIMP DiscardUndoState();
STDMETHODIMP DeactivateAndUndo();
STDMETHODIMP OnPosRectChange(LPCRECT lprcPosRect);
// IOleInPlaceUIWindow Methods
STDMETHODIMP GetBorder(LPRECT lprectBorder);
STDMETHODIMP RequestBorderSpace(LPCBORDERWIDTHS lpborderwidths);
STDMETHODIMP SetBorderSpace(LPCBORDERWIDTHS lpborderwidths);
STDMETHODIMP SetActiveObject(IOleInPlaceActiveObject* pActiveObject, LPCOLESTR lpszObjName);
// IOleInPlaceFrame Methods
STDMETHODIMP InsertMenus(HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths);
STDMETHODIMP SetMenu(HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject);
STDMETHODIMP RemoveMenus(HMENU hmenuShared);
STDMETHODIMP SetStatusText(LPCOLESTR pszStatusText);
STDMETHODIMP EnableModeless(BOOL fEnable);
STDMETHODIMP TranslateAccelerator(LPMSG lpmsg, WORD wID);
// IOleControlSite Methods
STDMETHODIMP OnControlInfoChanged();
STDMETHODIMP LockInPlaceActive(BOOL fLock);
STDMETHODIMP GetExtendedControl(IDispatch** ppDisp);
STDMETHODIMP TransformCoords(POINTL* pptlHimetric, POINTF* pptfContainer, DWORD dwFlags);
STDMETHODIMP TranslateAccelerator(LPMSG pMsg, DWORD grfModifiers);
STDMETHODIMP OnFocus(BOOL fGotFocus);
STDMETHODIMP ShowPropertyFrame();
// IDispatch Methods
STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames, unsigned int cNames, LCID lcid, DISPID* rgdispid);
STDMETHODIMP GetTypeInfo(unsigned int itinfo, LCID lcid, ITypeInfo** pptinfo);
STDMETHODIMP GetTypeInfoCount(unsigned int* pctinfo);
STDMETHODIMP Invoke(DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexecinfo, unsigned int* puArgErr);
private:
ULONG m_cRefs; // ref count
HWND m_hWnd; // window handle of the container
HWND m_hWndStatus; // status window handle
IUnknown* m_pUnk; // IUnknown of contained object
CRect m_rcControl; // size of control
};
///////////////////////////////////////////////
// Declaration of the CWebBrowser class
// This class uses an AciveX Container provided by
// CAXWindow to host the IWebBrower2 interface.
class CWebBrowser : public CWnd
{
public:
CWebBrowser();
virtual ~CWebBrowser();
virtual void AddWebBrowserControl(void);
virtual CAXWindow& GetAXWindow() const { return (CAXWindow&)m_AXContainer; }
virtual IWebBrowser2* GetIWebBrowser2() const { return m_pIWebBrowser2; }
virtual void Navigate(LPCTSTR str);
protected:
virtual void OnCreate();
virtual void OnSize(int width, int height);
virtual LRESULT WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam);
private:
CAXWindow m_AXContainer; // The ActiveX Container
IWebBrowser2* m_pIWebBrowser2;// Interface to the ActiveX web browser control
};
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
namespace Win32xx
{
/////////////////////////////////////////
// Definitions for the CAXWindow class
//
inline CAXWindow::CAXWindow() : m_cRefs(1), m_hWnd(NULL), m_pUnk(NULL)
{
}
inline CAXWindow::~CAXWindow()
{
}
inline void CAXWindow::CreateControl(BSTR bstrClsid)
{
CLSID clsid;
CLSIDFromString(bstrClsid, &clsid);
CreateControl(clsid);
}
inline void CAXWindow::Activate(BOOL fFocus)
{
if (!m_pUnk)
return;
if (fFocus)
{
IOleObject* pioo;
HRESULT hr = m_pUnk->QueryInterface(IID_IOleObject, (void**)&pioo);
if (FAILED(hr))
return;
pioo->DoVerb(OLEIVERB_UIACTIVATE, NULL, this, 0, m_hWnd, &m_rcControl);
pioo->Release();
}
}
inline void CAXWindow::CreateControl(CLSID clsid)
{
CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IUnknown, (void**)&m_pUnk);
if (!m_pUnk)
return;
IOleObject* pioo;
HRESULT hr = m_pUnk->QueryInterface(IID_IOleObject, (void**)&pioo);
if (FAILED(hr))
return;
pioo->SetClientSite(this);
pioo->Release();
IPersistStreamInit* ppsi;
hr = m_pUnk->QueryInterface(IID_IPersistStreamInit, (void**)&ppsi);
if (SUCCEEDED(hr))
{
ppsi->InitNew();
ppsi->Release();
}
}
inline STDMETHODIMP_(ULONG) CAXWindow::AddRef()
{
return ++m_cRefs;
}
inline STDMETHODIMP CAXWindow::CanInPlaceActivate()
{
return S_OK;
}
inline STDMETHODIMP CAXWindow::ContextSensitiveHelp(BOOL fEnterMode)
{
UNREFERENCED_PARAMETER(fEnterMode);
return E_NOTIMPL;
}
inline STDMETHODIMP CAXWindow::DeactivateAndUndo()
{
return E_NOTIMPL;
}
inline STDMETHODIMP CAXWindow::DiscardUndoState()
{
return E_NOTIMPL;
}
inline STDMETHODIMP CAXWindow::EnableModeless(BOOL fEnable)
{
UNREFERENCED_PARAMETER(fEnable);
return E_NOTIMPL;
}
inline STDMETHODIMP CAXWindow::GetBorder(LPRECT lprectBorder)
{
UNREFERENCED_PARAMETER(lprectBorder);
return E_NOTIMPL;
}
inline STDMETHODIMP CAXWindow::GetContainer(LPOLECONTAINER* ppContainer)
{
UNREFERENCED_PARAMETER(ppContainer);
return E_NOINTERFACE;
}
inline IDispatch* CAXWindow::GetDispatch()
{
if (!m_pUnk)
return NULL;
HRESULT hr;
IDispatch* pdisp;
hr = m_pUnk->QueryInterface(IID_IDispatch, (void**)&pdisp);
return pdisp;
}
inline STDMETHODIMP CAXWindow::GetExtendedControl(IDispatch** ppDisp)
{
if (ppDisp == NULL)
return E_INVALIDARG;
*ppDisp = (IDispatch*)this;
(*ppDisp)->AddRef();
return S_OK;
}
inline STDMETHODIMP CAXWindow::GetIDsOfNames(REFIID riid, OLECHAR** rgszNames, unsigned int cNames, LCID lcid, DISPID* rgdispid)
{
UNREFERENCED_PARAMETER((IID)riid); // IID cast required for the MinGW compiler
UNREFERENCED_PARAMETER(rgszNames);
UNREFERENCED_PARAMETER(cNames);
UNREFERENCED_PARAMETER(lcid);
*rgdispid = DISPID_UNKNOWN;
return DISP_E_UNKNOWNNAME;
}
inline STDMETHODIMP CAXWindow::GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, LPMONIKER* ppMk)
{
UNREFERENCED_PARAMETER(dwAssign);
UNREFERENCED_PARAMETER(dwWhichMoniker);
UNREFERENCED_PARAMETER(ppMk);
return E_NOTIMPL;
}
inline STDMETHODIMP CAXWindow::GetTypeInfo(unsigned int itinfo, LCID lcid, ITypeInfo** pptinfo)
{
UNREFERENCED_PARAMETER(itinfo);
UNREFERENCED_PARAMETER(lcid);
UNREFERENCED_PARAMETER(pptinfo);
return E_NOTIMPL;
}
inline STDMETHODIMP CAXWindow::GetTypeInfoCount(unsigned int* pctinfo)
{
UNREFERENCED_PARAMETER(pctinfo);
return E_NOTIMPL;
}
inline IUnknown* CAXWindow::GetUnknown()
{
if (!m_pUnk)
return NULL;
m_pUnk->AddRef();
return m_pUnk;
}
inline STDMETHODIMP CAXWindow::GetWindow(HWND* lphwnd)
{
if (!IsWindow(m_hWnd))
return S_FALSE;
*lphwnd = m_hWnd;
return S_OK;
}
inline STDMETHODIMP CAXWindow::GetWindowContext (IOleInPlaceFrame** ppFrame, IOleInPlaceUIWindow** ppIIPUIWin,
LPRECT lprcPosRect, LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
{
*ppFrame = (IOleInPlaceFrame*)this;
*ppIIPUIWin = NULL;
RECT rect;
GetClientRect(m_hWnd, &rect);
lprcPosRect->left = 0;
lprcPosRect->top = 0;
lprcPosRect->right = rect.right;
lprcPosRect->bottom = rect.bottom;
CopyRect(lprcClipRect, lprcPosRect);
lpFrameInfo->cb = sizeof(OLEINPLACEFRAMEINFO);
lpFrameInfo->fMDIApp = FALSE;
lpFrameInfo->hwndFrame = m_hWnd;
lpFrameInfo->haccel = 0;
lpFrameInfo->cAccelEntries = 0;
(*ppFrame)->AddRef();
return S_OK;
}
inline STDMETHODIMP CAXWindow::InsertMenus(HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths)
{
UNREFERENCED_PARAMETER(hmenuShared);
UNREFERENCED_PARAMETER(lpMenuWidths);
return E_NOTIMPL;
}
inline STDMETHODIMP CAXWindow::Invoke(DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult, EXCEPINFO* pexecinfo, unsigned int* puArgErr)
{
UNREFERENCED_PARAMETER(dispid);
UNREFERENCED_PARAMETER((IID)riid); // IID cast required for the MinGW compiler
UNREFERENCED_PARAMETER(lcid);
UNREFERENCED_PARAMETER(wFlags);
UNREFERENCED_PARAMETER(pdispparams);
UNREFERENCED_PARAMETER(pvarResult);
UNREFERENCED_PARAMETER(pexecinfo);
UNREFERENCED_PARAMETER(puArgErr);
return DISP_E_MEMBERNOTFOUND;
}
inline STDMETHODIMP CAXWindow::LockInPlaceActive(BOOL fLock)
{
UNREFERENCED_PARAMETER(fLock);
return E_NOTIMPL;
}
inline STDMETHODIMP CAXWindow::OnControlInfoChanged()
{
return E_NOTIMPL;
}
inline STDMETHODIMP CAXWindow::OnFocus(BOOL fGotFocus)
{
UNREFERENCED_PARAMETER(fGotFocus);
return E_NOTIMPL;
}
inline STDMETHODIMP CAXWindow::OnInPlaceActivate()
{
return S_OK;
}
inline STDMETHODIMP CAXWindow::OnInPlaceDeactivate()
{
return S_OK;
}
inline STDMETHODIMP CAXWindow::OnPosRectChange(LPCRECT lprcPosRect)
{
UNREFERENCED_PARAMETER(lprcPosRect);
return S_OK;
}
inline STDMETHODIMP CAXWindow::OnShowWindow(BOOL fShow)
{
UNREFERENCED_PARAMETER(fShow);
return S_OK;
}
inline STDMETHODIMP CAXWindow::OnUIActivate()
{
return S_OK;
}
inline STDMETHODIMP CAXWindow::OnUIDeactivate(BOOL fUndoable)
{
UNREFERENCED_PARAMETER(fUndoable);
return E_NOTIMPL;
}
inline STDMETHODIMP CAXWindow::QueryInterface(REFIID riid, void** ppvObject)
{
if (!ppvObject)
return E_POINTER;
if (IsEqualIID(riid, IID_IOleClientSite))
*ppvObject = (IOleClientSite*)this;
else if (IsEqualIID(riid, IID_IOleInPlaceSite))
*ppvObject = (IOleInPlaceSite*)this;
else if (IsEqualIID(riid, IID_IOleInPlaceFrame))
*ppvObject = (IOleInPlaceFrame*)this;
else if (IsEqualIID(riid, IID_IOleInPlaceUIWindow))
*ppvObject = (IOleInPlaceUIWindow*)this;
else if (IsEqualIID(riid, IID_IOleControlSite))
*ppvObject = (IOleControlSite*)this;
else if (IsEqualIID(riid, IID_IOleWindow))
*ppvObject = this;
else if (IsEqualIID(riid, IID_IDispatch))
*ppvObject = (IDispatch*)this;
else if (IsEqualIID(riid, IID_IUnknown))
*ppvObject = this;
else
{
*ppvObject = NULL;
return E_NOINTERFACE;
}
AddRef();
return S_OK;
}
inline STDMETHODIMP_(ULONG) CAXWindow::Release()
{
return --m_cRefs;
}
inline void CAXWindow::Remove()
{
if (!m_pUnk)
return;
IOleObject* pioo;
HRESULT hr = m_pUnk->QueryInterface(IID_IOleObject, (void**)&pioo);
if (SUCCEEDED(hr))
{
pioo->Close(OLECLOSE_NOSAVE);
pioo->SetClientSite(NULL);
pioo->Release();
}
IOleInPlaceObject* pipo;
hr = m_pUnk->QueryInterface(IID_IOleInPlaceObject, (void**)&pipo);
if (SUCCEEDED(hr))
{
pipo->UIDeactivate();
pipo->InPlaceDeactivate();
pipo->Release();
}
m_pUnk->Release();
m_pUnk = NULL;
}
inline STDMETHODIMP CAXWindow::RemoveMenus(HMENU hmenuShared)
{
UNREFERENCED_PARAMETER(hmenuShared);
return E_NOTIMPL;
}
inline STDMETHODIMP CAXWindow::RequestBorderSpace(LPCBORDERWIDTHS lpborderwidths)
{
UNREFERENCED_PARAMETER(lpborderwidths);
return E_NOTIMPL;
}
inline STDMETHODIMP CAXWindow::RequestNewObjectLayout()
{
return E_NOTIMPL;
}
inline STDMETHODIMP CAXWindow::SaveObject()
{
return E_NOTIMPL;
}
inline STDMETHODIMP CAXWindow::Scroll(SIZE scrollExtent)
{
UNREFERENCED_PARAMETER(scrollExtent);
return E_NOTIMPL;
}
inline STDMETHODIMP CAXWindow::SetActiveObject(IOleInPlaceActiveObject* pActiveObject, LPCOLESTR lpszObjName)
{
UNREFERENCED_PARAMETER(pActiveObject);
UNREFERENCED_PARAMETER(lpszObjName);
return E_NOTIMPL;
}
inline STDMETHODIMP CAXWindow::SetBorderSpace(LPCBORDERWIDTHS lpborderwidths)
{
UNREFERENCED_PARAMETER(lpborderwidths);
return E_NOTIMPL;
}
inline void CAXWindow::SetLocation(int x, int y, int width, int height)
{
m_rcControl.SetRect(x, y, x + width, y + height);
if (!m_pUnk)
return;
IOleInPlaceObject* pipo;
HRESULT hr = m_pUnk->QueryInterface(IID_IOleInPlaceObject, (void**)&pipo);
if (FAILED(hr))
return;
pipo->SetObjectRects(&m_rcControl, &m_rcControl);
pipo->Release();
}
inline STDMETHODIMP CAXWindow::SetMenu(HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject)
{
UNREFERENCED_PARAMETER(hmenuShared);
UNREFERENCED_PARAMETER(holemenu);
UNREFERENCED_PARAMETER(hwndActiveObject);
return E_NOTIMPL;
}
inline void CAXWindow::SetParent(HWND hWndParent)
{
m_hWnd = hWndParent;
}
inline STDMETHODIMP CAXWindow::SetStatusText(LPCOLESTR pszStatusText)
{
if (NULL == pszStatusText)
return E_POINTER;
#ifndef _UNICODE
char status[MAX_PATH];
// Convert the Wide string to char
WideCharToMultiByte(CP_ACP, 0, pszStatusText, -1, status, MAX_PATH, NULL, NULL);
if (IsWindow(m_hWndStatus))
SendMessage(m_hWndStatus, SB_SETTEXT, (WPARAM)0, (LPARAM)status);
#else
if (IsWindow(m_hWndStatus))
SendMessage(m_hWndStatus, SB_SETTEXT, (WPARAM)0, (LPARAM)pszStatusText);
#endif
return (S_OK);
}
inline void CAXWindow::SetStatusWindow(HWND hWndStatus)
{
m_hWndStatus = hWndStatus;
}
inline void CAXWindow::SetVisible(BOOL fVisible)
{
if (!m_pUnk)
return;
IOleObject* pioo;
HRESULT hr = m_pUnk->QueryInterface(IID_IOleObject, (void**)&pioo);
if (FAILED(hr))
return;
if (fVisible)
{
pioo->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL, this, 0, m_hWnd, &m_rcControl);
pioo->DoVerb(OLEIVERB_SHOW, NULL, this, 0, m_hWnd, &m_rcControl);
}
else
pioo->DoVerb(OLEIVERB_HIDE, NULL, this, 0, m_hWnd, NULL);
pioo->Release();
}
inline STDMETHODIMP CAXWindow::ShowObject()
{
return S_OK;
}
inline STDMETHODIMP CAXWindow::ShowPropertyFrame()
{
return E_NOTIMPL;
}
inline STDMETHODIMP CAXWindow::TransformCoords(POINTL* pptlHimetric, POINTF* pptfContainer, DWORD dwFlags)
{
UNREFERENCED_PARAMETER(pptlHimetric);
UNREFERENCED_PARAMETER(pptfContainer);
UNREFERENCED_PARAMETER(dwFlags);
return E_NOTIMPL;
}
inline STDMETHODIMP CAXWindow::TranslateAccelerator(LPMSG lpmsg, WORD wID)
{
UNREFERENCED_PARAMETER(lpmsg);
UNREFERENCED_PARAMETER(wID);
return S_OK;
}
inline STDMETHODIMP CAXWindow::TranslateAccelerator(LPMSG pMsg, DWORD grfModifiers)
{
UNREFERENCED_PARAMETER(pMsg);
UNREFERENCED_PARAMETER(grfModifiers);
return S_FALSE;
}
inline void CAXWindow::TranslateKey(MSG msg)
{
if (!m_pUnk)
return;
IOleInPlaceActiveObject* pao;
HRESULT hr = m_pUnk->QueryInterface(IID_IOleInPlaceActiveObject, (void**)&pao);
if (FAILED(hr))
return;
pao->TranslateAccelerator(&msg);
pao->Release();
}
////////////////////////////////////////
// Definitions for the CWebBrowser class
//
inline CWebBrowser::CWebBrowser() : m_pIWebBrowser2(0)
{
OleInitialize(NULL);
}
inline CWebBrowser::~CWebBrowser()
{
if (m_pIWebBrowser2)
{
m_pIWebBrowser2->Stop();
m_pIWebBrowser2->Release();
}
OleUninitialize();
}
inline void CWebBrowser::AddWebBrowserControl()
{
GetAXWindow().CreateControl(CLSID_WebBrowser);
GetAXWindow().SetParent(m_hWnd);
GetAXWindow().SetVisible(TRUE);
GetAXWindow().Activate(TRUE);
IUnknown* pUnk = GetAXWindow().GetUnknown();
if(pUnk)
{
// Store the pointer to the WebBrowser control
HRESULT hr = pUnk->QueryInterface(IID_IWebBrowser2, (void**)&m_pIWebBrowser2);
pUnk->Release();
// Navigate to an empty page
if (SUCCEEDED(hr))
{
VARIANT vURL;
vURL.vt = VT_BSTR;
vURL.bstrVal = SysAllocString(L"about:blank");
VARIANT ve1, ve2, ve3, ve4;
ve1.vt = VT_EMPTY;
ve2.vt = VT_EMPTY;
ve3.vt = VT_EMPTY;
ve4.vt = VT_EMPTY;
m_pIWebBrowser2->Navigate2(&vURL, &ve1, &ve2, &ve3, &ve4);
VariantClear(&vURL);
}
}
}
inline void CWebBrowser::Navigate(LPCTSTR pTChar)
{
// Navigate to our web page
VARIANT vURL;
vURL.vt = VT_BSTR;
vURL.bstrVal = SysAllocString(T2W(pTChar));
VARIANT ve1, ve2, ve3, ve4;
ve1.vt = VT_EMPTY;
ve2.vt = VT_EMPTY;
ve3.vt = VT_EMPTY;
ve4.vt = VT_EMPTY;
GetIWebBrowser2()->Navigate2(&vURL, &ve1, &ve2, &ve3, &ve4);
VariantClear(&vURL); // Also frees memory allocated by SysAllocateString
}
inline void CWebBrowser::OnCreate()
{
AddWebBrowserControl();
}
inline void CWebBrowser::OnSize(int width, int height)
{
// position the container
GetAXWindow().SetLocation(0, 0, width, height);
}
inline LRESULT CWebBrowser::WndProcDefault(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_SIZE:
OnSize(LOWORD(lParam), HIWORD(lParam));
break;
case WM_DESTROY:
GetAXWindow().Remove();
break;
}
return CWnd::WndProcDefault(uMsg, wParam, lParam);
}
}
#endif // _WIN32XX_WEBBROWSER_H_
|