-
Notifications
You must be signed in to change notification settings - Fork 11
/
EditLog.h
87 lines (66 loc) · 2.63 KB
/
EditLog.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
/*\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\ editlog.h, Fast asynchronous text logging using a Windows Edit-Control
/
\ Version: 1.0, created 2000-04-02
/ 1.1, 2000-07-11: Now *really* supports Win9x, uses V2.0 of SubclassWnd
\
/ Author: Daniel Lohmann (daniel@uni-koblenz.de)
\
/ Please send comments and bugfixes to the above email address.
\
/ This code is provided AS IS, you use it at your own risk!
\ You may use it for whatever you want.
/
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
#ifndef __EDITLOG_H__
#define __EDITLOG_H__
// We use the CSubclassWnd class, created by William E. Kempf (sirwillard@my-Deja.com)
// You can find the complete article at http://www.codeproject.com/miscctrl/subclasswnd.asp
#include "SubclassWnd.h"
///////////////////////////////////
// CEditLog class
// Implemets a fast, asynchronous and threadsave text logging for Edit-Controls
//
//
class CEditLog : protected CSubclassWnd
{
public:
typedef CSubclassWnd root_type;
// Constructs the CEditLog. You can pass the edit controls handle
// here or set it later using the SetEditCtrl() function.
// To increase performance CEditLog repaints the edit-control
// only if the caret resides in the last line. Otherwise the
// control will be refreshed only every nMaxRefreshDelay msec.
CEditLog( HWND hEdit = NULL, UINT nMaxRefreshDelay = 500 );
virtual ~CEditLog();
// Adds some text to the end of the edit control. Works asynchronously
// (using PostMessage()) and is save to be called by multiple threads.
// If you pass true for bLFtoCRLF every LF (ASCII 10) (as it is used in
// most cases for end-of-line) will be converted to a CR/LF (ASCII 10/13)
// sequence as it is needed by the windows edit control.
virtual void AddText( LPCWSTR pwszAdd, bool bLFtoCRLF = false );
// Converts pszAdd to UNICODE and calls the above
void AddText( LPCSTR pszAdd, bool bLFtoCRLF = false );
// Sets the edit-control to be used for logging.
// Pass NULL to stop text logging.
virtual void SetEditCtrl( HWND hEdit );
HWND GetEditCtrl() const
{
return GetHandle();
}
protected:
virtual BOOL ProcessWindowMessage( UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lResult );
void OnDestroy();
void OnTimer(UINT id);
bool OnAddText( bool bForce = false);
// This members are used by the GUI thread only
UINT m_nTimerID;
UINT m_nTimerDelay;
// This members are used by the GUI thread and
// every thread calling AddText, so we protect them with
// a Critical Section.
CRITICAL_SECTION m_csLock;
bool m_bMessagePending;
std::wstring m_wsStore;
};
#endif // __EDITLOG_H__