完全不熟悉web方面的东西

方法都是网上找的 具体出处没有记录

首先 让WebBrowser 使用 IE8或以上的内核

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void WINAPI WriteWebBrowserRegKey(LPCTSTR lpKey,DWORD dwValue)
{
HKEY hk;
CString str = "Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\";
str += lpKey;
if (RegCreateKey(HKEY_LOCAL_MACHINE,str,&hk)!=0)
{
MessageBox(NULL,"打开注册表失败!","Error",0);
ExitProcess(-1);
}
if (RegSetValueEx(hk,"你的exe名称.exe",NULL,REG_DWORD,(const byte*)&dwValue,4)!=0)
{
RegCloseKey(hk);
MessageBox(NULL,"写注册表失败!","Error",0);
ExitProcess(-1);
}
RegCloseKey(hk);
}

在 InitInstance()内

1
2
3
4
5
6
7
8
9
	WriteWebBrowserRegKey("FEATURE_BROWSER_EMULATION",9000);
// WriteWebBrowserRegKey("FEATURE_ACTIVEX_REPURPOSEDETECTION",1);
WriteWebBrowserRegKey("FEATURE_BLOCK_LMZ_IMG",1);
WriteWebBrowserRegKey("FEATURE_BLOCK_LMZ_OBJECT",1);
WriteWebBrowserRegKey("FEATURE_BLOCK_LMZ_SCRIPT",1);
WriteWebBrowserRegKey("FEATURE_Cross_Domain_Redirect_Mitigation",1);
WriteWebBrowserRegKey("FEATURE_ENABLE_SCRIPT_PASTE_URLACTION_IF_PROMPT",1);
WriteWebBrowserRegKey("FEATURE_LOCALMACHINE_LOCKDOWN",1);
WriteWebBrowserRegKey("FEATURE_GPU_RENDERING",1);

下面是让WebBrowser 使用ie的风格 具体这个应该怎么称呼.不懂 -_-! 总之按钮样式不再是丑陋的 2000经典样式了

增加一个头文件

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

// class name: CWebUIController WebUIController.h 源代码:
// author: Dandy Cheung
// email: dandycheung@21cn.com
// date: 2005-3-18

#ifndef __WEBUICONTROLLER_H__
#define __WEBUICONTROLLER_H__
#
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <MSHTMHST.H>
#include <EXDISP.H>
#include <EXDISPID.H>

inline
HRESULT _CoAdvise(IUnknown* pUnkCP, IUnknown* pUnk, const IID& iid, LPDWORD pdw)
{
IConnectionPointContainer* pCPC = NULL;
IConnectionPoint* pCP = NULL;
HRESULT hRes = pUnkCP->QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC);
if(SUCCEEDED(hRes) && pCPC != NULL)
{
hRes = pCPC->FindConnectionPoint(iid, &pCP);
if(SUCCEEDED(hRes) && pCP != NULL)
{
hRes = pCP->Advise(pUnk, pdw);
pCP->Release();
}

pCPC->Release();
}

return hRes;
}

inline
HRESULT _CoUnadvise(IUnknown* pUnkCP, const IID& iid, DWORD dw)
{
IConnectionPointContainer* pCPC = NULL;
IConnectionPoint* pCP = NULL;
HRESULT hRes = pUnkCP->QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC);
if(SUCCEEDED(hRes) && pCPC != NULL)
{
hRes = pCPC->FindConnectionPoint(iid, &pCP);
if(SUCCEEDED(hRes) && pCP != NULL)
{
hRes = pCP->Unadvise(dw);
pCP->Release();
}

pCPC->Release();
}

return hRes;
}

