comparison dep/animia/src/win/win32.cc @ 156:cdf79282d647

dep/animia: add VERY early x11 window stuff
author Paper <mrpapersonic@gmail.com>
date Wed, 15 Nov 2023 18:04:04 -0500
parents bd439dd6ffc5
children 0fc126d52de4
comparison
equal deleted inserted replaced
155:d2bbb5773616 156:cdf79282d647
1 #include "animia/win/win32.h" 1 #include "animia/win/win32.h"
2 #include "animia.h"
2 #include "animia/util/win32.h" 3 #include "animia/util/win32.h"
3 #include "animia/win.h" 4 #include "animia/win.h"
4 #include "animia.h"
5 5
6 #include <set> 6 #include <set>
7 #include <string> 7 #include <string>
8 8
9 #include <windows.h> 9 #include <windows.h>
46 // code is ERROR_ACCESS_DENIED. 46 // code is ERROR_ACCESS_DENIED.
47 // 47 //
48 // Note that if we requested PROCESS_QUERY_INFORMATION access right instead 48 // Note that if we requested PROCESS_QUERY_INFORMATION access right instead
49 // of PROCESS_QUERY_LIMITED_INFORMATION, this function would fail when used 49 // of PROCESS_QUERY_LIMITED_INFORMATION, this function would fail when used
50 // to open an elevated process. 50 // to open an elevated process.
51 Handle process_handle(::OpenProcess( 51 Handle process_handle(::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, process_id));
52 PROCESS_QUERY_LIMITED_INFORMATION, FALSE, process_id));
53 52
54 if (!process_handle) 53 if (!process_handle)
55 return std::wstring(); 54 return std::wstring();
56 55
57 std::wstring buffer(MAX_PATH, L'\0'); 56 std::wstring buffer(MAX_PATH, L'\0');
70 69
71 static bool VerifyWindowStyle(HWND hwnd) { 70 static bool VerifyWindowStyle(HWND hwnd) {
72 const auto window_style = ::GetWindowLong(hwnd, GWL_STYLE); 71 const auto window_style = ::GetWindowLong(hwnd, GWL_STYLE);
73 const auto window_ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE); 72 const auto window_ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE);
74 73
75 auto has_style = [&window_style](DWORD style) { 74 auto has_style = [&window_style](DWORD style) { return (window_style & style) != 0; };
76 return (window_style & style) != 0; 75 auto has_ex_style = [&window_ex_style](DWORD ex_style) { return (window_ex_style & ex_style) != 0; };
77 };
78 auto has_ex_style = [&window_ex_style](DWORD ex_style) {
79 return (window_ex_style & ex_style) != 0;
80 };
81 76
82 // Toolbars, tooltips and similar topmost windows 77 // Toolbars, tooltips and similar topmost windows
83 if (has_style(WS_POPUP) && has_ex_style(WS_EX_TOOLWINDOW)) 78 if (has_style(WS_POPUP) && has_ex_style(WS_EX_TOOLWINDOW))
84 return false; 79 return false;
85 if (has_ex_style(WS_EX_TOPMOST) && has_ex_style(WS_EX_TOOLWINDOW)) 80 if (has_ex_style(WS_EX_TOPMOST) && has_ex_style(WS_EX_TOOLWINDOW))
88 return true; 83 return true;
89 } 84 }
90 85
91 static bool VerifyClassName(const std::wstring& name) { 86 static bool VerifyClassName(const std::wstring& name) {
92 static const std::set<std::wstring> invalid_names = { 87 static const std::set<std::wstring> invalid_names = {
93 // System classes 88 // System classes
94 L"#32770", // Dialog box 89 L"#32770", // Dialog box
95 L"CabinetWClass", // Windows Explorer 90 L"CabinetWClass", // Windows Explorer
96 L"ComboLBox", 91 L"ComboLBox",
97 L"DDEMLEvent", 92 L"DDEMLEvent",
98 L"DDEMLMom", 93 L"DDEMLMom",
99 L"DirectUIHWND", 94 L"DirectUIHWND",
100 L"GDI+ Hook Window Class", 95 L"GDI+ Hook Window Class",
101 L"IME", 96 L"IME",
102 L"Internet Explorer_Hidden", 97 L"Internet Explorer_Hidden",
103 L"MSCTFIME UI", 98 L"MSCTFIME UI",
104 L"tooltips_class32", 99 L"tooltips_class32",
105 }; 100 };
106 101
107 return !name.empty() && !invalid_names.count(name); 102 return !name.empty() && !invalid_names.count(name);
108 } 103 }
109 104
111 return !path.empty() && !IsSystemDirectory(path); 106 return !path.empty() && !IsSystemDirectory(path);
112 } 107 }
113 108
114 static bool VerifyProcessFileName(const std::wstring& name) { 109 static bool VerifyProcessFileName(const std::wstring& name) {
115 static const std::set<std::wstring> invalid_names = { 110 static const std::set<std::wstring> invalid_names = {
116 // System files 111 // System files
117 L"explorer", // Windows Explorer 112 L"explorer", // Windows Explorer
118 L"taskeng", // Task Scheduler Engine 113 L"taskeng", // Task Scheduler Engine
119 L"taskhost", // Host Process for Windows Tasks 114 L"taskhost", // Host Process for Windows Tasks
120 L"taskhostex", // Host Process for Windows Tasks 115 L"taskhostex", // Host Process for Windows Tasks
121 L"Taskmgr", // Task Manager 116 L"Taskmgr", // Task Manager
122 }; 117 };
123 118
124 return !name.empty() && !invalid_names.count(name); 119 return !name.empty() && !invalid_names.count(name);
125 } 120 }
126 121
174 // Note that EnumWindows enumerates only top-level windows of desktop apps 169 // Note that EnumWindows enumerates only top-level windows of desktop apps
175 // (as opposed to UWP apps) on Windows 8 and above. 170 // (as opposed to UWP apps) on Windows 8 and above.
176 return ::EnumWindows(EnumWindowsProc, param) != FALSE; 171 return ::EnumWindows(EnumWindowsProc, param) != FALSE;
177 } 172 }
178 173
179 } // namespace animia::win::detail 174 } // namespace animia::internal::win32