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 |  150 +++++++++++++++++++++++++++++++++-----------------
 1 files changed, 99 insertions(+), 51 deletions(-)

diff --git a/SourceCode/Bond/BondEq/View/UserManagerDlg.cpp b/SourceCode/Bond/BondEq/View/UserManagerDlg.cpp
index 50136c1..9daa3d1 100644
--- a/SourceCode/Bond/BondEq/View/UserManagerDlg.cpp
+++ b/SourceCode/Bond/BondEq/View/UserManagerDlg.cpp
@@ -20,7 +20,8 @@
 CUserManagerDlg::CUserManagerDlg(CWnd* pParent /*=nullptr*/)
 	: CDialogEx(IDD_DIALOG_USER_MANAGER, pParent)
 {
-
+	m_nInitialWidth = 0;
+	m_nInitialHeight = 0;
 }
 
 CUserManagerDlg::~CUserManagerDlg()
@@ -349,25 +350,27 @@
 	return false;
 }
 
+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 = 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; // 瀛樺偍鍒板瓧浣撶鐞嗗鍣�
-	}
+	CFont* defaultFont = GetOrCreateFont(12);
 
 	// 閬嶅巻鎵�鏈夋帶浠讹紝搴旂敤榛樿瀛椾綋
 	CWnd* pWnd = GetWindow(GW_CHILD);
@@ -385,41 +388,40 @@
 	}
 }
 
-void CUserManagerDlg::AdjustControls(int nWidth, int nHeight)
+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("ComboBox")) == 0) {
-			CComboBox* pComboBox = (CComboBox*)pWnd;
-			pComboBox->SetItemHeight(-1, nHeight);  // -1 琛ㄧず鎵�鏈夐」鐨勯珮搴�
+			pWnd->MoveWindow(&newRect);
+			AdjustControlFont(pWnd, newRect.Width(), newRect.Height());
 		}
-
-		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();
 	}
 }
@@ -465,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()
 
 
@@ -480,12 +483,37 @@
 	SetWindowText(_T("鐢ㄦ埛绠$悊"));
 	SystemParametersInfo(SPI_GETWORKAREA, 0, &screenRect, 0);
 
-	// 璁剧疆榛樿瀛椾綋
-	SetDefaultFont();
-
 	GetClientRect(&clientRect);
 	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;
@@ -509,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)
 {
@@ -550,11 +594,13 @@
 	*pResult = 0;
 }
 
+
 void CUserManagerDlg::OnBnClickedButtonAdd()
 {
 	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
 	AddRow(&m_gridUserManager);
 }
+
 
 void CUserManagerDlg::OnBnClickedButtonInsert()
 {
@@ -619,12 +665,14 @@
 	m_gridUserManager.UpdateWindow();
 }
 
+
 void CUserManagerDlg::OnBnClickedButtonDel()
 {
 	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
 	DeleteSelectedRow(&m_gridUserManager);
 }
 
+
 void CUserManagerDlg::OnBnClickedOk()
 {
 	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜

--
Gitblit v1.9.3