class CWebUIController : public DWebBrowserEvents2, public IDocHostUIHandler
{
ULONG m_uRefCount;

IWebBrowser2* m_pWebBrowser2;
DWORD m_dwCookie;

BOOL m_bEnable3DBorder;
BOOL m_bEnableScrollBar;

public:
CWebUIController() : m_uRefCount(0), m_pWebBrowser2(NULL), m_dwCookie(0)
{
m_bEnable3DBorder = TRUE;
m_bEnableScrollBar = TRUE;
}

virtual ~CWebUIController()
{
}
public:
// IUnknown Methods
STDMETHOD(QueryInterface)(REFIID riid, void** ppvObject)
{
*ppvObject = NULL;

if(IsEqualGUID(riid, DIID_DWebBrowserEvents2) ||
IsEqualGUID(riid, IID_IDispatch))
{
*ppvObject = (DWebBrowserEvents2*)this;
AddRef();
return S_OK;
}
else if(IsEqualGUID(riid, IID_IDocHostUIHandler) ||
IsEqualGUID(riid, IID_IUnknown))
{
*ppvObject = (IDocHostUIHandler*)this;
AddRef();
return S_OK;
}

return E_NOINTERFACE;
}

STDMETHOD_(ULONG, AddRef)(void)
{
m_uRefCount++;
return m_uRefCount;
}

STDMETHOD_(ULONG, Release)(void)
{
m_uRefCount--;
ULONG uRefCount = m_uRefCount;
if(uRefCount == 0)
delete this;

return uRefCount;
}

// IDispatch Methods
STDMETHOD(GetTypeInfoCount)(unsigned int FAR* pctinfo)
{
return E_NOTIMPL;
}

STDMETHOD(GetTypeInfo)(UINT itinfo, LCID lcid, ITypeInfo** pptinfo)
{
return E_NOTIMPL;
}


STDMETHOD(GetIDsOfNames)(REFIID riid, OLECHAR FAR* FAR* rgszNames,
unsigned int cNames, LCID lcid, DISPID FAR* rgDispId)
{
return E_NOTIMPL;
}

STDMETHOD(Invoke)(DISPID dispidMember,REFIID riid, LCID lcid, WORD wFlags,
DISPPARAMS* pDispParams, VARIANT* pvarResult,
EXCEPINFO* pexcepinfo, UINT* puArgErr)
{
if(!pDispParams)
return E_INVALIDARG;

switch(dispidMember)
{
//
// The parameters for this DISPID are as follows:
// [0]: URL to navigate to - VT_BYREF|VT_VARIANT
// [1]: An object that evaluates to the top-level or frame
// WebBrowser object corresponding to the event.
case DISPID_NAVIGATECOMPLETE2:

//
// The IDocHostUIHandler association must be set
// up every time we navigate to a new page.
//
if(pDispParams->cArgs >= 2 && pDispParams->rgvarg[1].vt == VT_DISPATCH)
SetCustomDoc(pDispParams->rgvarg[1].pdispVal);
else
return E_INVALIDARG;

break;

default:
break;
}

return S_OK;
}

// IDocHostUIHandler Methods
protected:
STDMETHOD(ShowContextMenu)(DWORD dwID, POINT FAR* ppt, IUnknown FAR* pcmdtReserved,
IDispatch FAR* pdispReserved)
{
return E_NOTIMPL;
}

STDMETHOD(GetHostInfo)(DOCHOSTUIINFO FAR* pInfo)
{
if(pInfo != NULL)
{
pInfo->dwFlags |= (m_bEnable3DBorder ? 0 : DOCHOSTUIFLAG_NO3DBORDER);
pInfo->dwFlags |= (m_bEnableScrollBar ? 0 : DOCHOSTUIFLAG_SCROLL_NO);
pInfo->dwFlags |=DOCHOSTUIFLAG_THEME; //这里是我自己添加的 让其使用IE的按钮风格
}

return S_OK;
}

STDMETHOD(ShowUI)(DWORD dwID, IOleInPlaceActiveObject FAR* pActiveObject,
IOleCommandTarget FAR* pCommandTarget,
IOleInPlaceFrame FAR* pFrame,
IOleInPlaceUIWindow FAR* pDoc)
{
return E_NOTIMPL;
}

STDMETHOD(HideUI)(void)
{
return E_NOTIMPL;
}

STDMETHOD(UpdateUI)(void)
{
return E_NOTIMPL;
}

STDMETHOD(EnableModeless)(BOOL fEnable)
{
return E_NOTIMPL;
}

STDMETHOD(OnDocWindowActivate)(BOOL fActivate)
{
return E_NOTIMPL;
}

STDMETHOD(OnFrameWindowActivate)(BOOL fActivate)
{
return E_NOTIMPL;
}

STDMETHOD(ResizeBorder)(LPCRECT prcBorder, IOleInPlaceUIWindow FAR* pUIWindow,
BOOL fRameWindow)
{
return E_NOTIMPL;
}

STDMETHOD(TranslateAccelerator)(LPMSG lpMsg, const GUID FAR* pguidCmdGroup,
DWORD nCmdID)
{
return E_NOTIMPL;
}

STDMETHOD(GetOptionKeyPath)(LPOLESTR FAR* pchKey, DWORD dw)
{
return E_NOTIMPL;
}

STDMETHOD(GetDropTarget)(IDropTarget* pDropTarget,
IDropTarget** ppDropTarget)
{
return E_NOTIMPL;
}

STDMETHOD(GetExternal)(IDispatch** ppDispatch)
{
return E_NOTIMPL;
}

STDMETHOD(TranslateUrl)(DWORD dwTranslate, OLECHAR* pchURLIn,
OLECHAR** ppchURLOut)
{
return E_NOTIMPL;
}

STDMETHOD(FilterDataObject)(IDataObject* pDO, IDataObject** ppDORet)
{
return E_NOTIMPL;
}

public:
HRESULT SetWebBrowser(IWebBrowser2* pWebBrowser2)
{
// Unadvise the event sink, if there was a
// previous reference to the WebBrowser control.
if(m_pWebBrowser2)
{
_CoUnadvise(m_pWebBrowser2, DIID_DWebBrowserEvents2, m_dwCookie);
m_dwCookie = 0;
// _CoUnadvise中就已经被Release // m_pWebBrowser2->Release();
}

m_pWebBrowser2 = pWebBrowser2;
if(pWebBrowser2 == NULL)
return S_OK;

m_pWebBrowser2->AddRef();

return _CoAdvise(m_pWebBrowser2, (IDispatch*)this, DIID_DWebBrowserEvents2, &m_dwCookie);
}

void Enable3DBorder(BOOL bEnable = TRUE)
{
m_bEnable3DBorder = bEnable;
}

void EnableScrollBar(BOOL bEnable = TRUE)
{
m_bEnableScrollBar = bEnable;
}

private:
void SetCustomDoc(LPDISPATCH lpDisp)
{
if(lpDisp == NULL)
return;

IWebBrowser2* pWebBrowser2 = NULL;
HRESULT hr = lpDisp->QueryInterface(IID_IWebBrowser2, (void**)&pWebBrowser2);

if(SUCCEEDED(hr) && pWebBrowser2)
{
IDispatch* pDoc = NULL;
hr = pWebBrowser2->get_Document(&pDoc);

if(SUCCEEDED(hr) && pDoc)
{
ICustomDoc* pCustDoc = NULL;
hr = pDoc->QueryInterface(IID_ICustomDoc, (void**)&pCustDoc);
if(SUCCEEDED(hr) && pCustDoc != NULL)
{
pCustDoc->SetUIHandler(this);
pCustDoc->Release();
}

pDoc->Release();
}

pWebBrowser2->Release();
}
}
};

