| | |
| | | #include "BondEq.h" |
| | | #include "afxdialogex.h" |
| | | #include "SystemLogManagerDlg.h" |
| | | #include "UserManager.h" |
| | | #include "SystemLogManager.h" |
| | | |
| | | |
| | | // CSystemLogManagerDlg 对话框 |
| | | |
| | | IMPLEMENT_DYNAMIC(CSystemLogManagerDlg, CDialogEx) |
| | | IMPLEMENT_DYNAMIC(CSystemLogManagerDlg, CBaseDlg) |
| | | |
| | | CSystemLogManagerDlg::CSystemLogManagerDlg(CWnd* pParent /*=nullptr*/) |
| | | : CDialogEx(IDD_DIALOG_SYSTEM_LOG_MANAGER, pParent) |
| | | : CBaseDlg(IDD_DIALOG_SYSTEM_LOG_MANAGER, pParent) |
| | | { |
| | | |
| | | } |
| | | |
| | | CSystemLogManagerDlg::~CSystemLogManagerDlg() |
| | |
| | | |
| | | void CSystemLogManagerDlg::DoDataExchange(CDataExchange* pDX) |
| | | { |
| | | CDialogEx::DoDataExchange(pDX); |
| | | CBaseDlg::DoDataExchange(pDX); |
| | | DDX_Control(pDX, IDC_COMBO_TYPE, m_comboType); |
| | | DDX_Control(pDX, IDC_COMBO_USER, m_comboUser); |
| | | DDX_Control(pDX, IDC_DATETIMEPICKER_START, m_dateTimeStart); |
| | |
| | | m_listLogs.SetFixedColumnCount(nFixCols); |
| | | |
| | | // Col |
| | | m_listLogs.SetColumnWidth(nColIdx, 20); |
| | | m_listLogs.SetColumnWidth(nColIdx, 10); |
| | | m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("No.")); |
| | | m_listLogs.SetColumnWidth(nColIdx, 70); |
| | | m_listLogs.SetColumnWidth(nColIdx, 10); |
| | | m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("类型")); |
| | | m_listLogs.SetColumnWidth(nColIdx, 150); |
| | | m_listLogs.SetColumnWidth(nColIdx, 100); |
| | | m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("事件")); |
| | | m_listLogs.SetColumnWidth(nColIdx, 70); |
| | | m_listLogs.SetColumnWidth(nColIdx, 30); |
| | | m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("用户")); |
| | | m_listLogs.SetColumnWidth(nColIdx, 70); |
| | | m_listLogs.SetColumnWidth(nColIdx, 50); |
| | | m_listLogs.SetItemText(nRowIdx, nColIdx++, _T("时间")); |
| | | |
| | | // 创建 20 行空白数据行 |
| | |
| | | } |
| | | } |
| | | |
| | | m_listLogs.Invalidate(); |
| | | m_listLogs.UpdateWindow(); |
| | | m_listLogs.ExpandColumnsToFit(FALSE); |
| | | m_listLogs.ExpandLastColumn(); |
| | | m_listLogs.Invalidate(); |
| | | m_listLogs.UpdateWindow(); |
| | | |
| | | UpdatePageInfo(); |
| | | } |
| | | |
| | |
| | | m_staticPageNum.SetWindowText(pageInfo); |
| | | } |
| | | |
| | | void CSystemLogManagerDlg::SetDefaultFont() |
| | | { |
| | | CFont* pFont = new CFont(); |
| | | LOGFONT logFont = { 0 }; |
| | | |
| | | // 设置字体属性 |
| | | _tcscpy_s(logFont.lfFaceName, _T("Segoe UI")); // 使用清晰字体 |
| | | logFont.lfHeight = -12; // 字体高度 |
| | | logFont.lfWeight = FW_NORMAL; |
| | | logFont.lfQuality = CLEARTYPE_QUALITY; // 启用 ClearType 抗锯齿 |
| | | |
| | | pFont->CreateFontIndirect(&logFont); |
| | | |
| | | // 遍历所有控件,应用字体 |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0 |
| | | || _tcsicmp(szClassName, _T("ComboBoxs")) == 0) { |
| | | pWnd = pWnd->GetNextWindow(); |
| | | continue; |
| | | } |
| | | |
| | | pWnd->SetFont(pFont, TRUE); |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | } |
| | | |
| | | void CSystemLogManagerDlg::AdjustControls(int nWidth, int nHeight) |
| | | { |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | UINT nCtrlID = pWnd->GetDlgCtrlID(); |
| | | |
| | | CRect ctrlRect; |
| | | pWnd->GetWindowRect(&ctrlRect); |
| | | ScreenToClient(&ctrlRect); |
| | | |
| | | // 计算控件的新位置和大小,按比例调整 |
| | | int newX = (int)(ctrlRect.left * (nWidth / (float)m_nInitialWidth)); |
| | | int newY = (int)(ctrlRect.top * (nHeight / (float)m_nInitialHeight)); |
| | | int newWidth = (int)(ctrlRect.Width() * (nWidth / (float)m_nInitialWidth)); |
| | | int newHeight = (int)(ctrlRect.Height() * (nHeight / (float)m_nInitialHeight)); |
| | | |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | |
| | | |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | CGridCtrl* pGridCtrl = (CGridCtrl*)pWnd; |
| | | pGridCtrl->SetDefCellHeight(newHeight / 21); |
| | | pGridCtrl->ExpandColumnsToFit(TRUE); |
| | | pGridCtrl->Invalidate(); |
| | | } |
| | | |
| | | pWnd->MoveWindow(newX, newY, newWidth, newHeight); |
| | | AdjustControlFont(pWnd, newWidth, newHeight); |
| | | |
| | | // 获取下一个控件 |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | } |
| | | |
| | | void CSystemLogManagerDlg::AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight) |
| | | { |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | |
| | | if (_tcsicmp(szClassName, _T("Static")) == 0) { |
| | | CStatic* pStatic = (CStatic*)pWnd; |
| | | pStatic->ModifyStyle(SS_CENTER | SS_RIGHT | SS_CENTERIMAGE, SS_LEFT | SS_CENTERIMAGE); |
| | | return; |
| | | } |
| | | |
| | | if (_tcsicmp(szClassName, _T("ComboBox")) == 0) { |
| | | CComboBox* pComboBox = (CComboBox*)pWnd; |
| | | pComboBox->SetItemHeight(-1, nHeight); // -1 表示所有项的高度 |
| | | } |
| | | |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | return; |
| | | } |
| | | |
| | | int fontSize = nHeight - 10; |
| | | CFont* pCurrentFont = pWnd->GetFont(); |
| | | LOGFONT logFont; |
| | | pCurrentFont->GetLogFont(&logFont); |
| | | logFont.lfHeight = -fontSize; |
| | | |
| | | CFont newFont; |
| | | newFont.CreateFontIndirect(&logFont); |
| | | |
| | | pWnd->SetFont(&newFont); |
| | | pWnd->Invalidate(); |
| | | } |
| | | |
| | | |
| | | void CSystemLogManagerDlg::AdjustComboBoxStyle(CComboBox& comboBox) |
| | | { |
| | | DWORD dwStyle = comboBox.GetStyle(); |
| | | comboBox.ModifyStyle(0, CBS_DROPDOWNLIST | CBS_HASSTRINGS | CBS_OWNERDRAWFIXED); |
| | | |
| | | comboBox.Invalidate(); |
| | | comboBox.UpdateWindow(); |
| | | } |
| | | |
| | | |
| | | void CSystemLogManagerDlg::AdjustDateTimeCtrlStyle(CDateTimeCtrl& dateTimeCtrl) |
| | | { |
| | | dateTimeCtrl.ModifyStyle(0, DTS_RIGHTALIGN); |
| | | dateTimeCtrl.Invalidate(); |
| | | dateTimeCtrl.UpdateWindow(); |
| | | } |
| | | |
| | | |
| | | BEGIN_MESSAGE_MAP(CSystemLogManagerDlg, CDialogEx) |
| | | BEGIN_MESSAGE_MAP(CSystemLogManagerDlg, CBaseDlg) |
| | | ON_BN_CLICKED(IDC_BUTTON_SEARCH, &CSystemLogManagerDlg::OnBnClickedButtonSearch) |
| | | ON_BN_CLICKED(IDC_BUTTON_PREV_PAGE, &CSystemLogManagerDlg::OnBnClickedButtonPrevPage) |
| | | ON_BN_CLICKED(IDC_BUTTON_NEXT_PAGE, &CSystemLogManagerDlg::OnBnClickedButtonNextPage) |
| | | ON_CBN_SELCHANGE(IDC_COMBO_TYPE, &CSystemLogManagerDlg::OnSelchangeComboType) |
| | | ON_CBN_SELCHANGE(IDC_COMBO_USER, &CSystemLogManagerDlg::OnSelchangeComboUser) |
| | | ON_WM_SIZE() |
| | | END_MESSAGE_MAP() |
| | | |
| | | |
| | |
| | | |
| | | BOOL CSystemLogManagerDlg::OnInitDialog() |
| | | { |
| | | CDialogEx::OnInitDialog(); |
| | | CBaseDlg::OnInitDialog(); |
| | | |
| | | // TODO: 在此添加额外的初始化 |
| | | SetWindowText(_T("系统运行日志")); |
| | |
| | | COleDateTime defaultStartTime = currentTime - COleDateTimeSpan(30, 0, 0, 0); |
| | | m_dateTimeStart.SetTime(defaultStartTime); |
| | | |
| | | CRect screenRect, dlgRect, clientRect; |
| | | GetClientRect(&clientRect); |
| | | m_nInitialWidth = clientRect.Width(); |
| | | m_nInitialHeight = clientRect.Height(); |
| | | |
| | | GetWindowRect(&dlgRect); |
| | | int dlgWidth = dlgRect.Width() * 2; |
| | | int dlgHeight = dlgRect.Height() * 2; |
| | | |
| | | SystemParametersInfo(SPI_GETWORKAREA, 0, &screenRect, 0); |
| | | if (dlgWidth > screenRect.Width()) { |
| | | dlgWidth = screenRect.Width(); |
| | | } |
| | | if (dlgHeight > screenRect.Height()) { |
| | | dlgHeight = screenRect.Height(); |
| | | } |
| | | |
| | | int centerX = screenRect.left + (screenRect.Width() - dlgWidth) / 2; |
| | | int centerY = screenRect.top + (screenRect.Height() - dlgHeight) / 2; |
| | | MoveWindow(centerX, centerY, dlgWidth, dlgHeight); |
| | | |
| | | InitSystemLogManager(); |
| | | |
| | | return TRUE; // return TRUE unless you set the focus to a control |
| | | // 异常: OCX 属性页应返回 FALSE |
| | | } |
| | | |
| | | |
| | | void CSystemLogManagerDlg::OnSize(UINT nType, int cx, int cy) |
| | | { |
| | | CDialogEx::OnSize(nType, cx, cy); |
| | | |
| | | // TODO: 在此处添加消息处理程序代码 |
| | | CRect rect; |
| | | GetClientRect(&rect); |
| | | |
| | | // 遍历对话框中的所有控件 |
| | | AdjustControls(rect.Width(), rect.Height()); |
| | | //SetDefaultFont(); |
| | | } |
| | | |
| | | |
| | | void CSystemLogManagerDlg::OnBnClickedButtonSearch() |
| | | { |
| | |
| | | AfxMessageBox(errorMsg, MB_ICONERROR); |
| | | } |
| | | } |
| | | |
| | | |
| | | void CSystemLogManagerDlg::OnBnClickedButtonPrevPage() |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | void CSystemLogManagerDlg::OnBnClickedButtonNextPage() |
| | | { |
| | | // TODO: 在此添加控件通知处理程序代码 |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | void CSystemLogManagerDlg::OnSelchangeComboType() |
| | | { |
| | | // TODO: 在此添加控件通知处理程序代码 |
| | |
| | | AfxMessageBox(errorMsg, MB_ICONERROR); |
| | | } |
| | | } |
| | | |
| | | |
| | | void CSystemLogManagerDlg::OnSelchangeComboUser() |
| | | { |