Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLTK 1.4] Skip the call to MonitorFromRect when it is not needed. #174

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/Fl_win32.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -565,13 +565,22 @@ void Fl_WinAPI_Screen_Driver::open_display_platform() {

void Fl_WinAPI_Screen_Driver::desktop_scale_factor() {
typedef HRESULT(WINAPI * GetDpiForMonitor_type)(HMONITOR, int, UINT *, UINT *);
typedef HMONITOR(WINAPI * MonitorFromRect_type)(LPCRECT, DWORD);
GetDpiForMonitor_type fl_GetDpiForMonitor = NULL;
if (is_dpi_aware)
MonitorFromRect_type fl_MonitorFromRect = NULL;
if (is_dpi_aware) {
fl_GetDpiForMonitor = (GetDpiForMonitor_type)GetProcAddress(LoadLibrary("Shcore.DLL"), "GetDpiForMonitor");
if (fl_GetDpiForMonitor != NULL)
fl_MonitorFromRect = (MonitorFromRect_type)GetProcAddress(LoadLibrary("User32.DLL"), "MonitorFromRect");
}
for (int ns = 0; ns < screen_count(); ns++) {
HMONITOR hm = MonitorFromRect(&screens[ns], MONITOR_DEFAULTTONEAREST);
HRESULT r = !S_OK;
UINT dpiX, dpiY;
HRESULT r = fl_GetDpiForMonitor ? fl_GetDpiForMonitor(hm, 0, &dpiX, &dpiY) : !S_OK;
// The result of MonitorFromRect is only needed when is_dpi_aware is true and when GetProcAddress successed getting the address for GetDpiForMonitor.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/successed/succeeded/ ?

if ((fl_GetDpiForMonitor != NULL) && (fl_MonitorFromRect != NULL)) {
HMONITOR hm = fl_MonitorFromRect(&screens[ns], MONITOR_DEFAULTTONEAREST);
r = fl_GetDpiForMonitor(hm, 0, &dpiX, &dpiY);
}
if (r != S_OK) { dpiX = dpiY = 96; }
dpi[ns][0] = dpiX;
dpi[ns][1] = dpiY;
Expand Down