/
HTMLWindow2.h
257 lines (186 loc) · 6.68 KB
/
HTMLWindow2.h
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
/*
HTMLWindow.h
Copyright (C) 2003-2004 René Nyffenegger
This source code is provided 'as-is', without any express or implied
warranty. In no event will the author be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this source code must not be misrepresented; you must not
claim that you wrote the original source code. If you use this source code
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original source code.
3. This notice may not be removed or altered from any source distribution.
René Nyffenegger rene.nyffenegger@adp-gmbh.ch
*/
#ifndef HTMLWINDOW_H__
#define HTMLWINDOW_H__
#include <windows.h>
#include <exdisp.h>
#include <mshtml.h>
#include <mshtmhst.h>
#include <oaidl.h>
#include <string>
#include <map>
// TODO
#define MUST_BE_IMPLEMENTED(s) ::MessageBox(0, s, "Not Implemented", 0); return E_NOTIMPL;
/*
Thanks to http://www.codeproject.com/com/cwebpage.asp for a great example
*/
extern bool todo_bool;
/*
The following class receives links whose protocol is link://
That is, the virtual method AppLink will be called.
So, in order to make use of this mechanism, one has to inherit from
EventReceiver and override AppLink.
See http://www.adp-gmbh.ch/win/misc/mshtml/event_receiver/index.html for more details
*/
class EventReceiver {
friend class HTMLWindow;
protected:
class Parameters {
friend class HTMLWindow;
Parameters(std::map<std::string,std::string> p) {
parameters_ = p;
}
std::map<std::string, std::string> parameters_;
public:
std::string Value(std::string const& name) const {
if (parameters_.find(name) != parameters_.end()) {
return parameters_.find(name)->second.c_str();
}
else {
return "";
}
}
};
virtual void AppLink(std::string const& path, std::string& out_html, const Parameters& params) = 0;
};
class HTMLWindow :
public virtual DWebBrowserEvents2
{
friend class DocHostUiHandler;
public:
typedef std::map<std::string, std::string> param_list;
HTMLWindow(std::string const& html_or_url,
std::string const& title,
HINSTANCE,
bool is_url);
HTMLWindow(EventReceiver*,
std::string const& title,
HINSTANCE,
std::string const& first_link = "start_link",
param_list const& first_params = param_list());
virtual ~HTMLWindow();
long HTML(std::string const&);
long URL (std::string const& url);
void ResizeBrowser (HWND hwnd, DWORD width, DWORD height);
void AddSink();
HWND hwnd_;
private:
static bool ole_is_initialized_;
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
long EmbedBrowserObject();
void InitOle_CreateWindow(std::string const& title);
HINSTANCE instance_;
IOleObject* browserObject_;
IOleClientSite* ole_client_site_;
IStorage* storage_;
IOleInPlaceSite* ole_in_place_site_;
IOleInPlaceFrame* ole_in_place_frame_;
IDocHostUIHandler* doc_host_ui_handler_;
EventReceiver* event_receiver_;
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void ** ppvObject);
ULONG STDMETHODCALLTYPE AddRef() {return 1;}
ULONG STDMETHODCALLTYPE Release() {return 1;}
void STDMETHODCALLTYPE BeforeNavigate2(
IDispatch* pDisp,
VARIANT* url,
VARIANT* Flags,
VARIANT* TargetFrameName,
VARIANT* PostData,
VARIANT* Headers,
VARIANT_BOOL* Cancel) {
::MessageBox(0, "-- BeforeNavigate2", 0, 0);
*Cancel = 0;
}
void ClientToHostWindow(
long* CX,
long* CY
) {}
void CommandStateChange( long Command,
VARIANT_BOOL Enable
) {}
void DocumentComplete( IDispatch* pDisp,
VARIANT* URL
) {}
void DownloadBegin(VOID) {}
void DownloadComplete(VOID) {}
void FileDownload(VARIANT_BOOL* Cancel) {}
void NavigateComplete(IDispatch* pDisp, VARIANT* URL) {}
void NavigateError( IDispatch* pDisp,
VARIANT* URL,
VARIANT* TargetFrameName,
VARIANT* StatusCode,
VARIANT_BOOL* Cancel
) {}
void NewWindow2(
IDispatch** ppDisp,
VARIANT_BOOL* Cancel
) {}
void OnFullScreen(VARIANT_BOOL FullScreen) {}
void OnMenuBar(VARIANT_BOOL MenuBar) {}
void OnQuit(VOID) {}
void OnStatusBar(VARIANT_BOOL StatusBar) {}
void OnTheaterMode(VARIANT_BOOL TheaterMode) {}
void OnToolBar(VARIANT_BOOL ToolBar) {}
void OnVisible(VARIANT_BOOL Visible) {::MessageBox(0, "OnVisible", 0, 0);}
void PrintTemplateInstantiation(IDispatch* pDisp) {}
void PrintTemplateTeardown(IDispatch* pDisp) {}
void PrivacyImpactedStateChange(VARIANT_BOOL PrivacyImpacted) {}
void ProgressChange(long Progress, long ProgressMax) {}
void PropertyChange(BSTR szProperty) {}
void SetSecureLockIcon(long SecureLockIcon) {}
void StatusTextChange(BSTR Text) {}
void TitleChange(BSTR Text) {}
void WindowClosing(VARIANT_BOOL IsChildWindow, VARIANT_BOOL* Cancel) {}
void WindowSetHeight(long Height) {}
void WindowSetLeft(long Left) {}
void WindowSetResizable(VARIANT_BOOL Resizable) {}
void WindowSetTop(long Top) {}
void WindowSetWidth(long Width) {}
HRESULT STDMETHODCALLTYPE GetTypeInfoCount( unsigned int FAR* pctinfo) {
MUST_BE_IMPLEMENTED("GetTypeInfoCount")
*pctinfo = 0;
return S_OK;
}
HRESULT STDMETHODCALLTYPE GetTypeInfo(
unsigned int iTInfo,
LCID lcid,
ITypeInfo FAR* FAR* ppTInfo
) {
MUST_BE_IMPLEMENTED("GetTypeInfo")
}
HRESULT STDMETHODCALLTYPE GetIDsOfNames(
REFIID riid,
OLECHAR FAR* FAR* rgszNames,
unsigned int cNames,
LCID lcid,
DISPID FAR* rgDispId
) {
MUST_BE_IMPLEMENTED("GetIDsOfNames")
}
HRESULT STDMETHODCALLTYPE Invoke(
DISPID dispIdMember,
REFIID riid,
LCID lcid,
WORD wFlags,
DISPPARAMS FAR* pDispParams,
VARIANT FAR* pVarResult,
EXCEPINFO FAR* pExcepInfo,
unsigned int FAR* puArgErr);
};
#endif