-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenEdit.cpp
More file actions
361 lines (289 loc) · 8.19 KB
/
Copy pathOpenEdit.cpp
File metadata and controls
361 lines (289 loc) · 8.19 KB
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
// OpenEdit.cpp : COpenEdit 的实现
#include "stdafx.h"
#include "OpenEdit.h"
#include "word/word.h"
//#include "comutil.h"
//#include <comutil.h>
//#include <stdio.h>
//#include <comdef.h>
//#pragma comment(lib, "comsupp.lib")
//#pragma comment(lib, "kernel32.lib")
using namespace std;
COleVariant vOpt(DISP_E_PARAMNOTFOUND, VT_ERROR);
STDMETHODIMP COpenEdit::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* const arr[] =
{
&IID_IOpenEdit
};
for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}
STDMETHODIMP COpenEdit::GetDocumentFile(int nOpenMode, BOOL bTrace)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
USES_CONVERSION;
//CString test((LPCTSTR)sHeader);
if (this->nDocumentType == 0){//文档类型(ms office)
if (SUCCEEDED(m_pWord.CreateInstance(__uuidof(Word::Application)))){
BOOL Res = m_WordEventSink.Advise(m_pWord, IID_IWordAppEventSink);
if (!wdocx::GetDocFileFromServer(m_pWord, W2A(this->sFileID), W2A(this->sUserName), nOpenMode, bTrace)) {
AfxGetApp()->DoWaitCursor(0);
return S_FALSE;
}
}
}
AfxGetApp()->DoWaitCursor(0);
return S_OK;
}
STDMETHODIMP COpenEdit::SendDocumentFile(BSTR sHeader, int nOpenMode)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
USES_CONVERSION;
AfxGetApp()->DoWaitCursor(1);
if (this->nDocumentType == 0){//文档类型(ms office)
if (SUCCEEDED(m_pWord.CreateInstance(__uuidof(Word::Application)))) {//判断客户端是否安装ms word
m_pWord->Quit(vOpt, vOpt, vOpt);
m_pWord->Release();
if (!wdocx::SendDocFileToServer(W2A(sHeader), nOpenMode)) {
AfxGetApp()->DoWaitCursor(0);
return S_FALSE;
}}}
AfxGetApp()->DoWaitCursor(0);
return S_OK;
}
STDMETHODIMP COpenEdit::get_DocumentType(int* pDocType)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: 在此添加实现代码
*pDocType = this->nDocumentType;
return S_OK;
}
STDMETHODIMP COpenEdit::put_DocumentType(int nDocType)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: 在此添加实现代码
this->nDocumentType = nDocType;
return S_OK;
}
STDMETHODIMP COpenEdit::GetAttachment(BSTR sInfo, BSTR sFile, int idx)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: 在此添加实现代码
return S_OK;
}
STDMETHODIMP COpenEdit::SendAttachment(BSTR sInfo)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: 在此添加实现代码
return S_OK;
}
STDMETHODIMP COpenEdit::get_ServerIp(BSTR* IP)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: 在此添加实现代码
//*IP = this->nIP;
CString str;
::GetProfileString("openwd", "Ip", "127.0.0.1", str.GetBuffer(15),15);
str.ReleaseBuffer();
*IP = str.AllocSysString();
SysFreeString(*IP);
return S_OK;
}
STDMETHODIMP COpenEdit::put_ServerIp(BSTR IP)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
this->nIP = IP;
::WriteProfileStringA("openwd", "Ip", (LPCSTR)_bstr_t(IP));
// TODO: 在此添加实现代码
return S_OK;
}
STDMETHODIMP COpenEdit::get_ServerPort(BSTR* pPort)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: 在此添加实现代码
//*pPort = this->nPort;
CString str;
::GetProfileString("openwd", "Port", "80", str.GetBuffer(6), 6);
str.ReleaseBuffer();
*pPort = str.AllocSysString();
SysFreeString(*pPort);
return S_OK;
}
STDMETHODIMP COpenEdit::put_ServerPort(BSTR iPort)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: 在此添加实现代码
this->nPort = iPort;
::WriteProfileString("openwd", "Port", (LPCSTR)_bstr_t(iPort));
return S_OK;
}
STDMETHODIMP COpenEdit::get_ServerPath(BSTR* pPath)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: 在此添加实现代码
//*pPath = this->sPath;
CString str;
::GetProfileString("openwd", "ServerURL", "jc/legalDoc", str.GetBuffer(50), 50);
str.ReleaseBuffer();
*pPath = str.AllocSysString();
SysFreeString(*pPath);
return S_OK;
}
STDMETHODIMP COpenEdit::put_ServerPath(BSTR sPath)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: 在此添加实现代码
this->sPath = sPath;
::WriteProfileString("openwd", "ServerURL", (LPCSTR)_bstr_t(sPath));
return S_OK;
}
STDMETHODIMP COpenEdit::get_FileID(BSTR* pFileID)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: 在此添加实现代码
*pFileID = this->sFileID;
return S_OK;
}
STDMETHODIMP COpenEdit::put_FileID(BSTR sFileID)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: 在此添加实现代码
this->sFileID = sFileID;
return S_OK;
}
STDMETHODIMP COpenEdit::get_UserName(BSTR* pUserName)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: 在此添加实现代码
*pUserName = this->sUserName;
return S_OK;
}
STDMETHODIMP COpenEdit::put_UserName(BSTR sUserName)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: 在此添加实现代码
this->sUserName = sUserName;
return S_OK;
}
STDMETHODIMP COpenEdit::ShowWindows(BSTR sTitle, int nCmdShow)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
USES_CONVERSION;
// TODO: 在此添加实现代码
ShowWinEx(W2A(sTitle), nCmdShow);
return S_OK;
}
void COpenEdit::DumpComError(const _com_error& e) const
{
CString ComErrorMessage;
ComErrorMessage.Format("COM Error1111: 0x%08lX. %s", e.Error(), e.ErrorMessage());
AfxMessageBox(ComErrorMessage);
}
void COpenEdit::DumpOleError(const COleException& e) const
{
CString OleErrorMessage;
OleErrorMessage.Format("Ole Error : 0x%08lX", (long)e.m_sc);
AfxMessageBox(OleErrorMessage);
}void COpenEdit::DumpDispatchError(const COleDispatchException& e) const
{
AfxMessageBox("Dispatch Error : " + e.m_strDescription);
}
BOOL COpenEdit::GetPageCount(DWORD& PageCount)
{
// To get the page count, you must first get the BuiltInDocumentProperties
// IDispatch interface, so you have access to the VB collection of document
// properties. What you have to do next is to get Item(n).Value where n is
// the index of the property you want to retrieve (wdPropertyPage here).
// Don't forget to trap COleException, COleDispatchException and _com_error
try
{
IDispatchPtr pDispatch(m_pWord->ActiveDocument->BuiltInDocumentProperties);
AfxMessageBox("000000000000000000");
ASSERT(pDispatch != NULL);
AfxMessageBox("111111111111111111");
// this pDispatch will be released by the smart pointer, so use FALSE
COleDispatchDriver DocProperties(pDispatch, FALSE);
_variant_t Property((long)Word::wdPropertyPages);
_variant_t Result;
// The Item method is the default member for the collection object
DocProperties.InvokeHelper(DISPID_VALUE,
DISPATCH_METHOD | DISPATCH_PROPERTYGET,
VT_VARIANT,
(void*)&Result,
(BYTE*)VTS_VARIANT,
&Property);
AfxMessageBox("22222222222222222222222");
// pDispatch will be extracted from variant Result
COleDispatchDriver DocProperty(Result);
// The Value property is the default member for the Item object
DocProperty.GetProperty(DISPID_VALUE, VT_I4, &PageCount);
}
catch (_com_error& ComError)
{
DumpComError(ComError);
return FALSE;
}
catch (COleException* pOleError)
{
DumpOleError(*pOleError);
pOleError->Delete();
return FALSE;
}
catch (COleDispatchException* pDispatchError)
{
DumpDispatchError(*pDispatchError);
pDispatchError->Delete();
return FALSE;
}
catch (...)
{
return FALSE;
}
return TRUE;
}
void COpenEdit::OnDocClose()
{
DWORD PageCount;
GetPageCount(PageCount);
CString Msg;
Msg.Format("Close event received\nNumber of pages is %d", PageCount);
AfxMessageBox(Msg);
}
void COpenEdit::ShowWinEx(CString szTitle, int nCmdShow)
{
//因某些机器打开wps的速度较慢,而无法将其置于顶层,故将这段代码改为多线程
//循环查找方式
HWND hWnd = 0;
if (nCmdShow < 0) //此种情况控制wps
{
CString szTemp;
//szTitle = szFinalFile + " - Kingsoft wps";
for (int i = 0; i < 10; i++)
{
hWnd = ::FindWindow(NULL, szTitle);
if (hWnd) break; //找到后退出
szTemp = szTitle;
hWnd = ::FindWindow(NULL, szTemp);
if (hWnd) break; //找到后退出
szTemp.Format("循环中hWnd=%d", hWnd);
// WriteLog(szTemp);
Sleep(200);
}
int rec = ::SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
// szTemp.Format("设置窗口时的返回值=%d",rec);
// WriteLog(szTemp);
}
else{ // 控制网页
// WriteLog("控制网页");
hWnd = ::FindWindow(NULL, szTitle);
::ShowWindow(hWnd, nCmdShow);
}
// szTitle=lpTitle;
// CmdShow = nCmdShow;
// AfxBeginThread(ShowWindowEx,NULL);
}