// LogDlg.cpp : implementation file
//
#include "stdafx.h"
#include "NICE.h"
#include "LogDlg.h"
// CLogDlg dialog
IMPLEMENT_DYNAMIC(CLogDlg, CDialog)
CLogDlg::CLogDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLogDlg::IDD, pParent)
{
AfxInitRichEdit2();
}
CLogDlg::~CLogDlg()
{
}
void CLogDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_RICHEDITLOG, m_ctrlLog);
}
BEGIN_MESSAGE_MAP(CLogDlg, CDialog)
ON_COMMAND(IDC_BUTTON_CLEAR, CLogDlg::OnClear)
END_MESSAGE_MAP()
// CLogDlg message handlers
int CLogDlg::AppendToLog(CString str, COLORREF color)
{
int nOldLines = 0, nNewLines = 0, nScroll = 0;
long nInsertionPoint = 0;
CHARFORMAT cf;
// Save number of lines before insertion of new text
nOldLines = m_ctrlLog.GetLineCount();
// Initialize character format structure
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_COLOR;
cf.dwEffects = 0; // To disable CFE_AUTOCOLOR
cf.crTextColor = color;
// Set insertion point to end of text
nInsertionPoint = m_ctrlLog.GetWindowTextLength();
m_ctrlLog.SetSel(nInsertionPoint, -1);
// Set the character format
m_ctrlLog.SetSelectionCharFormat(cf);
// Replace selection. Because we have nothing
// selected, this will simply insert
// the string at the current caret position.
m_ctrlLog.ReplaceSel(str);
// Get new line count
nNewLines = m_ctrlLog.GetLineCount();
// Scroll by the number of lines just inserted
nScroll = nNewLines - nOldLines;
m_ctrlLog.LineScroll(nScroll);
return 0;
}
void CLogDlg::OnClear()
{
}