From d362ec98ec0db2039944da31729ad8efcd72834a Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期四, 02 一月 2025 14:19:36 +0800
Subject: [PATCH] 1.20250102合并;
---
SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp | 193 ++++-------------------------------------------
1 files changed, 19 insertions(+), 174 deletions(-)
diff --git a/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp b/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
index d8add62..7cf9480 100644
--- a/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
+++ b/SourceCode/Bond/BondEq/View/AxisSettingsDlg.cpp
@@ -21,13 +21,11 @@
// CAxisSettingsDlg 瀵硅瘽妗�
-IMPLEMENT_DYNAMIC(CAxisSettingsDlg, CDialogEx)
+IMPLEMENT_DYNAMIC(CAxisSettingsDlg, CBaseDlg)
CAxisSettingsDlg::CAxisSettingsDlg(CWnd* pParent /*=nullptr*/)
- : CDialogEx(IDD_DIALOG_AXIS_SETTINGS, pParent)
+ : CBaseDlg(IDD_DIALOG_AXIS_SETTINGS, pParent)
{
- m_nInitialWidth = 0;
- m_nInitialHeight = 0;
m_pPLC = nullptr;
m_bSEV = FALSE;
@@ -63,14 +61,6 @@
CAxisSettingsDlg::~CAxisSettingsDlg()
{
- for (auto& pair : m_mapFonts) {
- if (pair.second) {
- pair.second->DeleteObject();
- delete pair.second;
- }
- }
- m_mapFonts.clear();
-
for (int i = 0; i < BTN_MAX; i++) {
delete m_pBlBtns[i];
}
@@ -97,7 +87,7 @@
void CAxisSettingsDlg::DoDataExchange(CDataExchange* pDX)
{
- CDialogEx::DoDataExchange(pDX);
+ CBaseDlg::DoDataExchange(pDX);
DDX_Control(pDX, IDC_COMBO_AXIS_NAME, m_comboAxisNO);
DDX_Control(pDX, IDC_STATIC_AXIS_NUMBER, m_staticAxisNO);
DDX_Control(pDX, IDC_STATIC_AXIS_DESCRIP, m_staticAxisDescription);
@@ -130,81 +120,12 @@
return 0;
}
-CFont* CAxisSettingsDlg::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 CAxisSettingsDlg::SetDefaultFont()
-{
- CFont* defaultFont = GetOrCreateFont(12);
-
- // 閬嶅巻鎵�鏈夋帶浠讹紝搴旂敤榛樿瀛椾綋
- CWnd* pWnd = GetWindow(GW_CHILD);
- while (pWnd) {
- pWnd->SetFont(defaultFont, TRUE);
- pWnd = pWnd->GetNextWindow();
- }
-}
-
-void CAxisSettingsDlg::AdjustControls(float dScaleX, float dScaleY)
-{
- CWnd* pWnd = GetWindow(GW_CHILD);
- while (pWnd) {
- 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));
-
- TCHAR szClassName[256];
- GetClassName(pWnd->m_hWnd, szClassName, sizeof(szClassName));
-
- if (_tcsicmp(szClassName, _T("ComboBox")) == 0) {
- CComboBox* pComboBox = (CComboBox*)pWnd;
- pComboBox->SetItemHeight(-1, newRect.Height()); // -1 琛ㄧず鎵�鏈夐」鐨勯珮搴�
- }
-
- pWnd->MoveWindow(&newRect);
- AdjustControlFont(pWnd, newRect.Width(), newRect.Height());
- }
- pWnd = pWnd->GetNextWindow();
- }
-}
-
-void CAxisSettingsDlg::AdjustControlFont(CWnd* pWnd, int nWidth, int nHeight)
-{
- // 鏍规嵁鎺т欢楂樺害鍔ㄦ�佽皟鏁村瓧浣撳ぇ灏�
- int fontSize = nHeight / 2;
- if (fontSize < 8) fontSize = 8;
- if (fontSize > 24) fontSize = 24; // 鏈�澶у瓧浣撳ぇ灏�
-
- // 鑾峰彇鎴栧垱寤哄瓧浣�
- CFont* pFont = GetOrCreateFont(fontSize);
-
- pWnd->SetFont(pFont);
- pWnd->Invalidate(); // 鍒锋柊鎺т欢鏄剧ず
-}
-
void CAxisSettingsDlg::AdjustLabelFont(CBLLabel& label)
{
+ if (label.m_hWnd == nullptr) {
+ return;
+ }
+
// 鑾峰彇鎺т欢鐨勭煩褰㈠尯鍩�
CRect rect;
label.GetClientRect(&rect);
@@ -212,7 +133,7 @@
// 鍔ㄦ�佽绠楀瓧浣撳ぇ灏忥紝鍩轰簬鎺т欢鐨勯珮搴�
int fontSize = rect.Height() / 2; // 鎺т欢楂樺害鐨勪竴鍗婁綔涓哄瓧浣撳ぇ灏�
if (fontSize < 8) fontSize = 8; // 鏈�灏忓瓧浣撳ぇ灏�
- if (fontSize > 30) fontSize = 30; // 鏈�澶у瓧浣撳ぇ灏�
+ if (fontSize > 20) fontSize = 20; // 鏈�澶у瓧浣撳ぇ灏�
// 璁剧疆瀛椾綋澶у皬
label.SetFontSize(fontSize);
@@ -299,7 +220,6 @@
RecipeManager& recipeManager = RecipeManager::getInstance();
if (m_strRecipeName.IsEmpty() || !recipeManager.loadRecipe(std::string(CT2A(m_strRecipeName)))) {
AfxMessageBox(_T("鍔犺浇閰嶆柟澶辫触锛�"));
- recipeManager.saveRecipe(std::string(CT2A(m_strRecipeName)));
return;
}
@@ -829,7 +749,7 @@
}
-BEGIN_MESSAGE_MAP(CAxisSettingsDlg, CDialogEx)
+BEGIN_MESSAGE_MAP(CAxisSettingsDlg, CBaseDlg)
ON_BN_CLICKED(IDC_BUTTON_AXIS_LAST, &CAxisSettingsDlg::OnBnClickedButtonAxisLast)
ON_BN_CLICKED(IDC_BUTTON_AXIS_NEXT, &CAxisSettingsDlg::OnBnClickedButtonAxisNext)
ON_BN_CLICKED(IDC_BUTTON_AXIS_ANCHOR_POINT_GROUP1, &CAxisSettingsDlg::OnBnClickedButtonAxisAnchorPointGroup1)
@@ -851,8 +771,6 @@
ON_BN_CLICKED(IDC_BUTTON_AXIS_DETAIL_SETTINGS, &CAxisSettingsDlg::OnBnClickedButtonAxisDetailSettings)
ON_MESSAGE(ID_MSG_UPDATA_DATA_TO_UI, &CAxisSettingsDlg::OnUpdateDataToUI)
ON_WM_SIZE()
- ON_WM_CTLCOLOR()
- ON_WM_SIZING()
ON_WM_TIMER()
ON_WM_CLOSE()
END_MESSAGE_MAP()
@@ -863,7 +781,7 @@
BOOL CAxisSettingsDlg::OnInitDialog()
{
- CDialogEx::OnInitDialog();
+ CBaseDlg::OnInitDialog();
// TODO: 鍦ㄦ娣诲姞棰濆鐨勫垵濮嬪寲
CString strTitle;
@@ -893,6 +811,8 @@
pLabel->SetTextColor(RGB(255, 255, 255));
pLabel->SetAlignment(AlignCenter);
pLabel->SetDynamicFont(TRUE);
+
+ AdjustLabelFont(*pLabel);
}
// 鍒濆鍖栫紪杈戞
@@ -967,47 +887,6 @@
initializeAxisIDCombo();
refreshAxisDetails(1);
refreshPositionDetails(1, m_currentPage);
-
- CRect screenRect, dlgRect, clientRect;
- 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;
-
- // 璁剧疆榛樿瀛椾綋
- pWnd->SetFont(pDefaultFont);
- }
- pWnd = pWnd->GetNextWindow();
- }
-
- 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);
SetTimer(TIMER_READ_PLC_DATA, 500, nullptr);
@@ -1053,7 +932,7 @@
}
if (currentIndex == -1) {
- return CDialogEx::PreTranslateMessage(pMsg);
+ return CBaseDlg::PreTranslateMessage(pMsg);
}
CString descriptionCtrlName, positionCtrlName;
@@ -1067,7 +946,7 @@
CWnd* pPositionCtrl = GetDlgItem(positionCtrlId);
if (pDescriptionCtrl == nullptr || pPositionCtrl == nullptr) {
- return CDialogEx::PreTranslateMessage(pMsg);
+ return CBaseDlg::PreTranslateMessage(pMsg);
}
PositionRange& position = recipeManager.getPositionByIndex(getCurrentSelectedAxisID(), m_currentPage, AXIS_PAGE_SIZE, currentIndex);
@@ -1079,7 +958,7 @@
CString strText;
GetDlgItem(IDC_EDIT_AXIS_CURR_POS)->GetWindowText(strText);
if (strText.IsEmpty()) {
- return CDialogEx::PreTranslateMessage(pMsg);;
+ return CBaseDlg::PreTranslateMessage(pMsg);;
}
double enteredValue = _ttof(strText);
@@ -1135,24 +1014,14 @@
}
}
- return CDialogEx::PreTranslateMessage(pMsg);
+ return CBaseDlg::PreTranslateMessage(pMsg);
}
void CAxisSettingsDlg::OnSize(UINT nType, int cx, int cy)
{
- CDialogEx::OnSize(nType, cx, cy);
+ CBaseDlg::OnSize(nType, cx, cy);
// TODO: 鍦ㄦ澶勬坊鍔犳秷鎭鐞嗙▼搴忎唬鐮�
- 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(dScaleX, dScaleY);
-
// 鍔ㄦ�佽皟鏁村悇涓� CBLLabel 鐨勫瓧浣撳ぇ灏�
for (auto pLabel : m_pBlLabels) {
AdjustLabelFont(*pLabel);
@@ -1179,30 +1048,6 @@
pComboBox->MoveWindow(&rectComboBox);
pComboBox->SetItemHeight(-1, rectButton.Height() - 6);
}
-}
-
-void CAxisSettingsDlg::OnSizing(UINT fwSide, LPRECT pRect)
-{
- if (fwSide == WMSZ_BOTTOMRIGHT) {
- if (pRect->right - pRect->left < 200) {
- pRect->right = pRect->left + 200;
- }
- if (pRect->bottom - pRect->top < 150) {
- pRect->bottom = pRect->top + 150;
- }
- }
-
- CDialogEx::OnSizing(fwSide, pRect);
-}
-
-HBRUSH CAxisSettingsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
-{
- HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
-
- // TODO: 鍦ㄦ鏇存敼 DC 鐨勪换浣曠壒鎬�
-
- // TODO: 濡傛灉榛樿鐨勪笉鏄墍闇�鐢荤瑪锛屽垯杩斿洖鍙︿竴涓敾绗�
- return hbr;
}
void CAxisSettingsDlg::OnBnClickedButtonAxisLast()
@@ -1513,7 +1358,7 @@
readPLCDataToUI(nAxisId);
}
- CDialogEx::OnTimer(nIDEvent);
+ CBaseDlg::OnTimer(nIDEvent);
}
void CAxisSettingsDlg::OnClose()
@@ -1521,5 +1366,5 @@
// TODO: 鍦ㄦ娣诲姞娑堟伅澶勭悊绋嬪簭浠g爜鍜�/鎴栬皟鐢ㄩ粯璁ゅ��
KillTimer(TIMER_READ_PLC_DATA);
- CDialogEx::OnClose();
+ CBaseDlg::OnClose();
}
--
Gitblit v1.9.3