summaryrefslogtreecommitdiffabout
path: root/T42View.cpp
blob: 8ccad1c58dec11cca869ae0065e8ba9ced01d221 (plain)
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
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
// T42View.cpp : implementation file
//

#include "stdafx.h"
#include "T42.h"
#include "T42View.h"

#include "T42Frame.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// T42View

IMPLEMENT_DYNCREATE(T42View, CFormView)

T42View::T42View()
	: CFormView(T42View::IDD)
{
	//{{AFX_DATA_INIT(T42View)
	//}}AFX_DATA_INIT
	m_localCtl.m_pView = m_remoteCtl.m_pView = this;
	m_pFrame = NULL;
	m_localSize = 50;
	m_remoteSize = 50;
	m_gapSize = 5;
	m_Ort = ortHorizontal;
	m_bShown = FALSE;
	m_bTracking = FALSE;
	m_hHorzCursor = AfxGetApp()->LoadStandardCursor(IDC_SIZENS);
	m_hVertCursor = AfxGetApp()->LoadStandardCursor(IDC_SIZEWE);
	m_bEnabled = FALSE;
}

T42View::~T42View()
{
}

void T42View::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(T42View)
	DDX_Control(pDX, IDC_SPLIT, m_splitCtl);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(T42View, CFormView)
	//{{AFX_MSG_MAP(T42View)
	ON_WM_SIZE()
	ON_MESSAGE(WM_SPLITTERBDOWN, OnSplitterBDown)
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONUP()
	ON_WM_SETCURSOR()
	ON_COMMAND(ID_WINDOW_SPLITEQUALLY, OnWindowSplitequally)
	ON_UPDATE_COMMAND_UI(ID_WINDOW_HORIZONTALSPLIT, OnUpdateWindowHorizontalsplit)
	ON_UPDATE_COMMAND_UI(ID_WINDOW_VERTICALSPLIT, OnUpdateWindowVerticalsplit)
	ON_COMMAND(ID_WINDOW_HORIZONTALSPLIT, OnWindowHorizontalsplit)
	ON_COMMAND(ID_WINDOW_VERTICALSPLIT, OnWindowVerticalsplit)
	ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
	ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
	ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
	ON_WM_CANCELMODE()
	ON_UPDATE_COMMAND_UI(ID_TEA_SAVE, OnUpdateTeaSave)
	ON_COMMAND(ID_TEA_SAVE, OnTeaSave)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// T42View diagnostics

#ifdef _DEBUG
void T42View::AssertValid() const
{
	CFormView::AssertValid();
}

void T42View::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// T42View message handlers
/////////////////////////////////////////////////////////////////////////////
// CSplitBar

CSplitBar::CSplitBar()
{
}

CSplitBar::~CSplitBar()
{
}


BEGIN_MESSAGE_MAP(CSplitBar, CStatic)
	//{{AFX_MSG_MAP(CSplitBar)
	ON_WM_LBUTTONDOWN()
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSplitBar message handlers

void CSplitBar::OnLButtonDown(UINT nFlags, CPoint point) 
{
	GetParent()->PostMessage(WM_SPLITTERBDOWN);
}

void CSplitBar::OnPaint() 
{
CPaintDC dc(this); // device context for painting
CRect rc;
	GetWindowRect(rc);
	ScreenToClient(rc);
	dc.DrawEdge(rc,EDGE_RAISED,(m_Ort==T42View::ortVertical)?BF_LEFT|BF_RIGHT:BF_TOP|BF_BOTTOM);
}

void T42View::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();
	m_pFrame = (T42Frame*)GetParent();
	ASSERT_KINDOF(T42Frame,m_pFrame);
	SetScaleToFitSize(CSize(10,10));

	m_localCtl.Create(WS_CHILD|WS_VISIBLE|ES_AUTOVSCROLL|ES_LEFT|ES_MULTILINE|ES_WANTRETURN|WS_VSCROLL,
		CRect(0,0,0,0), this, 0);
	m_remoteCtl.Create(WS_CHILD|WS_VISIBLE|ES_AUTOVSCROLL|ES_LEFT|ES_MULTILINE|ES_WANTRETURN|WS_VSCROLL,
		CRect(0,0,0,0), this, 0);
	m_localCtl.SetFocus();
	m_localCtl.m_pInTEC = &m_pFrame->m_localEC;
	m_localCtl.m_pOuTEC = &m_pFrame->m_remoteEC;
	m_remoteCtl.m_pInTEC = &m_pFrame->m_remoteEC;
	m_remoteCtl.m_pOuTEC = &m_pFrame->m_localEC;


	LoadLayout();

	RecalcLayout();
	m_bShown=TRUE;
}

