Skip to content

Commit

Permalink
修正引入GetDpiForMonitor函数后(zhongyang219#1097)在Win7下提示找不到dll的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongyang219 committed Jul 30, 2022
1 parent b85326c commit 7d52e8a
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 5 deletions.
28 changes: 28 additions & 0 deletions TrafficMonitor/DllFunctions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "stdafx.h"
#include "DllFunctions.h"

CDllFunctions::CDllFunctions()
{
//shellscalingapi
m_shcore_module = ::LoadLibrary(_T("Shcore.dll"));
if (m_shcore_module != NULL)
{
m_getDpiForMonitor = (_GetDpiForMonitor)::GetProcAddress(m_shcore_module, "GetDpiForMonitor");
}
}

CDllFunctions::~CDllFunctions()
{
if (m_shcore_module != NULL)
{
FreeLibrary(m_shcore_module);
m_shcore_module = NULL;
}
}

HRESULT CDllFunctions::GetDpiForMonitor(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, UINT* dpiX, UINT* dpiY)
{
if (m_getDpiForMonitor != nullptr)
return m_getDpiForMonitor(hmonitor, dpiType, dpiX, dpiY);
return 0;
}
21 changes: 21 additions & 0 deletions TrafficMonitor/DllFunctions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once
#include <shellscalingapi.h> // °üº¬::GetDpiForMonitor

typedef HRESULT(WINAPI* _GetDpiForMonitor)(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, UINT* dpiX, UINT* dpiY);

class CDllFunctions
{
public:
CDllFunctions();
~CDllFunctions();

public:
HRESULT GetDpiForMonitor(HMONITOR hmonitor, MONITOR_DPI_TYPE dpiType, UINT* dpiX, UINT* dpiY);

private:
_GetDpiForMonitor m_getDpiForMonitor{};

private:
HMODULE m_shcore_module{};
};

5 changes: 1 addition & 4 deletions TrafficMonitor/TaskBarDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
//

#include "stdafx.h"
#include <shellscalingapi.h> // 包含::GetDpiForMonitor
#include "TrafficMonitor.h"
#include "TaskBarDlg.h"
#include "afxdialogex.h"
#include "TrafficMonitorDlg.h"
#include "WindowsSettingHelper.h"

#pragma comment(lib, "Shcore.lib") // 函数::GetDpiForMonitor依赖此lib

// CTaskBarDlg 对话框

IMPLEMENT_DYNAMIC(CTaskBarDlg, CDialogEx)
Expand Down Expand Up @@ -612,7 +609,7 @@ void CTaskBarDlg::DPI(CRect& rect) const
void CTaskBarDlg::DPIFromRect(const RECT& rect, UINT* out_dpi_x, UINT* out_dpi_y)
{
HMONITOR h_current_monitor = ::MonitorFromRect(&rect, MONITOR_DEFAULTTONEAREST);
::GetDpiForMonitor(h_current_monitor, MDT_EFFECTIVE_DPI, out_dpi_x, out_dpi_y);
theApp.m_dll_functions.GetDpiForMonitor(h_current_monitor, MDT_EFFECTIVE_DPI, out_dpi_x, out_dpi_y);
}

CTaskBarDlg::ClassCheckWindowMonitorDPIAndHandle CTaskBarDlg::CheckWindowMonitorDPIAndHandle{};
Expand Down
3 changes: 2 additions & 1 deletion TrafficMonitor/TrafficMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <map>
#include "OpenHardwareMonitor/OpenHardwareMonitorApi.h"
#include "PluginManager.h"
#include "DllFunctions.h"

// CTrafficMonitorApp:
// 有关此类的实现,请参阅 TrafficMonitor.cpp
Expand Down Expand Up @@ -82,8 +83,8 @@ class CTrafficMonitorApp : public CWinApp
HICON m_notify_icons[MAX_NOTIFY_ICON];

CTaskbarDefaultStyle m_taskbar_default_style;

CPluginManager m_plugins;
CDllFunctions m_dll_functions;

CMenu m_main_menu;
CMenu m_taskbar_menu;
Expand Down
2 changes: 2 additions & 0 deletions TrafficMonitor/TrafficMonitor.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@
<ClInclude Include="CTabCtrlEx.h" />
<ClInclude Include="CVariant.h" />
<ClInclude Include="DisplayTextSettingDlg.h" />
<ClInclude Include="DllFunctions.h" />
<ClInclude Include="DrawCommonEx.h" />
<ClInclude Include="FilePathHelper.h" />
<ClInclude Include="HighResolutionTimer.h" />
Expand Down Expand Up @@ -513,6 +514,7 @@
<ClCompile Include="CTabCtrlEx.cpp" />
<ClCompile Include="CVariant.cpp" />
<ClCompile Include="DisplayTextSettingDlg.cpp" />
<ClCompile Include="DllFunctions.cpp" />
<ClCompile Include="DrawCommonEx.cpp" />
<ClCompile Include="FilePathHelper.cpp" />
<ClCompile Include="HistoryTrafficCalendarDlg.cpp" />
Expand Down
6 changes: 6 additions & 0 deletions TrafficMonitor/TrafficMonitor.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,9 @@
<ClInclude Include="WindowsSettingHelper.h">
<Filter>源文件和头文件\公共的类\WindowsSettingHelper</Filter>
</ClInclude>
<ClInclude Include="DllFunctions.h">
<Filter>源文件和头文件\头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="StaticEx.cpp">
Expand Down Expand Up @@ -607,6 +610,9 @@
<ClCompile Include="WindowsSettingHelper.cpp">
<Filter>源文件和头文件\公共的类\WindowsSettingHelper</Filter>
</ClCompile>
<ClCompile Include="DllFunctions.cpp">
<Filter>源文件和头文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="TrafficMonitor.rc">
Expand Down

0 comments on commit 7d52e8a

Please sign in to comment.