-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSharedMemWinDoc.cpp
More file actions
195 lines (141 loc) · 4 KB
/
SharedMemWinDoc.cpp
File metadata and controls
195 lines (141 loc) · 4 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
// SharedMemWinDoc.cpp : CSharedMemWinDoc クラスの実装
//
#include "stdafx.h"
#include "SharedMemWin.h"
#include "SharedMemWinDoc.h"
#include "WinTools.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
using namespace jbxl;
//using namespace jbxwl;
// CSharedMemWinDoc
IMPLEMENT_DYNCREATE(CSharedMemWinDoc, CDocument)
BEGIN_MESSAGE_MAP(CSharedMemWinDoc, CDocument)
END_MESSAGE_MAP()
// CSharedMemWinDoc コンストラクション/デストラクション
CSharedMemWinDoc::CSharedMemWinDoc()
{
save_fname = "";
pApp = NULL;
bufferRing = new CBufferRing(MAXBUFFERLINE);
}
CSharedMemWinDoc::~CSharedMemWinDoc()
{
//DEBUG_Error("ディストラクタ:IN CSharedMemWinDoc");
pApp->m_state = SHM_STOP;
CSharedMemWinDoc::free();
//DEBUG_Error("ディストラクタ:OUT CSharedMemWinDoc");
}
void CSharedMemWinDoc::free(void)
{
if (bufferRing!=NULL) {
delete(bufferRing);
bufferRing = NULL;
}
}
BOOL CSharedMemWinDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument()) return FALSE;
return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
// CSharedMemWinDoc シリアル化
void CSharedMemWinDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: 格納するコードをここに追加してください。
}
else
{
// TODO: 読み込むコードをここに追加してください。
}
}
///////////////////////////////////////////////////////////////////////////////
// CSharedMemWinDoc 診断
#ifdef _DEBUG
void CSharedMemWinDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CSharedMemWinDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
///////////////////////////////////////////////////////////////////////////////
// CSharedMemWinDoc コマンド
void CSharedMemWinDoc::DeleteContents(void)
{
//CSharedMemWinDoc::clear();
//DEBUG_Warning("CSharedMemWinDoc::DeleteContents: IN");
CDocument::DeleteContents();
}
CSharedMemWinView* CSharedMemWinDoc::GetView(void)
{
POSITION pos = GetFirstViewPosition();
while (pos!=NULL) {
CSharedMemWinView* pview = (CSharedMemWinView*)GetNextView(pos);
if (this==pview->GetDocument()) return pview;
}
return NULL;
}
void CSharedMemWinDoc::clear(void)
{
save_fname = "";
CSingleLock lock(&criticalKey);
lock.Lock();
while (!lock.IsLocked()) {
Sleep(100);
lock.Lock();
}
bufferRing->clear();
lock.Unlock();
return;
}
int CSharedMemWinDoc::writeLogFile(void)
{
if (save_fname=="") return -1;
CSingleLock lock(&criticalKey);
lock.Lock();
while (!lock.IsLocked()) {
Sleep(100);
lock.Lock();
}
int size = 0;
//FILE* fp = fopen((LPCSTR)save_fname, "wb");
char* fname = jbxwl::ts2mbs(save_fname);
FILE* fp = fopen(fname, "wb");
freeNull(fname);
if (fp==NULL) {
lock.Unlock();
return -2;
}
for (int pos=0; pos<bufferRing->getMaxLineY(); pos++) {
Buffer buf = bufferRing->pBuf[pos];
//fwrite((const char*)buf.buf, buf.vldsz, 1, fp);
fwrite((const char*)buf.buf, strlen((const char*)buf.buf), 1, fp);
size += (int)strlen((const char*)buf.buf);
}
fclose(fp);
lock.Unlock();
return size;
}
CString CSharedMemWinDoc::easyGetSaveFileName(LPCSTR title, HWND hWnd)
{
OPENFILENAME ofn;
char fn[LNAME];
CString str = _T("");
bzero(fn, LNAME);
bzero(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hWnd;
ofn.Flags = 0;
ofn.lpstrFile = (LPWSTR)fn;
ofn.nMaxFile = LNAME;
if (title!=NULL) ofn.lpstrTitle = (LPCWSTR)title;
BOOL ret = GetSaveFileName(&ofn);
if (ret) str = fn;
return (LPWSTR)fn;
}