void T42View::RecalcLayout()
{
UINT lrs = m_localSize+m_remoteSize;
	m_splitCtl.m_Ort = m_Ort;
CRect crc;
	GetClientRect(crc);
CRect rc;
UINT ls = m_localSize, rs = m_remoteSize;
	if(m_Ort==ortHorizontal){
	UINT lr = crc.Height()-m_gapSize;
		rc.top = rc.left = 0;
		rc.right = crc.right;

		ls = lr*m_localSize/lrs;
		rc.bottom = ls;
		m_localCtl.MoveWindow(rc);

		rc.top=rc.bottom+1;
		rc.bottom=rc.top+m_gapSize-1;
		m_splitCtl.MoveWindow(rc);

		rc.top=rc.bottom+1;
		rc.bottom=crc.bottom;
		rs = rc.Height();
		m_remoteCtl.MoveWindow(rc);
	}else if(m_Ort==ortVertical){
	CRect crc;
		GetClientRect(crc);
	CRect rc;
	UINT lr = crc.Width()-m_gapSize;
		rc.top = rc.left = 0;
		rc.bottom = crc.bottom;

		ls = lr*m_localSize/lrs;
		rc.right = ls;
		m_localCtl.MoveWindow(rc);

		rc.left=rc.right+1;
		rc.right=rc.left+m_gapSize-1;
		m_splitCtl.MoveWindow(rc);

		rc.left=rc.right+1;
		rc.right=crc.right;
		rs = rc.Width();
		m_remoteCtl.MoveWindow(rc);
	}else
		ASSERT(FALSE);
	m_localSize = ls; m_remoteSize = rs;
}

void T42View::OnSize(UINT nType, int cx, int cy) 
{
	CFormView::OnSize(nType, cx, cy);
	if(m_bShown)
		RecalcLayout();
}

LRESULT T42View::OnSplitterBDown(WPARAM,LPARAM)
{
	SetCapture();
	m_bTracking = TRUE;
CRect rc;
	GetClientRect(rc);
	if(m_Ort==ortHorizontal){
		ASSERT(rc.Height()>25);
		rc.top+=10;
		rc.bottom-=10;
	}else{
		ASSERT(rc.Width()>25);
		rc.left+=10;
		rc.right-=10;
	}
	ClientToScreen(rc);
	ClipCursor(&rc);
	return 0;
}

void T42View::OnMouseMove(UINT nFlags, CPoint point) 
{
	if(m_bTracking){
	CRect rc;
		GetClientRect(rc);
		if(m_Ort==ortHorizontal){
			m_localSize = point.y;
			m_remoteSize = rc.bottom-point.y;
		}else{
			m_localSize = point.x;
			m_remoteSize = rc.right-point.x;
		}
		RecalcLayout();
	}
	
	CFormView::OnMouseMove(nFlags, point);
}

void T42View::OnLButtonUp(UINT nFlags, CPoint point) 
{
	if(m_bTracking){
		ClipCursor(NULL);
		m_bTracking=FALSE;
		ReleaseCapture();
	}
	CFormView::OnLButtonUp(nFlags, point);
}
/////////////////////////////////////////////////////////////////////////////
// CLocalCtl

CLocalCtl::CLocalCtl()
{
CT42App* app = (CT42App*)AfxGetApp();
	m_bgColor = app->m_crT42LocalBG;
	memmove(&m_fmtUser,&app->m_fmtT42Local,sizeof(m_fmtUser));
	memmove(&m_fmtSystem,&app->m_fmtT42System,sizeof(m_fmtSystem));
}

CLocalCtl::~CLocalCtl()
{
}


BEGIN_MESSAGE_MAP(CLocalCtl, CRichTalkCtl)
	//{{AFX_MSG_MAP(CLocalCtl)
	ON_WM_CREATE()
	ON_WM_CHAR()
	ON_WM_KEYDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLocalCtl message handlers
/////////////////////////////////////////////////////////////////////////////
// CRemoteCtl

