forked from blueantst/DuiVision
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCDuiPlugin.cpp
423 lines (363 loc) · 10.2 KB
/
CDuiPlugin.cpp
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
#include "stdafx.h"
#include "CDuiPlugin.h"
#include "DuiHandlerPlugin.h"
/////////////////////////////////////////////////////////////////////////////
// 获取平台路径
/////////////////////////////////////////////////////////////////////////////
CString GetPlatRootPath()
{
//获取平台路径
TCHAR szFullPath[MAX_PATH];
TCHAR szdrive[_MAX_DRIVE];
TCHAR szdir[_MAX_DIR];
::GetModuleFileName(NULL, szFullPath, MAX_PATH);
#ifdef _UNICODE
_wsplitpath(szFullPath, szdrive, szdir, NULL, NULL);
#else
_splitpath(szFullPath, szdrive, szdir, NULL, NULL);
#endif
CString szPath;
szPath.Format(_T("%s%s"), szdrive, szdir);
szPath = szPath.Left(szPath.GetLength() - 1);
int nPos = szPath.ReverseFind('\\');
if(nPos >= 0)
{
szPath = szPath.Left(nPos+1);
}
return szPath;
}
/////////////////////////////////////////////////////////////////////////////
// 获取插件路径
/////////////////////////////////////////////////////////////////////////////
CString GetPlugInRootPath()
{
//获取平台路径
TCHAR szFullPath[MAX_PATH];
TCHAR szdrive[_MAX_DRIVE];
TCHAR szdir[_MAX_DIR];
::GetModuleFileName(GetDllInstance(), szFullPath, MAX_PATH);
#ifdef _UNICODE
_wsplitpath(szFullPath, szdrive, szdir, NULL, NULL);
#else
_splitpath(szFullPath, szdrive, szdir, NULL, NULL);
#endif
CString szPath;
szPath.Format(_T("%s%s"), szdrive, szdir);
return szPath;
}
//////////////////////////////////////////////////////////////////////////
// 功能实现
//////////////////////////////////////////////////////////////////////////
CDuiPlugin::CDuiPlugin()
{
m_pDuiPanel = NULL;
}
CDuiPlugin::~CDuiPlugin()
{
// 释放DUI界面库的资源
if(m_pDuiPanel)
{
delete m_pDuiPanel;
m_pDuiPanel = NULL;
}
DuiSystem::Release();
}
/////////////////////////////////////////////////////////////////////////////
// 安装回调函数
/////////////////////////////////////////////////////////////////////////////
int CDuiPlugin::InstallHandler(DWORD nEventID, LPVOID lpHandler, DWORD dwRefData)
{
CVisualComponent::InstallHandler(nEventID, lpHandler, dwRefData);
return 0;
}
/////////////////////////////////////////////////////////////////////////////
// 卸载回调函数
/////////////////////////////////////////////////////////////////////////////
int CDuiPlugin::UninstallHandler(DWORD nEventID, LPVOID lpHandler)
{
CVisualComponent::UninstallHandler(nEventID, lpHandler);
return 0;
}
/////////////////////////////////////////////////////////////////////////////
// 消息处理
/////////////////////////////////////////////////////////////////////////////
int CDuiPlugin::ProcessMessage(CVciMessage* pIn, CVciMessage* ppOut)
{
return 0;
}
//{{VCI_IMPLEMENT_BEGIN
int CDuiPlugin::OnInit(UINT nIDTemplate, HWND hWnd, LPCTSTR lpszName, CRect rc)
{
// 调用DuiSystem创建一个Panel控件对象,并加载xml文件
TRACE("CDuiPlugin::OnInit, name=%s, rc=%d,%d,%d,%d\n", lpszName, rc.left, rc.top, rc.right, rc.bottom);
USES_CONVERSION;
// 设置DuiVision库的根目录
DuiSystem::SetRootPath(GetPlugInRootPath());
// 初始化DUI库
DWORD dwLangID = 0;
new DuiSystem(NULL, dwLangID, _T(""), 1116, nIDTemplate, _T(""));
DuiSystem::LogEvent(LOG_LEVEL_DEBUG, _T("CDuiPlugin::OnInit root path is %s"), GetPlugInRootPath());
// 加载xml
m_pDuiPanel = (CDuiPanel*)DuiSystem::CreateControlByName(_T("div"), hWnd, NULL);
if(m_pDuiPanel)
{
// 给插件的panel对象注册事件处理对象
CDuiHandlerPlugin* pHandler = new CDuiHandlerPlugin();
pHandler->SetDuiPanel(m_pDuiPanel);
DuiSystem::RegisterHandler(m_pDuiPanel, pHandler);
// 加载插件界面文件
//BOOL bRet = m_pDuiPanel->LoadXmlFile(A2W(lpszName));
BOOL bRet = m_pDuiPanel->LoadXmlFile(lpszName);
// 事件处理对象初始化
pHandler->OnInit();
//DuiSystem::LogEvent(LOG_LEVEL_DEBUG, _T("CDuiPlugin::OnInit load %s %s"), A2W(lpszName), bRet ? _T("succ") : _T("fail"));
DuiSystem::LogEvent(LOG_LEVEL_DEBUG, _T("CDuiPlugin::OnInit load %s %s"), lpszName, bRet ? _T("succ") : _T("fail"));
}
return 0;
}
int CDuiPlugin::SetRect(CRect rc)
{
TRACE("CDuiPlugin::SetRect(%d,%d,%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
if(m_pDuiPanel)
{
CString strPos;
strPos.Format(_T("%d,%d,%d,%d"), rc.left, rc.top,rc.right, rc.bottom);
m_pDuiPanel->SetPosStr(strPos);
m_pDuiPanel->OnPositionChange();
}
return 0;
}
int CDuiPlugin::SetVisible(BOOL bIsVisible)
{
TRACE("CDuiPlugin::SetVisible(%d)\n", bIsVisible);
if(m_pDuiPanel)
{
m_pDuiPanel->SetVisible(bIsVisible);
}
return 0;
}
int CDuiPlugin::SetDisable(BOOL bIsDisable)
{
TRACE("CDuiPlugin::SetDisable(%d)\n", bIsDisable);
if(m_pDuiPanel)
{
m_pDuiPanel->SetDisable(bIsDisable);
}
return 0;
}
int CDuiPlugin::SetFocus(BOOL bFocus)
{
TRACE("CDuiPlugin::SetFocus(%d)\n", bFocus);
if(m_pDuiPanel)
{
m_pDuiPanel->OnFocus(bFocus);
}
return 0;
}
int CDuiPlugin::DrawControl(CDC &dc, CRect rcUpdate)
{
//TRACE("CDuiPlugin::DrawControl(%d,%d,%d,%d)(%d,%d)\n", rcUpdate.left, rcUpdate.top, rcUpdate.right, rcUpdate.bottom);
if(m_pDuiPanel)
{
m_pDuiPanel->Draw(dc, rcUpdate);
}
return 0;
}
int CDuiPlugin::OnTimer(UINT uTimerID, LPCTSTR lpszTimerName)
{
if(m_pDuiPanel)
{
m_pDuiPanel->OnTimer();
}
return 0;
}
int CDuiPlugin::OnMessage(UINT uID, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if(m_pDuiPanel)
{
return m_pDuiPanel->OnMessage(uID, uMsg, wParam, lParam);
}
return 0;
}
int CDuiPlugin::OnMousePointChange(CPoint& point)
{
if(m_pDuiPanel)
{
return m_pDuiPanel->OnMousePointChange(point);
}
return 0;
}
int CDuiPlugin::OnCheckMouseResponse(UINT nFlags, CPoint point)
{
if(m_pDuiPanel)
{
return m_pDuiPanel->OnCheckMouseResponse(nFlags, point);
}
return 0;
}
int CDuiPlugin::OnMouseMove(UINT nFlags, CPoint point)
{
if(m_pDuiPanel)
{
return m_pDuiPanel->OnMouseMove(nFlags, point);
}
return 0;
}
int CDuiPlugin::OnLButtonDown(UINT nFlags, CPoint point)
{
if(m_pDuiPanel)
{
return m_pDuiPanel->OnLButtonDown(nFlags, point);
}
return 0;
}
int CDuiPlugin::OnLButtonUp(UINT nFlags, CPoint point)
{
if(m_pDuiPanel)
{
return m_pDuiPanel->OnLButtonUp(nFlags, point);
}
return 0;
}
int CDuiPlugin::OnScroll(BOOL bVertical, UINT nFlags, CPoint point)
{
if(m_pDuiPanel)
{
return m_pDuiPanel->OnScroll(bVertical, nFlags, point);
}
return 0;
}
int CDuiPlugin::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if(m_pDuiPanel)
{
return m_pDuiPanel->OnKeyDown(nChar, nRepCnt, nFlags);
}
return 0;
}
int CDuiPlugin::OnLButtonDblClk(UINT nFlags, CPoint point)
{
if(m_pDuiPanel)
{
return m_pDuiPanel->OnLButtonDblClk(nFlags, point);
}
return 0;
}
int CDuiPlugin::SetUpdate(BOOL bUpdate, COLORREF clr)
{
if(m_pDuiPanel)
{
m_pDuiPanel->SetUpdate(bUpdate, clr);
}
return 0;
}
//}}VCI_IMPLEMENT_END
//////////////////////////////////////////////////////////////////////////
// 接口实现
//////////////////////////////////////////////////////////////////////////
INTERFACE_IMPLEMENT(DuiPlugin)
CONTROL_INTERFACE_IMPLEMENT(DuiPlugin)
//{{ 注意:!!!这里是保留的重要函数,不可删除!!!
// 获取接口的额外信息
LPVOID __stdcall CDuiPlugin::XDuiPlugin::GetExtraInfo(LPVOID lpRefData)
{
CDuiPlugin *pObj = GET_INTERFACE_OBJECT(DuiPlugin);
return pObj;
}
//}} 注意:!!!这里是保留的重要函数,不可删除!!!
//{{VCI_INTERFACE_IMPLEMENT_BEGIN
int __stdcall CDuiPlugin::XDuiPlugin::OnInit(UINT nIDTemplate, HWND hWnd, LPCTSTR lpszName, CRect rc)
{
CDuiPlugin *pObj = GET_INTERFACE_OBJECT(DuiPlugin);
return pObj->OnInit(nIDTemplate, hWnd, lpszName, rc);
}
int __stdcall CDuiPlugin::XDuiPlugin::SetRect(CRect rc)
{
CDuiPlugin *pObj = GET_INTERFACE_OBJECT(DuiPlugin);
return pObj->SetRect(rc);
}
int __stdcall CDuiPlugin::XDuiPlugin::SetVisible(BOOL bIsVisible)
{
CDuiPlugin *pObj = GET_INTERFACE_OBJECT(DuiPlugin);
return pObj->SetVisible(bIsVisible);
}
int __stdcall CDuiPlugin::XDuiPlugin::SetDisable(BOOL bIsDisable)
{
CDuiPlugin *pObj = GET_INTERFACE_OBJECT(DuiPlugin);
return pObj->SetDisable(bIsDisable);
}
int __stdcall CDuiPlugin::XDuiPlugin::SetFocus(BOOL bFocus)
{
CDuiPlugin *pObj = GET_INTERFACE_OBJECT(DuiPlugin);
return pObj->SetFocus(bFocus);
}
int __stdcall CDuiPlugin::XDuiPlugin::DrawControl(CDC &dc, CRect rcUpdate)
{
CDuiPlugin *pObj = GET_INTERFACE_OBJECT(DuiPlugin);
return pObj->DrawControl(dc, rcUpdate);
}
int __stdcall CDuiPlugin::XDuiPlugin::OnTimer(UINT uTimerID, LPCTSTR lpszTimerName)
{
CDuiPlugin *pObj = GET_INTERFACE_OBJECT(DuiPlugin);
return pObj->OnTimer(uTimerID, lpszTimerName);
}
int __stdcall CDuiPlugin::XDuiPlugin::OnMessage(UINT uID, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
CDuiPlugin *pObj = GET_INTERFACE_OBJECT(DuiPlugin);
return pObj->OnMessage(uID, uMsg, wParam, lParam);
}
int __stdcall CDuiPlugin::XDuiPlugin::OnMousePointChange(CPoint& point)
{
CDuiPlugin *pObj = GET_INTERFACE_OBJECT(DuiPlugin);
return pObj->OnMousePointChange(point);
}
int __stdcall CDuiPlugin::XDuiPlugin::OnCheckMouseResponse(UINT nFlags, CPoint point)
{
CDuiPlugin *pObj = GET_INTERFACE_OBJECT(DuiPlugin);
return pObj->OnCheckMouseResponse(nFlags, point);
}
int __stdcall CDuiPlugin::XDuiPlugin::OnMouseMove(UINT nFlags, CPoint point)
{
CDuiPlugin *pObj = GET_INTERFACE_OBJECT(DuiPlugin);
return pObj->OnMouseMove(nFlags, point);
}
int __stdcall CDuiPlugin::XDuiPlugin::OnLButtonDown(UINT nFlags, CPoint point)
{
CDuiPlugin *pObj = GET_INTERFACE_OBJECT(DuiPlugin);
return pObj->OnLButtonDown(nFlags, point);
}
int __stdcall CDuiPlugin::XDuiPlugin::OnLButtonUp(UINT nFlags, CPoint point)
{
CDuiPlugin *pObj = GET_INTERFACE_OBJECT(DuiPlugin);
return pObj->OnLButtonUp(nFlags, point);
}
int __stdcall CDuiPlugin::XDuiPlugin::OnScroll(BOOL bVertical, UINT nFlags, CPoint point)
{
CDuiPlugin *pObj = GET_INTERFACE_OBJECT(DuiPlugin);
return pObj->OnScroll(bVertical, nFlags, point);
}
int __stdcall CDuiPlugin::XDuiPlugin::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
CDuiPlugin *pObj = GET_INTERFACE_OBJECT(DuiPlugin);
return pObj->OnKeyDown(nChar, nRepCnt, nFlags);
}
int __stdcall CDuiPlugin::XDuiPlugin::OnLButtonDblClk(UINT nFlags, CPoint point)
{
CDuiPlugin *pObj = GET_INTERFACE_OBJECT(DuiPlugin);
return pObj->OnLButtonDblClk(nFlags, point);
}
int __stdcall CDuiPlugin::XDuiPlugin::SetUpdate(BOOL bUpdate, COLORREF clr)
{
CDuiPlugin *pObj = GET_INTERFACE_OBJECT(DuiPlugin);
return pObj->SetUpdate(bUpdate, clr);
}
//}}VCI_INTERFACE_IMPLEMENT_END
// 查询命令是否支持
extern "C" __declspec(dllexport)
int gQueryCommandIsSupport(LPCSTR lpcsCmd)
{
//if(strcmp(lpcsCmd, "HELLO") == 0)
//{
//}
return 0;
}