102 lines
2.7 KiB
C++
102 lines
2.7 KiB
C++
#include "stdafx.h"
|
|
#include "LogPanel.h"
|
|
|
|
//////////////////////////////////////////
|
|
// CLogView
|
|
//////////////////////////////////////////
|
|
|
|
int CLogView::OnCreate(CREATESTRUCT&)
|
|
{
|
|
CRect rc = GetClientRect();
|
|
HINSTANCE inst = ::GetModuleHandleW(nullptr);
|
|
m_hEdit = ::CreateWindowExW(
|
|
0, L"EDIT", L"",
|
|
WS_CHILD | WS_VISIBLE | WS_VSCROLL |
|
|
ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY,
|
|
0, 0, rc.Width(), rc.Height(),
|
|
GetHwnd(), nullptr, inst, nullptr);
|
|
|
|
HFONT hFont = static_cast<HFONT>(::GetStockObject(DEFAULT_GUI_FONT));
|
|
::SendMessageW(m_hEdit, WM_SETFONT, (WPARAM)hFont, TRUE);
|
|
::SendMessageW(m_hEdit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELPARAM(4, 4));
|
|
return 0;
|
|
}
|
|
|
|
void CLogView::AppendLine(const CString& text)
|
|
{
|
|
if (!m_hEdit) return;
|
|
int len = ::GetWindowTextLengthW(m_hEdit);
|
|
::SendMessageW(m_hEdit, EM_SETSEL, (WPARAM)len, (LPARAM)len);
|
|
CString line = text + L"\r\n";
|
|
::SendMessageW(m_hEdit, EM_REPLACESEL, FALSE, (LPARAM)line.c_str());
|
|
::SendMessageW(m_hEdit, EM_SCROLLCARET, 0, 0);
|
|
}
|
|
|
|
void CLogView::Clear()
|
|
{
|
|
if (m_hEdit) ::SetWindowTextW(m_hEdit, L"");
|
|
}
|
|
|
|
LRESULT CLogView::WndProc(UINT msg, WPARAM wparam, LPARAM lparam)
|
|
{
|
|
try {
|
|
if (msg == WM_SIZE) {
|
|
if (m_hEdit) {
|
|
int w = LOWORD(lparam), h = HIWORD(lparam);
|
|
::MoveWindow(m_hEdit, 0, 0, w, h, TRUE);
|
|
}
|
|
}
|
|
return WndProcDefault(msg, wparam, lparam);
|
|
}
|
|
catch (const CException& e) {
|
|
CString s;
|
|
s << e.GetText() << L'\n' << e.GetErrorString();
|
|
::MessageBox(nullptr, s, L"Error", MB_ICONERROR);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
//////////////////////////////////////////
|
|
// CLogContainer
|
|
//////////////////////////////////////////
|
|
|
|
CLogContainer::CLogContainer()
|
|
{
|
|
SetTabText(L"Log");
|
|
SetDockCaption(L"Log");
|
|
SetView(m_view);
|
|
}
|
|
|
|
LRESULT CLogContainer::WndProc(UINT msg, WPARAM wparam, LPARAM lparam)
|
|
{
|
|
try { return WndProcDefault(msg, wparam, lparam); }
|
|
catch (const CException& e) {
|
|
CString s;
|
|
s << e.GetText() << L'\n' << e.GetErrorString();
|
|
::MessageBox(nullptr, s, L"Error", MB_ICONERROR);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
//////////////////////////////////////////
|
|
// CDockLog
|
|
//////////////////////////////////////////
|
|
|
|
CDockLog::CDockLog()
|
|
{
|
|
SetView(m_container);
|
|
SetBarWidth(3);
|
|
SetBarColor(RGB(204, 206, 210));
|
|
}
|
|
|
|
LRESULT CDockLog::WndProc(UINT msg, WPARAM wparam, LPARAM lparam)
|
|
{
|
|
try { return WndProcDefault(msg, wparam, lparam); }
|
|
catch (const CException& e) {
|
|
CString s;
|
|
s << e.GetText() << L'\n' << e.GetErrorString();
|
|
::MessageBox(nullptr, s, L"Error", MB_ICONERROR);
|
|
}
|
|
return 0;
|
|
}
|