CRemoteCtl::CRemoteCtl()
{
CT42App* app = (CT42App*)AfxGetApp();
	m_bgColor = app->m_crT42RemoteBG;
	memmove(&m_fmtUser,&app->m_fmtT42Remote,sizeof(m_fmtUser));
	memmove(&m_fmtSystem,&app->m_fmtT42System,sizeof(m_fmtSystem));
}

CRemoteCtl::~CRemoteCtl()
{
}


BEGIN_MESSAGE_MAP(CRemoteCtl, CRichTalkCtl)
	//{{AFX_MSG_MAP(CRemoteCtl)
	ON_WM_CREATE()
	ON_WM_CHAR()
	ON_WM_KEYDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRemoteCtl message handlers

void CRichTalkCtl::Setup()
{
	ModifyStyle(0,WS_VSCROLL);
	SetOptions(ECOOP_SET,ECO_AUTOWORDSELECTION|ECO_AUTOVSCROLL|ECO_READONLY|
		ECO_WANTRETURN|ECO_SAVESEL|ECO_SELECTIONBAR|ECO_NOHIDESEL);
	SetTargetDevice(NULL,0);
	SetSel(0,-1);
PARAFORMAT pf;
	memset(&pf,0,sizeof(pf));
	pf.cbSize = sizeof(pf);
	pf.dwMask = PFM_OFFSET;
	pf.dxOffset = 20;
	SetParaFormat(pf);
	SetDefaultCharFormat(m_fmtUser);
	SetSelectionCharFormat(m_fmtUser);
	SetSel(-1,-1);
	SetColor();
}

int CRemoteCtl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CRichEditCtrl::OnCreate(lpCreateStruct) == -1)
		return -1;
	Setup();
	return 0;
}

int CLocalCtl::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CRichEditCtrl::OnCreate(lpCreateStruct) == -1)
		return -1;
	Setup();
	return 0;
}

void CLocalCtl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if(!m_pView->m_bEnabled)
		return;
	if(!(nFlags&0x8000)){
		ASSERT(m_pView && m_pView->m_pFrame);
		if(nChar=='\r')
			nChar='\n';
	UINT c = nChar;
		if(c=='\b')
			c=m_pOuTEC->m_cErase;
		m_pView->m_pFrame->PostMessage(WM_TALKCHAR,c);
		PutCharacter(nChar);
	}
}

void CRemoteCtl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if(!m_pView->m_bEnabled)
		return;
	if(!(nFlags&0x8000)){
		ASSERT(m_pView && m_pView->m_pFrame);
		if(nChar=='\r')
			nChar='\n';
	UINT c = nChar;
		if(c=='\b')
			c=m_pOuTEC->m_cErase;
		m_pView->m_pFrame->PostMessage(WM_TALKCHAR,c);
		m_pView->m_localCtl.SetFocus();
		m_pView->m_localCtl.PutCharacter(nChar);
	}
}

void CRichTalkCtl::PutString(LPCTSTR str)
{
CString s = str;
CHAR span[] = { '\r','\n','\a','\b',m_pInTEC->m_cErase,0 };
CString sss;
	while(!s.IsEmpty()){
		sss=s.SpanExcluding(span);
		if(!sss.IsEmpty()){
		BOOL bDo = !GetTextLength();
			SetSel(-1,-1);
		long ss,es;
			if(bDo)
				GetSel(ss,es);
			ReplaceSel(sss);
			if(bDo){
				SetSel(ss,-1);
				SetSelectionCharFormat(m_fmtUser);
				SetSel(-1,-1);
			}
			s = s.Mid(sss.GetLength());
		}
		if(!s.IsEmpty()){
			PutCharacter(s[0]);
			s=s.Mid(1);
		}
	}
	UnlockWindowUpdate();
}

void CRichTalkCtl::PutCharacter(CHAR c)
{
	if(c=='\r')
		return;
	if(c=='\a'){
	CT42App* app = (CT42App*)AfxGetApp();
		ASSERT(app);
		app->StartSound(app->m_sndT42Bell);
		return;
	}else if(c=='\b' || c==m_pInTEC->m_cErase){
		SetSel(-1,-1);
	CHARRANGE cr;
		GetSel(cr);
		if(cr.cpMin>0){
			cr.cpMin--;
			SetSel(cr);
			ReplaceSel("");
		}else
			MessageBeep(0xFFFFFFFF);
		return;
	}
BOOL bDo = !GetTextLength();
	SetSel(-1,-1);
char tmp[2] = {c,0};
long ss,es;
	if(bDo)
		GetSel(ss,es);
	ReplaceSel(tmp);
	if(bDo){
		SetSel(ss,-1);
		SetSelectionCharFormat(m_fmtUser);
		SetSel(-1,-1);
	}
	UnlockWindowUpdate();
}

