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
|
// **********************************************************************
//
// Copyright (c) 2003-2009 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
#include <IceUtil/DisableWarnings.h>
#include <stdafx.h>
#include <LogI.h>
using namespace std;
LogI::LogI() :
_hwnd(0)
{
}
void
LogI::print(const string& msg)
{
string s = msg;
string::size_type idx = 0;
while((idx = s.find("\n", idx)) != string::npos)
{
s.replace(idx, 1, "\r\n ");
idx += 3;
}
message(s);
}
void
LogI::trace(const string& category, const string& msg)
{
string s = "[ " + category + ": " + msg + " ]";
string::size_type idx = 0;
while((idx = s.find("\n", idx)) != string::npos)
{
s.replace(idx, 1, "\r\n ");
idx += 3;
}
message(s);
}
void
LogI::warning(const string& msg)
{
message("warning: " + msg);
}
void
LogI::error(const string& msg)
{
message("error: " + msg);
}
void
LogI::message(const string& msg)
{
string line = msg + "\r\n";
if(_hwnd)
{
post(line);
}
else
{
_buffer.append(line);
}
}
void
LogI::setHandle(HWND hwnd)
{
_hwnd = hwnd;
if(_hwnd != 0 && !_buffer.empty())
{
post(_buffer);
_buffer.clear();
}
}
void
LogI::post(const string& data)
{
assert(_hwnd != 0);
char* text = new char[data.size()+1];
strcpy(text, data.c_str());
::PostMessage(_hwnd, WM_USER, (WPARAM)FALSE, (LPARAM)text);
}
|