From d84ddeea533a8e5f122cc4a2fed06e93c2aacf3d Mon Sep 17 00:00:00 2001
From: LAPTOP-T815PCOQ\25526 <mr.liuyang@126.com>
Date: 星期四, 21 十一月 2024 18:30:02 +0800
Subject: [PATCH] 1.显示对话框继续缩放 2.登录界面加载图片
---
SourceCode/Bond/BondEq/View/UserManagerDlg.cpp | 190 ++++++++++++++++++++++++++++++++++++----------
1 files changed, 147 insertions(+), 43 deletions(-)
diff --git a/SourceCode/Bond/BondEq/View/UserManagerDlg.cpp b/SourceCode/Bond/BondEq/View/UserManagerDlg.cpp
index 512eb5e..9daa3d1 100644
--- a/SourceCode/Bond/BondEq/View/UserManagerDlg.cpp
+++ b/SourceCode/Bond/BondEq/View/UserManagerDlg.cpp
@@ -20,11 +20,19 @@
CUserManagerDlg::CUserManagerDlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_DIALOG_USER_MANAGER, pParent)
{
-
+ m_nInitialWidth = 0;
+ m_nInitialHeight = 0;
}
CUserManagerDlg::~CUserManagerDlg()
{
+ for (auto& pair : m_mapFonts) {
+ if (pair.second) {
+ pair.second->DeleteObject();
+ delete pair.second;
+ }
+ }
+ m_mapFonts.clear();
}
void CUserManagerDlg::DoDataExchange(CDataExchange* pDX)
@@ -342,37 +350,78 @@
return false;
}
-void CUserManagerDlg::AdjustControls(int nWidth, int nHeight)
+CFont* CUserManagerDlg::GetOrCreateFont(int nFontSize)
+{
+ auto it = m_mapFonts.find(nFontSize);
+ if (it != m_mapFonts.end()) {
+ return it->second;
+ }
+
+ CFont* font = new CFont();
+ LOGFONT logFont = { 0 };
+ _tcscpy_s(logFont.lfFaceName, _T("Segoe UI"));
+ logFont.lfHeight = -nFontSize;
+ logFont.lfQuality = CLEARTYPE_QUALITY;
+ font->CreateFontIndirect(&logFont);
+ m_mapFonts[nFontSize] = font;
+
+ return font;
+}
+
+void CUserManagerDlg::SetDefaultFont()
+{
+ CFont* defaultFont = GetOrCreateFont(12);
+
+ // 閬嶅巻鎵�鏈夋帶浠讹紝搴旂敤榛樿瀛椾綋
+ 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(float dScaleX, float dScaleY)
{
CWnd* pWnd = GetWindow(GW_CHILD);
while (pWnd) {
- UINT nCtrlID = pWnd->GetDlgCtrlID();
+ int nCtrlID = pWnd->GetDlgCtrlID();
+ if (nCtrlID != -1 && m_mapCtrlLayouts.find(nCtrlID) != m_mapCtrlLayouts.end())
+ {
+ CRect originalRect = m_mapCtrlLayouts[nCtrlID];
+ CRect newRect(
+ static_cast<int>(originalRect.left * dScaleX),
+ static_cast<int>(originalRect.top * dScaleY),
+ static_cast<int>(originalRect.right * dScaleX),
+ static_cast<int>(originalRect.bottom * dScaleY));
- CRect ctrlRect;
- pWnd->GetWindowRect(&ctrlRect);
- ScreenToClient(&ctrlRect);
+ TCHAR szClassName[256];
+ GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName));
- // 璁$畻鎺т欢鐨勬柊浣嶇疆鍜屽ぇ灏忥紝鎸夋瘮渚嬭皟鏁�
- 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));
+ if (_tcsicmp(szClassName, _T("ComboBox")) == 0) {
+ CComboBox* pComboBox = (CComboBox*)pWnd;
+ pComboBox->SetItemHeight(-1, newRect.Height()); // -1 琛ㄧず鎵�鏈夐」鐨勯珮搴�
+ }
- TCHAR szClassName[256];
- GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName));
+ if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) {
+ CGridCtrl* pGridCtrl = (CGridCtrl*)pWnd;
+ pGridCtrl->SetDefCellHeight(newRect.Height() / 21);
+ pGridCtrl->ExpandColumnsToFit(TRUE);
+ pGridCtrl->ExpandLastColumn();
+ pGridCtrl->Invalidate();
+ pGridCtrl->UpdateWindow();
+ }
-
- if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) {
- CGridCtrl* pGridCtrl = (CGridCtrl*)pWnd;
- pGridCtrl->SetDefCellHeight(newHeight / 20);
- pGridCtrl->ExpandColumnsToFit(TRUE);
- pGridCtrl->Invalidate();
+ pWnd->MoveWindow(&newRect);
+ AdjustControlFont(pWnd, newRect.Width(), newRect.Height());
}
-
- pWnd->MoveWindow(newX, newY, newWidth, newHeight);
- AdjustControlFont(pWnd, newWidth, newHeight);
-
- // 鑾峰彇涓嬩竴涓帶浠�
pWnd = pWnd->GetNextWindow();
}
}
@@ -382,27 +431,33 @@
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);
- logFont.lfHeight = -fontSize;
+ // 鏍规嵁鎺т欢楂樺害鍔ㄦ�佽皟鏁村瓧浣撳ぇ灏�
+ int fontSize = nHeight / 2;
+ if (fontSize < 8) fontSize = 8;
- CFont newFont;
- newFont.CreateFontIndirect(&logFont);
+ // 妫�鏌ュ瓧浣撴槸鍚﹀凡缁忓瓨鍦�
+ 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);
- pWnd->SetFont(&newFont);
- pWnd->Invalidate();
+ // 瀛樺偍鍒板瓧浣撶鐞嗗鍣ㄤ腑
+ m_mapFonts[fontSize] = newFont;
+ it = m_mapFonts.find(fontSize);
+ }
+
+ pWnd->SetFont(it->second);
+ pWnd->Invalidate(); // 鍒锋柊鎺т欢鏄剧ず
}
BEGIN_MESSAGE_MAP(CUserManagerDlg, CDialogEx)
@@ -412,6 +467,7 @@
ON_BN_CLICKED(IDC_BUTTON_DEL, &CUserManagerDlg::OnBnClickedButtonDel)
ON_BN_CLICKED(IDOK, &CUserManagerDlg::OnBnClickedOk)
ON_BN_CLICKED(IDC_BUTTON_INSERT, &CUserManagerDlg::OnBnClickedButtonInsert)
+ ON_WM_GETMINMAXINFO()
END_MESSAGE_MAP()
@@ -431,12 +487,40 @@
m_nInitialWidth = clientRect.Width();
m_nInitialHeight = clientRect.Height();
+ // 鍒濆鍖栭粯璁ゅ瓧浣�
+ CFont* pDefaultFont = GetOrCreateFont(12);
+
+ // 閬嶅巻鎵�鏈夊瓙鎺т欢锛岃褰曞垵濮嬩綅缃苟璁剧疆榛樿瀛椾綋
+ CWnd* pWnd = GetWindow(GW_CHILD);
+ while (pWnd) {
+ int nCtrlID = pWnd->GetDlgCtrlID();
+ if (nCtrlID != -1) {
+ // 璁板綍鎺т欢鍒濆甯冨眬
+ CRect ctrlRect;
+ pWnd->GetWindowRect(&ctrlRect);
+ ScreenToClient(&ctrlRect);
+ m_mapCtrlLayouts[nCtrlID] = ctrlRect;
+
+ // 璺宠繃鐗规畩鎺т欢锛堝 MFCGridCtrl锛�
+ TCHAR szClassName[256];
+ GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName));
+ if (_tcsicmp(szClassName, _T("MFCGridCtrl")) == 0) {
+ pWnd = pWnd->GetNextWindow();
+ continue;
+ }
+
+ // 璁剧疆榛樿瀛椾綋
+ pWnd->SetFont(pDefaultFont);
+ }
+ pWnd = pWnd->GetNextWindow();
+ }
+
GetWindowRect(&dlgRect);
int dlgWidth = dlgRect.Width() * 3;
int dlgHeight = dlgRect.Height() * 3;
if (dlgWidth > screenRect.Width()) {
- dlgWidth = screenRect.Width();
+ dlgWidth = screenRect.Width();
}
if (dlgHeight > screenRect.Height()) {
dlgHeight = screenRect.Height();
@@ -453,17 +537,33 @@
// 寮傚父: OCX 灞炴�ч〉搴旇繑鍥� FALSE
}
+
void CUserManagerDlg::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
// TODO: 鍦ㄦ澶勬坊鍔犳秷鎭鐞嗙▼搴忎唬鐮�
- CRect rect;
- GetClientRect(&rect);
+ if (nType == SIZE_MINIMIZED || m_mapCtrlLayouts.empty()) {
+ return;
+ }
+
+ float dScaleX = static_cast<float>(cx) / m_nInitialWidth;
+ float dScaleY = static_cast<float>(cy) / m_nInitialHeight;
// 閬嶅巻瀵硅瘽妗嗕腑鐨勬墍鏈夋帶浠�
- AdjustControls(rect.Width(), rect.Height());
+ AdjustControls(dScaleX, dScaleY);
}
+
+
+void CUserManagerDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
+{
+ // TODO: 鍦ㄦ娣诲姞娑堟伅澶勭悊绋嬪簭浠g爜鍜�/鎴栬皟鐢ㄩ粯璁ゅ��
+ lpMMI->ptMinTrackSize.x = 400; // 鏈�灏忓搴�
+ lpMMI->ptMinTrackSize.y = 300; // 鏈�灏忛珮搴�
+
+ CDialogEx::OnGetMinMaxInfo(lpMMI);
+}
+
void CUserManagerDlg::OnGridComboSelChange(NMHDR* pNMHDR, LRESULT* pResult)
{
@@ -494,11 +594,13 @@
*pResult = 0;
}
+
void CUserManagerDlg::OnBnClickedButtonAdd()
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
AddRow(&m_gridUserManager);
}
+
void CUserManagerDlg::OnBnClickedButtonInsert()
{
@@ -563,12 +665,14 @@
m_gridUserManager.UpdateWindow();
}
+
void CUserManagerDlg::OnBnClickedButtonDel()
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
DeleteSelectedRow(&m_gridUserManager);
}
+
void CUserManagerDlg::OnBnClickedOk()
{
// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
--
Gitblit v1.9.3