void CRichTalkCtl::SystemMessage(LPCTSTR str)
{
	SetSel(-1,-1);

	if(
		GetTextLength()
		&& LineLength()
	)
		ReplaceSel("\n");

CString tmp = "[";
	tmp+=str;
	tmp+=']';
long ss,es;
	GetSel(ss,es);
	ReplaceSel(tmp);
	SetSel(ss,-1);
	SetSelectionCharFormat(m_fmtSystem);
	SetSel(-1,-1);
	GetSel(ss,es);
	ReplaceSel("\n");
	SetSel(ss,-1);
	SetSelectionCharFormat(m_fmtUser);
	SetSel(-1,-1);
	UnlockWindowUpdate();
}

BOOL T42View::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
BOOL rv = CFormView::OnSetCursor(pWnd, nHitTest, message);
	if(rv)
		return rv;
	if(pWnd==&m_splitCtl){
		if(m_Ort==ortVertical){
			SetCursor(m_hVertCursor);
		}else{
			SetCursor(m_hHorzCursor);
		}
		return TRUE;
	}
	return FALSE;
}

void CLocalCtl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	CRichTalkCtl::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CRichTalkCtl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	switch(nChar){
	case	VK_INSERT:
	case	VK_DELETE:
	case	VK_BACK:
	case	VK_ESCAPE:
		return;
	}
	CRichEditCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}

void CRemoteCtl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	CRichTalkCtl::OnKeyDown(nChar, nRepCnt, nFlags);
}

void T42View::OnWindowSplitequally() 
{
	m_localSize = m_remoteSize = 50;
	RecalcLayout();
}

void T42View::OnUpdateWindowHorizontalsplit(CCmdUI* pCmdUI) 
{
	pCmdUI->SetRadio(m_Ort==ortHorizontal);
}

void T42View::OnUpdateWindowVerticalsplit(CCmdUI* pCmdUI) 
{
	pCmdUI->SetRadio(m_Ort==ortVertical);
}

void T42View::OnWindowHorizontalsplit() 
{
	m_Ort = ortHorizontal;
	RecalcLayout();
}

void T42View::OnWindowVerticalsplit() 
{
	m_Ort = ortVertical;
	RecalcLayout();
}


void T42View::SetEnable(BOOL bEnable)
{
	m_bEnabled = bEnable;
	m_localCtl.SetColor();
	m_remoteCtl.SetColor();
}

void CRichTalkCtl::SetColor()
{
	if(m_pView->m_bEnabled)
		SetBackgroundColor(FALSE,m_bgColor);
	else{
		SetBackgroundColor(
			FALSE,
			RGB(
				GetRValue(m_bgColor)/2,
				GetGValue(m_bgColor)/2,
				GetBValue(m_bgColor)/2
			)
		);
	}
}

void T42View::OnEditCopy() 
{
CWnd* pWnd = GetFocus();
	if(pWnd==&m_localCtl)
		m_localCtl.Copy();
	else if(pWnd==&m_remoteCtl)
		m_remoteCtl.Copy();
	else
		MessageBeep(MB_OK);
}

void T42View::OnEditPaste() 
{
	ASSERT(m_pFrame);
	if(!m_bEnabled)
		return;
	if(!IsClipboardFormatAvailable(CF_TEXT))
		return;
	if(!OpenClipboard())
		return;
HANDLE h = GetClipboardData(CF_TEXT);
LPVOID gl = GlobalLock(h);
	ASSERT(gl);
	m_pFrame->SendMessage(WM_TALKCHAR,0,(LPARAM)gl);
	m_localCtl.PutString((LPCTSTR)gl);
	GlobalUnlock(h);
	CloseClipboard();
}

void T42View::OnUpdateEditPaste(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(m_bEnabled && IsClipboardFormatAvailable(CF_TEXT));
}

