| | |
| | | |
| | | CAxisSettingsDlg::~CAxisSettingsDlg() |
| | | { |
| | | for (auto& pair : m_mapFonts) { |
| | | if (pair.second) { |
| | | pair.second->DeleteObject(); |
| | | delete pair.second; |
| | | } |
| | | } |
| | | m_mapFonts.clear(); |
| | | } |
| | | |
| | | void CAxisSettingsDlg::DoDataExchange(CDataExchange* pDX) |
| | | { |
| | | CDialogEx::DoDataExchange(pDX); |
| | | } |
| | | |
| | | void CAxisSettingsDlg::SetDefaultFont() |
| | | { |
| | | CFont* defaultFont = nullptr; |
| | | |
| | | // 如果字体管理容器中有默认大小(如 12)的字体,直接使用 |
| | | auto it = m_mapFonts.find(12); |
| | | if (it != m_mapFonts.end()) { |
| | | defaultFont = it->second; |
| | | } |
| | | else { |
| | | // 创建默认字体 |
| | | defaultFont = new CFont(); |
| | | LOGFONT logFont = { 0 }; |
| | | _tcscpy_s(logFont.lfFaceName, _T("Segoe UI")); |
| | | logFont.lfHeight = -12; |
| | | logFont.lfQuality = CLEARTYPE_QUALITY; |
| | | defaultFont->CreateFontIndirect(&logFont); |
| | | m_mapFonts[12] = defaultFont; // 存储到字体管理容器 |
| | | } |
| | | |
| | | // 遍历所有控件,应用默认字体 |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | pWnd->SetFont(defaultFont, TRUE); |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | } |
| | | |
| | | void CAxisSettingsDlg::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("ComboBox")) == 0) { |
| | | CComboBox* pComboBox = (CComboBox*)pWnd; |
| | | pComboBox->SetItemHeight(-1, nHeight); // -1 表示所有项的高度 |
| | | } |
| | | |
| | | pWnd->MoveWindow(newX, newY, newWidth, newHeight); |
| | | AdjustControlFont(pWnd, newWidth, newHeight); |
| | | |
| | | // 获取下一个控件 |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | } |
| | | |
| | | void CAxisSettingsDlg::AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight) |
| | | { |
| | | // 根据控件高度动态调整字体大小 |
| | | int fontSize = nHeight / 2; |
| | | if (fontSize < 8) fontSize = 8; |
| | | |
| | | // 检查字体是否已经存在 |
| | | auto it = m_mapFonts.find(fontSize); |
| | | if (it == m_mapFonts.end()) { |
| | | // 动态创建新字体 |
| | | CFont* newFont = new CFont(); |
| | | LOGFONT logFont = { 0 }; |
| | | _tcscpy_s(logFont.lfFaceName, _T("Segoe UI")); |
| | | logFont.lfHeight = -fontSize; |
| | | logFont.lfQuality = CLEARTYPE_QUALITY; // 启用 ClearType 抗锯齿 |
| | | newFont->CreateFontIndirect(&logFont); |
| | | |
| | | // 存储到字体管理容器中 |
| | | m_mapFonts[fontSize] = newFont; |
| | | it = m_mapFonts.find(fontSize); |
| | | } |
| | | |
| | | pWnd->SetFont(it->second); |
| | | pWnd->Invalidate(); // 刷新控件显示 |
| | | } |
| | | |
| | | |
| | |
| | | // TODO: 在此添加额外的初始化 |
| | | //ModifyStyle(0, WS_THICKFRAME | WS_SIZEBOX); |
| | | |
| | | CRect rect; |
| | | GetClientRect(&rect); |
| | | m_nInitialWidth = rect.Width(); |
| | | m_nInitialHeight = rect.Height(); |
| | | // 设置默认字体 |
| | | SetDefaultFont(); |
| | | |
| | | rect.right *= 1.5; |
| | | rect.bottom *= 1.5; |
| | | // 调整对话框大小 |
| | | MoveWindow(rect); |
| | | 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); |
| | | |
| | | return TRUE; // return TRUE unless you set the focus to a control |
| | | // 异常: OCX 属性页应返回 FALSE |
| | |
| | | void CAxisSettingsDlg::OnBnClickedButtonAxisTestStop() |
| | | { |
| | | // TODO: 在此添加控件通知处理程序代码 |
| | | } |
| | | |
| | | void CAxisSettingsDlg::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)); |
| | | |
| | | pWnd->MoveWindow(newX, newY, newWidth, newHeight); |
| | | AdjustControlFont(pWnd, newWidth, newHeight); |
| | | |
| | | // 获取下一个控件 |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | } |
| | | |
| | | void CAxisSettingsDlg::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(0, SS_CENTER | SS_CENTERIMAGE); |
| | | return; |
| | | } |
| | | |
| | | if (_tcsicmp(szClassName, _T("ComboBox")) == 0) { |
| | | CComboBox* pComboBox = (CComboBox*)pWnd; |
| | | pComboBox->SetItemHeight(-1, nHeight); // -1 表示所有项的高度 |
| | | } |
| | | |
| | | 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(); |
| | | } |
| | |
| | | enum { IDD = IDD_DIALOG_AXIS_SETTINGS }; |
| | | #endif |
| | | |
| | | private: |
| | | void SetDefaultFont(); |
| | | void AdjustControls(int nWidth, int nHeight); |
| | | void AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight); |
| | | |
| | | private: |
| | | int m_nInitialWidth; |
| | | int m_nInitialHeight; |
| | | std::map<int, CFont*> m_mapFonts; // 管理字体的容器,键为字体大小 |
| | | |
| | | protected: |
| | | virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 |
| | | virtual BOOL OnInitDialog(); |
| | |
| | | afx_msg void OnBnClickedButtonAxisTestJogSub(); |
| | | afx_msg void OnBnClickedButtonAxisTestStop(); |
| | | DECLARE_MESSAGE_MAP() |
| | | |
| | | private: |
| | | void AdjustControls(int nWidth, int nHeight); |
| | | void AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight); |
| | | |
| | | private: |
| | | int m_nInitialWidth; |
| | | int m_nInitialHeight; |
| | | }; |
| | |
| | | loginDlg.DoModal(); |
| | | } |
| | | else if (1 == menuId) { |
| | | // test |
| | | CSystemLogManagerDlg dlg; |
| | | dlg.DoModal(); |
| | | |
| | | CChangePasswordDlg changePasswordDlg; |
| | | changePasswordDlg.DoModal(); |
| | | } |
| | |
| | | } |
| | | } |
| | | else if (3 == menuId) { |
| | | CSystemLogManagerDlg dlg; |
| | | dlg.DoModal(); |
| | | } |
| | | else if (4 == menuId) { |
| | | int ret = AfxMessageBox(_T("是否切换用户?切换用户会退出当前账号!"), MB_OKCANCEL | MB_ICONEXCLAMATION); |
| | | if (ret != IDOK) { |
| | | return 0; |
| | |
| | | { |
| | | ::EnableMenuItem(hMenu, ID_OPEATOR_LOGIN, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| | | ::EnableMenuItem(hMenu, ID_OPERATOR_CHANGE_PASSWORD, MF_BYCOMMAND | MF_ENABLED); |
| | | ::EnableMenuItem(hMenu, ID_OPERATOR_SYSTEM_LOG, MF_BYCOMMAND | MF_ENABLED); |
| | | ::EnableMenuItem(hMenu, ID_OPEATOR_SWITCH, MF_BYCOMMAND | MF_ENABLED); |
| | | ::EnableMenuItem(hMenu, ID_OPERATOR_LOGOUT, MF_BYCOMMAND | MF_ENABLED); |
| | | |
| | |
| | | ::EnableMenuItem(hMenu, ID_OPEATOR_LOGIN, MF_BYCOMMAND | MF_ENABLED); |
| | | ::EnableMenuItem(hMenu, ID_OPERATOR_CHANGE_PASSWORD, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| | | ::EnableMenuItem(hMenu, ID_OPEATOR_USER_MANAGER, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| | | ::EnableMenuItem(hMenu, ID_OPERATOR_SYSTEM_LOG, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| | | ::EnableMenuItem(hMenu, ID_OPEATOR_SWITCH, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| | | ::EnableMenuItem(hMenu, ID_OPERATOR_LOGOUT, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); |
| | | |
| | |
| | | #include "BondEq.h" |
| | | #include "afxdialogex.h" |
| | | #include "SystemLogManagerDlg.h" |
| | | #include "UserManager.h" |
| | | #include "SystemLogManager.h" |
| | | |
| | | |
| | | // CSystemLogManagerDlg 对话框 |
| | |
| | | |
| | | CSystemLogManagerDlg::~CSystemLogManagerDlg() |
| | | { |
| | | for (auto& pair : m_mapFonts) { |
| | | if (pair.second) { |
| | | pair.second->DeleteObject(); |
| | | delete pair.second; |
| | | } |
| | | } |
| | | m_mapFonts.clear(); |
| | | } |
| | | |
| | | void CSystemLogManagerDlg::DoDataExchange(CDataExchange* pDX) |
| | |
| | | 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, 200); |
| | | 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.SetItemText(nRowIdx, nColIdx++, _T("时间")); |
| | |
| | | |
| | | void CSystemLogManagerDlg::SetDefaultFont() |
| | | { |
| | | CFont* pFont = new CFont(); |
| | | CFont* defaultFont = nullptr; |
| | | |
| | | // 如果字体管理容器中有默认大小(如 12)的字体,直接使用 |
| | | auto it = m_mapFonts.find(12); |
| | | if (it != m_mapFonts.end()) { |
| | | defaultFont = it->second; |
| | | } |
| | | else { |
| | | // 创建默认字体 |
| | | defaultFont = new CFont(); |
| | | LOGFONT logFont = { 0 }; |
| | | _tcscpy_s(logFont.lfFaceName, _T("Segoe UI")); |
| | | logFont.lfHeight = -12; |
| | | logFont.lfQuality = CLEARTYPE_QUALITY; |
| | | defaultFont->CreateFontIndirect(&logFont); |
| | | m_mapFonts[12] = defaultFont; // 存储到字体管理容器 |
| | | } |
| | | |
| | | // 设置字体属性 |
| | | _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) { |
| | | // 跳过特殊控件(如 MFCGridCtrl) |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0 |
| | | || _tcsicmp(szClassName, _T("ComboBoxs")) == 0) { |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | pWnd = pWnd->GetNextWindow(); |
| | | continue; |
| | | } |
| | | |
| | | pWnd->SetFont(pFont, TRUE); |
| | | pWnd->SetFont(defaultFont, TRUE); |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | } |
| | |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | |
| | | if (_tcsicmp(szClassName, _T("ComboBox")) == 0) { |
| | | CComboBox* pComboBox = (CComboBox*)pWnd; |
| | | pComboBox->SetItemHeight(-1, nHeight); // -1 表示所有项的高度 |
| | | } |
| | | |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | CGridCtrl* pGridCtrl = (CGridCtrl*)pWnd; |
| | |
| | | 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 表示所有项的高度 |
| | | } |
| | | |
| | | // 跳过特殊控件(如 MFCGridCtrl) |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | return; |
| | | } |
| | | |
| | | int fontSize = nHeight - 10; |
| | | CFont* pCurrentFont = pWnd->GetFont(); |
| | | LOGFONT logFont; |
| | | pCurrentFont->GetLogFont(&logFont); |
| | | // 根据控件高度动态调整字体大小 |
| | | int fontSize = nHeight / 2; |
| | | if (fontSize < 8) fontSize = 8; |
| | | |
| | | // 检查字体是否已经存在 |
| | | auto it = m_mapFonts.find(fontSize); |
| | | if (it == m_mapFonts.end()) { |
| | | // 动态创建新字体 |
| | | CFont* newFont = new CFont(); |
| | | LOGFONT logFont = { 0 }; |
| | | _tcscpy_s(logFont.lfFaceName, _T("Segoe UI")); |
| | | logFont.lfHeight = -fontSize; |
| | | logFont.lfQuality = CLEARTYPE_QUALITY; // 启用 ClearType 抗锯齿 |
| | | newFont->CreateFontIndirect(&logFont); |
| | | |
| | | CFont newFont; |
| | | newFont.CreateFontIndirect(&logFont); |
| | | // 存储到字体管理容器中 |
| | | m_mapFonts[fontSize] = newFont; |
| | | it = m_mapFonts.find(fontSize); |
| | | } |
| | | |
| | | pWnd->SetFont(&newFont); |
| | | pWnd->Invalidate(); |
| | | pWnd->SetFont(it->second); |
| | | pWnd->Invalidate(); // 刷新控件显示 |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | // TODO: 在此添加额外的初始化 |
| | | SetWindowText(_T("系统运行日志")); |
| | | |
| | | // 设置默认字体 |
| | | SetDefaultFont(); |
| | | |
| | | m_nCurrentPage = 1; // 从第一页开始 |
| | | m_nTotalPages = 1; // 默认总页数为 1 |
| | |
| | | |
| | | // 遍历对话框中的所有控件 |
| | | AdjustControls(rect.Width(), rect.Height()); |
| | | //SetDefaultFont(); |
| | | } |
| | | |
| | | |
| | |
| | | #include "afxdialogex.h" |
| | | #include "GridCtrl.h" |
| | | |
| | | |
| | | // CSystemLogManagerDlg 对话框 |
| | | |
| | | class CSystemLogManagerDlg : public CDialogEx |
| | |
| | | int m_nInitialHeight; // 初始高度 |
| | | int m_nCurrentPage; // 当前页码 |
| | | int m_nTotalPages; // 总页数 |
| | | std::map<int, CFont*> m_mapFonts; // 管理字体的容器,键为字体大小 |
| | | |
| | | private: |
| | | CComboBox m_comboType; |
| | |
| | | |
| | | CUserManagerDlg::~CUserManagerDlg() |
| | | { |
| | | for (auto& pair : m_mapFonts) { |
| | | if (pair.second) { |
| | | pair.second->DeleteObject(); |
| | | delete pair.second; |
| | | } |
| | | } |
| | | m_mapFonts.clear(); |
| | | } |
| | | |
| | | void CUserManagerDlg::DoDataExchange(CDataExchange* pDX) |
| | |
| | | return false; |
| | | } |
| | | |
| | | void CUserManagerDlg::SetDefaultFont() |
| | | { |
| | | CFont* defaultFont = nullptr; |
| | | |
| | | // 如果字体管理容器中有默认大小(如 12)的字体,直接使用 |
| | | auto it = m_mapFonts.find(12); |
| | | if (it != m_mapFonts.end()) { |
| | | defaultFont = it->second; |
| | | } |
| | | else { |
| | | // 创建默认字体 |
| | | defaultFont = new CFont(); |
| | | LOGFONT logFont = { 0 }; |
| | | _tcscpy_s(logFont.lfFaceName, _T("Segoe UI")); |
| | | logFont.lfHeight = -12; |
| | | logFont.lfQuality = CLEARTYPE_QUALITY; |
| | | defaultFont->CreateFontIndirect(&logFont); |
| | | m_mapFonts[12] = defaultFont; // 存储到字体管理容器 |
| | | } |
| | | |
| | | // 遍历所有控件,应用默认字体 |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | | while (pWnd) { |
| | | // 跳过特殊控件(如 MFCGridCtrl) |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | pWnd = pWnd->GetNextWindow(); |
| | | continue; |
| | | } |
| | | |
| | | pWnd->SetFont(defaultFont, TRUE); |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | } |
| | | |
| | | void CUserManagerDlg::AdjustControls(int nWidth, int nHeight) |
| | | { |
| | | CWnd* pWnd = GetWindow(GW_CHILD); |
| | |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | |
| | | if (_tcsicmp(szClassName, _T("ComboBox")) == 0) { |
| | | CComboBox* pComboBox = (CComboBox*)pWnd; |
| | | pComboBox->SetItemHeight(-1, nHeight); // -1 表示所有项的高度 |
| | | } |
| | | |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | CGridCtrl* pGridCtrl = (CGridCtrl*)pWnd; |
| | | pGridCtrl->SetDefCellHeight(newHeight / 20); |
| | | pGridCtrl->SetDefCellHeight(newHeight / 21); |
| | | pGridCtrl->ExpandColumnsToFit(TRUE); |
| | | pGridCtrl->Invalidate(); |
| | | } |
| | |
| | | TCHAR szClassName[256]; |
| | | GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName)); |
| | | |
| | | if (_tcsicmp(szClassName, _T("Static")) == 0) { |
| | | CStatic* pStatic = (CStatic*)pWnd; |
| | | pStatic->ModifyStyle(0, SS_CENTER | SS_CENTERIMAGE); |
| | | return; |
| | | } |
| | | |
| | | // 跳过特殊控件(如 MFCGridCtrl) |
| | | if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) { |
| | | return; |
| | | } |
| | | |
| | | int fontSize = nHeight - 10; |
| | | CFont* pCurrentFont = pWnd->GetFont(); |
| | | LOGFONT logFont; |
| | | pCurrentFont->GetLogFont(&logFont); |
| | | // 根据控件高度动态调整字体大小 |
| | | int fontSize = nHeight / 2; |
| | | if (fontSize < 8) fontSize = 8; |
| | | |
| | | // 检查字体是否已经存在 |
| | | auto it = m_mapFonts.find(fontSize); |
| | | if (it == m_mapFonts.end()) { |
| | | // 动态创建新字体 |
| | | CFont* newFont = new CFont(); |
| | | LOGFONT logFont = { 0 }; |
| | | _tcscpy_s(logFont.lfFaceName, _T("Segoe UI")); |
| | | logFont.lfHeight = -fontSize; |
| | | logFont.lfQuality = CLEARTYPE_QUALITY; // 启用 ClearType 抗锯齿 |
| | | newFont->CreateFontIndirect(&logFont); |
| | | |
| | | CFont newFont; |
| | | newFont.CreateFontIndirect(&logFont); |
| | | // 存储到字体管理容器中 |
| | | m_mapFonts[fontSize] = newFont; |
| | | it = m_mapFonts.find(fontSize); |
| | | } |
| | | |
| | | pWnd->SetFont(&newFont); |
| | | pWnd->Invalidate(); |
| | | pWnd->SetFont(it->second); |
| | | pWnd->Invalidate(); // 刷新控件显示 |
| | | } |
| | | |
| | | BEGIN_MESSAGE_MAP(CUserManagerDlg, CDialogEx) |
| | |
| | | SetWindowText(_T("用户管理")); |
| | | SystemParametersInfo(SPI_GETWORKAREA, 0, &screenRect, 0); |
| | | |
| | | // 设置默认字体 |
| | | SetDefaultFont(); |
| | | |
| | | GetClientRect(&clientRect); |
| | | m_nInitialWidth = clientRect.Width(); |
| | | m_nInitialHeight = clientRect.Height(); |
| | |
| | | void AddRow(CGridCtrl* pGridCtrl); |
| | | void DeleteSelectedRow(CGridCtrl* pGridCtrl); |
| | | bool IsUsernameDuplicate(const CString& username); |
| | | void SetDefaultFont(); |
| | | void AdjustControls(int nWidth, int nHeight); |
| | | void AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight); |
| | | |
| | | private: |
| | | int m_nInitialWidth; |
| | | int m_nInitialHeight; |
| | | std::map<int, CFont*> m_mapFonts; |
| | | std::map<CString, CString> m_mapRoleDescriptions; |
| | | |
| | | private: |