Skip to content

Commit 0a1525a

Browse files
committedMay 19, 2024
Get screen dimensions faster
by using GetSystemMetrics function querying Win32_VideoController from the WMI can take a lot of time
1 parent 70b65e4 commit 0a1525a

File tree

1 file changed

+6
-27
lines changed

1 file changed

+6
-27
lines changed
 

‎machine_info_win.cpp

+6-27
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
#include <string>
44
#include <sstream>
55
#include <vector>
6-
#include <regex>
76

87
#include <unicode/unistr.h>
98

109
#define _WIN32_DCOM
10+
#define _WIN32_WINNT 0x0600
1111
#include <iostream>
1212
#include <windows.h>
1313
#include <wbemidl.h>
1414
#include <comdef.h>
15+
#include <winuser.h>
1516

1617
std::string exc_value("invalid");
1718

@@ -262,18 +263,6 @@ std::string wmi_value(std::wstring const& table,
262263
return exc_value;
263264
}
264265

265-
std::string match_regex(std::string const& input,
266-
char const* r_string)
267-
{
268-
std::regex r(r_string);
269-
std::smatch sm;
270-
if (std::regex_search(input, sm, r))
271-
{
272-
return sm[1];
273-
}
274-
return exc_value;
275-
}
276-
277266
std::string machine_info_uuid()
278267
{
279268
return wmi_value(L"Win32_ComputerSystemProduct",
@@ -294,24 +283,14 @@ std::string machine_info_manufacturer()
294283

295284
std::string machine_info_display_width()
296285
{
297-
std::string v_mode_desc = wmi_value(L"Win32_VideoController",
298-
L"VideoModeDescription");
299-
if (v_mode_desc == exc_value)
300-
{
301-
return exc_value;
302-
}
303-
return match_regex(v_mode_desc, "(\\d+) x \\d+ x \\d+ colors");
286+
SetProcessDPIAware();
287+
return std::to_string(GetSystemMetrics(SM_CXSCREEN));
304288
}
305289

306290
std::string machine_info_display_height()
307291
{
308-
std::string v_mode_desc = wmi_value(L"Win32_VideoController",
309-
L"VideoModeDescription");
310-
if (v_mode_desc == exc_value)
311-
{
312-
return exc_value;
313-
}
314-
return match_regex(v_mode_desc, "\\d+ x (\\d+) x \\d+ colors");
292+
SetProcessDPIAware();
293+
return std::to_string(GetSystemMetrics(SM_CYSCREEN));
315294
}
316295

317296
std::string machine_info_memory_serial0()

0 commit comments

Comments
 (0)
Please sign in to comment.