| | |
| | | #include "InputDialog.h" |
| | | #include "NewCellTypes/GridCellCombo.h" |
| | | #include "NewCellTypes/GridCellNumeric.h" |
| | | |
| | | #include <set> |
| | | |
| | | const COLORREF CURR_USER_BK_COLOR = RGB(0, 255, 0); |
| | | |
| | | // CUserManagerDlg 对话框 |
| | | |
| | | IMPLEMENT_DYNAMIC(CUserManagerDlg, CDialogEx) |
| | | IMPLEMENT_DYNAMIC(CUserManagerDlg, CBaseDlg) |
| | | |
| | | CUserManagerDlg::CUserManagerDlg(CWnd* pParent /*=nullptr*/) |
| | | : CDialogEx(IDD_DIALOG_USER_MANAGER, pParent) |
| | | : CBaseDlg(IDD_DIALOG_USER_MANAGER, pParent) |
| | | { |
| | | |
| | | } |
| | | |
| | | CUserManagerDlg::~CUserManagerDlg() |
| | |
| | | void CUserManagerDlg::DoDataExchange(CDataExchange* pDX) |
| | | { |
| | | DDX_Control(pDX, IDC_CUSTOM_USER, m_gridUserManager); |
| | | CDialogEx::DoDataExchange(pDX); |
| | | CBaseDlg::DoDataExchange(pDX); |
| | | } |
| | | |
| | | void CUserManagerDlg::InitUserManager() |
| | |
| | | int nCurrNameRow = -1; |
| | | std::vector<std::vector<std::string>> usersData = userManager.getUsers(); |
| | | if (!usersData.empty()) { |
| | | m_gridUserManager.SetRowCount(usersData.size() + 1); |
| | | m_gridUserManager.SetRowCount((int)usersData.size() + 1); |
| | | |
| | | for (int i = 0; i < usersData.size(); i++) { |
| | | int nRowIdx = i + 1; |
| | |
| | | return false; |
| | | } |
| | | |
| | | void CUserManagerDlg::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 / 20); |
| | | pGridCtrl->ExpandColumnsToFit(TRUE); |
| | | pGridCtrl->Invalidate(); |
| | | } |
| | | |
| | | pWnd->MoveWindow(newX, newY, newWidth, newHeight); |
| | | AdjustControlFont(pWnd, newWidth, newHeight); |
| | | |
| | | // 获取下一个控件 |
| | | pWnd = pWnd->GetNextWindow(); |
| | | } |
| | | } |
| | | |
| | | void CUserManagerDlg::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("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(); |
| | | } |
| | | |
| | | BEGIN_MESSAGE_MAP(CUserManagerDlg, CDialogEx) |
| | | ON_WM_SIZE() |
| | | BEGIN_MESSAGE_MAP(CUserManagerDlg, CBaseDlg) |
| | | ON_NOTIFY(GVN_COMBOSELCHANGE, IDC_CUSTOM_USER, &CUserManagerDlg::OnGridComboSelChange) |
| | | ON_BN_CLICKED(IDC_BUTTON_ADD, &CUserManagerDlg::OnBnClickedButtonAdd) |
| | | ON_BN_CLICKED(IDC_BUTTON_DEL, &CUserManagerDlg::OnBnClickedButtonDel) |
| | |
| | | |
| | | BOOL CUserManagerDlg::OnInitDialog() |
| | | { |
| | | CDialogEx::OnInitDialog(); |
| | | CBaseDlg::OnInitDialog(); |
| | | |
| | | // TODO: 在此添加额外的初始化 |
| | | CRect screenRect, dlgRect, clientRect; |
| | | SetWindowText(_T("用户管理")); |
| | | SystemParametersInfo(SPI_GETWORKAREA, 0, &screenRect, 0); |
| | | |
| | | GetClientRect(&clientRect); |
| | | m_nInitialWidth = clientRect.Width(); |
| | | m_nInitialHeight = clientRect.Height(); |
| | | |
| | | GetWindowRect(&dlgRect); |
| | | int dlgWidth = dlgRect.Width() * 3; |
| | | int dlgHeight = dlgRect.Height() * 3; |
| | | |
| | | 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); |
| | | |
| | | // 初始化用户管理表格 |
| | | InitUserManager(); |
| | | |
| | | return TRUE; // return TRUE unless you set the focus to a control |
| | | // 异常: OCX 属性页应返回 FALSE |
| | | } |
| | | |
| | | void CUserManagerDlg::OnSize(UINT nType, int cx, int cy) |
| | | { |
| | | CDialogEx::OnSize(nType, cx, cy); |
| | | |
| | | // TODO: 在此处添加消息处理程序代码 |
| | | CRect rect; |
| | | GetClientRect(&rect); |
| | | |
| | | // 遍历对话框中的所有控件 |
| | | AdjustControls(rect.Width(), rect.Height()); |
| | | } |
| | | |
| | | void CUserManagerDlg::OnGridComboSelChange(NMHDR* pNMHDR, LRESULT* pResult) |
| | |
| | | *pResult = 0; |
| | | } |
| | | |
| | | |
| | | void CUserManagerDlg::OnBnClickedButtonAdd() |
| | | { |
| | | // TODO: 在此添加控件通知处理程序代码 |
| | | AddRow(&m_gridUserManager); |
| | | } |
| | | |
| | | |
| | | void CUserManagerDlg::OnBnClickedButtonInsert() |
| | | { |
| | |
| | | m_gridUserManager.UpdateWindow(); |
| | | } |
| | | |
| | | |
| | | void CUserManagerDlg::OnBnClickedButtonDel() |
| | | { |
| | | // TODO: 在此添加控件通知处理程序代码 |
| | | DeleteSelectedRow(&m_gridUserManager); |
| | | } |
| | | |
| | | |
| | | void CUserManagerDlg::OnBnClickedOk() |
| | | { |
| | |
| | | } |
| | | |
| | | userManager.setUsers(vecData); |
| | | CDialogEx::OnOK(); |
| | | CBaseDlg::OnOK(); |
| | | } |