📄 logtestdlg.cpp
字号:
// LogTestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "LogTest.h"
#include "LogTestDlg.h"
#include "OutPutLog_ctrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define ID_CHANGE_COLOR 1
enum COLOR
{
COLOR_RED = RGB(255, 0, 255),
COLOR_ORANGE = RGB(255, 165, 0),
COLOR_YELLOW = RGB(255, 255, 0),
COLOR_GREEN = RGB( 0, 255, 0),
COLOR_BLUE = RGB( 0, 255, 255),
COLOR_DBLUE = RGB( 0, 0, 255),
COLOR_PURPLE = RGB(128, 0, 128)
};
static volatile byte g_btCount = 0;
COLORREF g_aColor[] = {COLOR_RED, COLOR_RED, COLOR_ORANGE, COLOR_YELLOW, COLOR_GREEN, COLOR_GREEN, COLOR_BLUE, COLOR_DBLUE, COLOR_DBLUE, COLOR_PURPLE};
__inline void ModifyExtension(OUT CString &strSource, const CString &strNewExtension)
{
strSource.Replace(strSource.Right(strSource.GetLength() - strSource.ReverseFind(_TEXT('.')) - 1), strNewExtension);
}
/////////////////////////////////////////////////////////////////////////////
// CLogTestDlg dialog
CLogTestDlg::CLogTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLogTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLogTestDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CLogTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLogTestDlg)
DDX_Control(pDX, IDC_STATIC_NOTICE, m_stcNotic);
DDX_Control(pDX, IDC_EDIT_STRING, m_edtString);
DDX_Control(pDX, IDC_EXCUTE, m_btnExec);
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLogTestDlg, CDialog)
//{{AFX_MSG_MAP(CLogTestDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_EXCUTE, OnExcute)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLogTestDlg message handlers
BOOL CLogTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
::GetModuleFileName(NULL, m_strAppPath.GetBuffer(MAX_PATH), MAX_PATH);
m_strAppPath.ReleaseBuffer();
m_strLogPath = m_strAppPath;
ModifyExtension(m_strLogPath, _T("log"));
#ifdef LOGTEST_LOG_OPEN
LOG_FILE_INIT(m_strLogPath);
#endif
LOGTEST_LOG("App path: %s", m_strAppPath);
LOGTEST_LOG("Log path: %s", m_strLogPath);
m_edtString.SetHoverInColor(RGB(0, 0, 255));
SetTimer(ID_CHANGE_COLOR, 200, NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CLogTestDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CLogTestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CLogTestDlg::OnCancel()
{
LOGTEST_LOG("OnCancel() IN");
#ifdef LOGTEST_LOG_OPEN
LOG_FILE_CLOSE();
#endif
CDialog::OnCancel();
}
void CLogTestDlg::OnOK()
{
LOGTEST_LOG("OnOK() IN");
#ifdef LOGTEST_LOG_OPEN
LOG_FILE_CLOSE();
#endif
CDialog::OnOK();
}
void CLogTestDlg::OnExcute()
{
LOGTEST_LOG("OnExcute() IN");
UpdateData();
CString strInfo = _T("");
GetDlgItemText(IDC_EDIT_STRING, strInfo);
LOGTEST_LOG("Input String is : %s", strInfo);
LOGTEST_LOG_HEX((LPCSTR)strInfo, strInfo.GetLength());
LOGTEST_LOG("Stop timer");
KillTimer(ID_CHANGE_COLOR);
LOGTEST_LOG("Change Static Color R=%u, G=%u, B=%u", 255, 0, 255);
m_stcNotic.SetTextColor(RGB(255, 0, 255));
LOGTEST_LOG("Start Log file!");
ShellExecute(this->GetSafeHwnd(), _T("open"), m_strLogPath, NULL, NULL, SW_MAXIMIZE);
LOGTEST_LOG("OnExcute() OUT");
}
void CLogTestDlg::OnTimer(UINT nIDEvent)
{
g_btCount = ++g_btCount % 10;
m_stcNotic.SetTextColor( *(g_aColor + g_btCount) );
CDialog::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -