From 52c5442bfdf3dc6c0bac302d3661e90398e1079a Mon Sep 17 00:00:00 2001 From: yuanyuanxiang <962914132@qq.com> Date: Fri, 7 Feb 2025 19:23:15 +0800 Subject: [PATCH] fix: #45 File dialog controls misalign when the screen is zoomed --- client/test.cpp | 22 +++++++++--------- server/2015Remote/2015Remote.rc | Bin 50748 -> 50782 bytes server/2015Remote/FileManagerDlg.cpp | 32 ++++++++++++++++++++------- server/2015Remote/FileManagerDlg.h | 2 ++ server/2015Remote/resource.h | Bin 25896 -> 25964 bytes 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/client/test.cpp b/client/test.cpp index a4b40b7..c5aa1d9 100644 --- a/client/test.cpp +++ b/client/test.cpp @@ -167,7 +167,13 @@ BOOL Run(const char* argv1, int argv2) { stop = hDll ? StopRun(GetProcAddress(hDll, "StopRun")) : NULL; bStop = hDll ? IsStoped(GetProcAddress(hDll, "IsStoped")) : NULL; bExit = hDll ? IsExit(GetProcAddress(hDll, "IsExit")) : NULL; - if (run) + if (NULL == run) { + if (hDll) FreeLibrary(hDll); + Mprintf("加载动态链接库\"ServerDll.dll\"失败. 错误代码: %d\n", GetLastError()); + Sleep(3000); + return FALSE; + } + do { char ip[_MAX_PATH]; strcpy_s(ip, g_ConnectAddress.ServerIP()); @@ -194,16 +200,12 @@ BOOL Run(const char* argv1, int argv2) { if (bExit) { result = bExit(); } - if (!FreeLibrary(hDll)) { - Mprintf("释放动态链接库\"ServerDll.dll\"失败. 错误代码: %d\n", GetLastError()); - } - else { - Mprintf("释放动态链接库\"ServerDll.dll\"成功!\n"); - } + } while (result == 2); + if (!FreeLibrary(hDll)) { + Mprintf("释放动态链接库\"ServerDll.dll\"失败. 错误代码: %d\n", GetLastError()); } else { - Mprintf("加载动态链接库\"ServerDll.dll\"失败. 错误代码: %d\n", GetLastError()); - Sleep(3000); + Mprintf("释放动态链接库\"ServerDll.dll\"成功!\n"); } return result; -} \ No newline at end of file +} diff --git a/server/2015Remote/2015Remote.rc b/server/2015Remote/2015Remote.rc index 4af343d6528914c7d66432dd26f3c61a2cbff9a3..a11f8721cc1d3a242aee2a750d79277746bdb473 100644 GIT binary patch delta 394 zcmdnf!+fuYd4rZFzX^j0gE@l^g93vwkYzG?qm=gKV+tLU-)Oc>o}j8Rd4ZOgB1p~@ ztOi0F0#zD-`5@guy_3&sbx&RtqBMDyE+3=9Qg93vQgZbq3Qo573h3%WHq~$mHKorO1fIybX2h>z1 z&(IPR2dUHnV?zcL1_L151PFB|f7I!o9H7QAxlclA@;qI>$z_28ljmsjO+KWeG5MNy zjwDE>5lAHi$OLmBZ3xtD2Gp6VqdxhVx54BsIughhMwY+A9yIS-0A180!m0s hPS6(+g-C)(P-qx}-Dxqou~B^T25XkhEA+Qb0{~5+O&kCK diff --git a/server/2015Remote/FileManagerDlg.cpp b/server/2015Remote/FileManagerDlg.cpp index 90d449e..b5e095e 100644 --- a/server/2015Remote/FileManagerDlg.cpp +++ b/server/2015Remote/FileManagerDlg.cpp @@ -26,10 +26,19 @@ typedef struct { ///////////////////////////////////////////////////////////////////////////// // CFileManagerDlg dialog +float GetScreenScalingFactor() { + HDC hdc = GetDC(NULL); // 获取屏幕设备上下文 + int dpiX = GetDeviceCaps(hdc, LOGPIXELSX); // 获取水平 DPI + ReleaseDC(NULL, hdc); + + // 缩放比例 = DPI / 标准 DPI(96) + return dpiX / 96.0f; +} CFileManagerDlg::CFileManagerDlg(CWnd* pParent, CIOCPServer* pIOCPServer, ClientContext *pContext) : CDialog(CFileManagerDlg::IDD, pParent) { + m_fScalingFactor = GetScreenScalingFactor(); //{{AFX_DATA_INIT(CFileManagerDlg) //}}AFX_DATA_INIT m_bIsClosed = false; @@ -245,9 +254,7 @@ BOOL CFileManagerDlg::OnInitDialog() m_wndToolBar_Remote.AddDropDownButton(this, IDT_REMOTE_VIEW, IDR_REMOTE_VIEW); //显示工具栏 - m_wndToolBar_Local.MoveWindow(268, 0, rect.right - 268, 48); - m_wndToolBar_Remote.MoveWindow(268, rect.bottom / 2 - 10, rect.right - 268, 48); - + UpdateWindowsPos(); // 设置标题 CString str; @@ -305,15 +312,24 @@ void CFileManagerDlg::OnSize(UINT nType, int cx, int cy) m_wndStatusBar.GetItemRect(1, &rect); m_ProgressCtrl->MoveWindow(&rect); + UpdateWindowsPos(); +} + +void CFileManagerDlg::UpdateWindowsPos() { + RECT rect; + GetClientRect(&rect); + int cx = rect.right - rect.left; + int cy = rect.bottom - rect.top; GetDlgItem(IDC_LIST_LOCAL)->MoveWindow(0, 36, cx, (cy - 100) / 2); GetDlgItem(IDC_LIST_REMOTE)->MoveWindow(0, (cy / 2) + 28, cx, (cy - 100) / 2); - GetDlgItem(IDC_STATIC_REMOTE)->MoveWindow(20, cy / 2, 25, 20); - GetDlgItem(IDC_REMOTE_PATH)->MoveWindow(53, (cy / 2) - 4 , 210, 12); + GetDlgItem(IDC_STATIC_LOCAL)->MoveWindow(10, 10, 25 * m_fScalingFactor, 20); + GetDlgItem(IDC_STATIC_REMOTE)->MoveWindow(10, cy / 2, 25 * m_fScalingFactor, 20); + GetDlgItem(IDC_LOCAL_PATH)->MoveWindow(56, 5, 210, 12); + GetDlgItem(IDC_REMOTE_PATH)->MoveWindow(56, (cy / 2) - 4, 210, 12); - GetClientRect(&rect); //显示工具栏 - m_wndToolBar_Local.MoveWindow(268, 0, rect.right - 268, 48); - m_wndToolBar_Remote.MoveWindow(268, rect.bottom / 2 - 10, rect.right - 268, 48); + m_wndToolBar_Local.MoveWindow(268, 0, (rect.right - 268), 48); + m_wndToolBar_Remote.MoveWindow(268, (rect.bottom / 2 - 10), (rect.right - 268), 48); } void CFileManagerDlg::FixedLocalDriveList() diff --git a/server/2015Remote/FileManagerDlg.h b/server/2015Remote/FileManagerDlg.h index 1724030..a2f10ad 100644 --- a/server/2015Remote/FileManagerDlg.h +++ b/server/2015Remote/FileManagerDlg.h @@ -75,6 +75,7 @@ public: BOOL SendDownloadJob(); BOOL SendUploadJob(); BOOL SendDeleteJob(); + void UpdateWindowsPos(); strList m_Remote_Download_Job; strList m_Remote_Upload_Job; @@ -213,6 +214,7 @@ private: void EndLocalUploadFile(); bool DeleteDirectory(LPCTSTR lpszDirectory); void EnableControl(BOOL bEnable = TRUE); + float m_fScalingFactor; }; //{{AFX_INSERT_LOCATION}} diff --git a/server/2015Remote/resource.h b/server/2015Remote/resource.h index 612536ae50492d0329ea53f613870ca77ec57406..7697893cc140b841982d5b9fd8579ed6aff7775d 100644 GIT binary patch delta 54 zcmZ2+it)`U#tm-rlN&f#Cg%zB3HvbkGdMFiGWalXLZRX0cx~m)Uh;9SlY@fAChtqh F0sy5^4!{5a delta 30 mcmaEJigCp$#tm-rlOHg#Z0?hfbDjK%MQrlBWRb~YsbK)p$qc6e