void T42View::SaveLayout()
{
CWinApp* app = AfxGetApp();
	app->WriteProfileInt("T42View","LocalSize",m_localSize);
	app->WriteProfileInt("T42View","RemoteSize",m_remoteSize);
	app->WriteProfileInt("T42View","Orientation",m_Ort);
}

void T42View::OnCancelMode() 
{
	CFormView::OnCancelMode();
	if(m_bTracking){
		ClipCursor(NULL);
		m_bTracking=FALSE;
		ReleaseCapture();
	}
}

void T42View::LoadLayout()
{
CWinApp* app = AfxGetApp();
	m_localSize = app->GetProfileInt("T42View","LocalSize",m_localSize);
	m_remoteSize = app->GetProfileInt("T42View","RemoteSize",m_remoteSize);
_orientation ortSave = m_Ort;
	m_Ort = (_orientation)app->GetProfileInt("T42View","Orientation",m_Ort);
	if(m_Ort!=ortHorizontal && m_Ort!=ortVertical)
		m_Ort=ortSave;
}

void T42View::SystemMessage(LPCTSTR str)
{
CT42App* app = (CT42App*)AfxGetApp();
	m_localCtl.SystemMessage(str);
	m_remoteCtl.SystemMessage(str);
}


void T42View::OnUpdateTeaSave(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable(m_localCtl.GetTextLength() || m_remoteCtl.GetTextLength());
}

void T42View::OnTeaSave() 
{
CString dfn;
	dfn.Format(IDS_FILENAME_T42,	m_pFrame->m_LocalUser,m_pFrame->m_Target);
CString filter;
	VERIFY(filter.LoadString(IDS_FILTER_RTF));
CFileDialog fd(FALSE,".rtf",dfn,
			   OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_EXPLORER|
			   OFN_LONGNAMES|OFN_NOREADONLYRETURN|OFN_PATHMUSTEXIST,
			   filter,this
	);
	if(fd.DoModal()==IDOK){
		try{
		CStdioFile f(fd.GetPathName(),
				CFile::modeCreate|CFile::modeWrite|CFile::shareDenyWrite|
				CFile::typeText);
		CString rtf;
			rtf.Format(IDS_RTF_HEAD,m_pFrame->m_LocalUser,m_pFrame->m_Target);
			f.WriteString(rtf);
		CMemFile mf(2048);
		EDITSTREAM es;
			memset(&es,0,sizeof(es));
			es.dwCookie = (DWORD)&mf;
			es.pfnCallback = ESINProc;
			m_localCtl.StreamOut(SF_RTF,es);
		UINT tmp=0;
			mf.Write(&tmp,1);
		LONG bytes = mf.GetLength();
		LPBYTE pd = mf.Detach();
		LPTSTR str;
			while(str = strstr((LPCTSTR)pd,"\\rtf1"))memmove(str,&str[5],strlen(str)-4);
			while(str = strstr((LPCTSTR)pd,"\\pard"))memmove(str,&str[5],strlen(str)-4);
			f.Write(pd,strlen((LPCTSTR)pd));
			rtf.LoadString(IDS_RTF_DELIMITER);
			f.WriteString(rtf);
			mf.Attach(pd,bytes,2048);
			memset(&es,0,sizeof(es));
			es.dwCookie = (DWORD)&mf;
			es.pfnCallback = ESINProc;
			m_remoteCtl.StreamOut(SF_RTF,es);
			mf.Write(&tmp,1);
			bytes = mf.GetLength();
			pd = mf.Detach();
			while(str = strstr((LPCTSTR)pd,"\\rtf1"))memmove(str,&str[5],strlen(str)-4);
			while(str = strstr((LPCTSTR)pd,"\\pard"))memmove(str,&str[5],strlen(str)-4);
			f.Write(pd,strlen((LPCTSTR)pd));
			rtf.LoadString(IDS_RTF_TAIL);
			f.WriteString(rtf);
			delete pd;
			f.Close();
		}catch(CException* e){
			TRACE0("Write exception\n");
			e->Delete();
		}
	}
}

DWORD CALLBACK T42View::ESINProc(DWORD dwCookie,LPBYTE pbBuff,LONG cb,LONG FAR *pcb)
{
CFile* f = (CFile*)dwCookie;
	try{
		f->Write(pbBuff,cb);
		(*pcb)=cb;
	}catch(CException* e){
		e->Delete();
		TRACE0("Save Exception\n");
		(*pcb)=0;
		return 1;
	}
	return 0;
}