Skip to content

Commit 730ff64

Browse files
committed
CBaseDailog类保存自己的DPI
1 parent c6e8774 commit 730ff64

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

TrafficMonitor/BaseDialog.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CBaseDialog::CBaseDialog(UINT nIDTemplate, CWnd* pParent /*=NULL*/)
1717
: CDialog(nIDTemplate, pParent)
1818
{
1919
m_nDialogID = nIDTemplate;
20+
m_dpi = theApp.GetDpi();
2021
}
2122

2223
CBaseDialog::~CBaseDialog()
@@ -133,6 +134,11 @@ void CBaseDialog::ReLoadLayoutResource()
133134
}
134135
}
135136

137+
int CBaseDialog::DPI(int pixel) const
138+
{
139+
return m_dpi * pixel / 96;
140+
}
141+
136142
CRect CBaseDialog::GetTextExtent(const CString& text)
137143
{
138144
ASSERT(m_pDC != nullptr); // m_pDC由OnInitDialog负责申请释放
@@ -293,9 +299,9 @@ BOOL CBaseDialog::OnInitDialog()
293299
font_info.size = 9;
294300
UINT dpi_x{}, dpi_y{};
295301
if (theApp.DPIFromRect(rect, &dpi_x, &dpi_y))
296-
font_info.Create(m_dlg_font, dpi_x);
297-
else
298-
font_info.Create(m_dlg_font, theApp.GetDpi());
302+
m_dpi = dpi_x;
303+
304+
font_info.Create(m_dlg_font, m_dpi);
299305

300306
//获取初始时窗口的大小
301307
if (m_min_size.cx <= 0 || m_min_size.cy <= 0)

TrafficMonitor/BaseDialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ class CBaseDialog : public CDialog
4242
static std::map<CString, HWND> m_unique_hwnd; //针对每一个基类的唯一的窗口句柄
4343
bool m_remember_dlg_size{ true }; //是否记住窗口大小(当此标志为true且GetDialogName返回字符串不为空时会记住窗口大小)
4444
CFont m_dlg_font;
45+
int m_dpi; //窗口自己的DPI
4546

4647
protected:
48+
int DPI(int pixel) const;
49+
4750
// 仅在InitializeControls期间可用,测量控件文本长度
4851
CRect GetTextExtent(const CString& text);
4952

TrafficMonitor/SetItemOrderDlg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ BOOL CSetItemOrderDlg::OnInitDialog()
7777
// TODO: 在此添加额外的初始化
7878
SetIcon(theApp.GetMenuIcon(IDI_ITEM), FALSE); // 设置小图标
7979

80-
m_list_ctrl.SetItemHeight(0, theApp.DPI(20));
80+
m_list_ctrl.SetItemHeight(0, DPI(20));
8181
EnableCtrl(-1);
8282
ShowItem();
8383

TrafficMonitor/SkinDlg.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ CRect CSkinDlg::CalculateViewRect()
9090
m_preview_static.GetWindowRect(rect); //获取“预览” group box 的位置
9191
ScreenToClient(&rect);
9292
CRect scroll_view_rect{ rect };
93-
scroll_view_rect.DeflateRect(theApp.DPI(12), theApp.DPI(40));
94-
scroll_view_rect.top = rect.top + theApp.DPI(28);
93+
scroll_view_rect.DeflateRect(DPI(12), DPI(40));
94+
scroll_view_rect.top = rect.top + DPI(28);
9595
return scroll_view_rect;
9696
}
9797

@@ -114,7 +114,7 @@ BOOL CSkinDlg::OnInitDialog()
114114
// TODO: 在此添加额外的初始化
115115
SetIcon(theApp.GetMenuIcon(IDI_SKIN), FALSE); // 设置小图标
116116
//初始化选择框
117-
m_skin_list_box.SetItemHeight(0, theApp.DPI(18));
117+
m_skin_list_box.SetItemHeight(0, DPI(18));
118118
for (const auto& skin_path : m_skins)
119119
{
120120
wstring skin_name;

0 commit comments

Comments
 (0)