#endif // __WEBUICONTROLLER_H__

在 Dlg类里添加一个变量

1
CWebUIController * m_webUICtrl;

在 Dlg的 OnInitDialog() 内

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
m_webUICtrl = NULL;
LPUNKNOWN pUnk1 = m_Web.GetControlUnknown();
MyDbgPrintf("punk1 %08X",pUnk1);
if(pUnk1 != NULL)
{
IWebBrowser2* pWB2 = NULL;
HRESULT hr = pUnk1->QueryInterface(IID_IWebBrowser2, (void**)&pWB2);
ASSERT(SUCCEEDED(hr) && pWB2 != NULL);
if(SUCCEEDED(hr) && pWB2 != NULL)
{
if (!m_webUICtrl)
{
m_webUICtrl = new CWebUIController();
}
m_webUICtrl->AddRef();
MyDbgPrintf("gogogo");
m_webUICtrl->Enable3DBorder(TRUE); // 此代码禁止三维边框
// m_webUICtrl->EnableScrollBar(FALSE); // 此代码禁止滚动条
m_webUICtrl->SetWebBrowser(pWB2);
m_webUICtrl->Release();
pWB2->Release();
}
}

现在就全部搞定了

感谢您的阅读,本文由 smallwhite's Blog 版权所有。如若转载,请注明出处:smallwhite's Blog(https://smallwhite.ml/pub/uncategorized/rang-mfc-de-webbrowser-kong-jian-shi-yong-ie8-huo-yi-shang-de-nei-he-mo-ren-shi-ie7-bing-qie-shi-yong-ie-an-niu-yang-shi.html
神舟优雅A550 插入鼠标关闭感应垫
用Aheadlib 生成lpk 修改了下