Skip to content
This repository was archived by the owner on Jan 4, 2025. It is now read-only.

Commit 7877df0

Browse files
committed
update
1 parent aad6c91 commit 7877df0

24 files changed

+211
-151
lines changed

Common/Api.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ bool Api::IsCurrentProcessInBlockList()
6666
// TranslucentFlyouts won't be loaded into one of these process
6767
// These processes are quite annoying because TranslucentFlyouts will not be automatically unloaded by them
6868
// Some of them even have no chance to show flyouts and other UI elements
69-
const std::array blockList
69+
static const std::array blockList
7070
{
7171
L"sihost.exe"sv,
7272
L"WSHost.exe"sv,
@@ -128,8 +128,8 @@ bool Api::InteractiveIO::OutputToConsole(
128128
return false;
129129
}
130130

131-
static WCHAR str[32768 + 1]{};
132-
LoadStringW(wil::GetModuleInstanceHandle(), strResourceId, str, 32768);
131+
LPCWSTR buffer{ nullptr };
132+
auto length{ LoadStringW(wil::GetModuleInstanceHandle(), strResourceId, reinterpret_cast<LPWSTR>(&buffer), 0)};
133133

134134
switch (strType)
135135
{
@@ -152,7 +152,7 @@ bool Api::InteractiveIO::OutputToConsole(
152152
break;
153153
}
154154

155-
auto outputString{std::format(L"{}{}{}", prefixStr, str, additionalStr)};
155+
auto outputString{std::format(L"{}{}{}", prefixStr, std::wstring_view{ buffer, static_cast<size_t>(length) }, additionalStr)};
156156
std::wcout << outputString;
157157
#ifdef _DEBUG
158158
OutputDebugStringW(outputString.c_str());
@@ -246,15 +246,20 @@ bool Api::IsPartDisabledExternally(std::wstring_view part)
246246
(
247247
GetSystemPowerStatus(&powerStatus) &&
248248
powerStatus.SystemStatusFlag
249-
)
250-
) ||
251-
RegHelper::Get<DWORD>({ L"DisabledList" }, Utils::get_process_name(), 0);
249+
) ||
250+
RegHelper::Get<DWORD>({ L"DisabledList" }, Utils::get_process_name(), 0)
251+
);
252252
}
253253

254254
bool Api::IsStartAllBackTakingOver(std::wstring_view part)
255255
{
256256
if (GetModuleHandleW(L"StartAllBackX64.dll"))
257257
{
258+
if (!_wcsicmp(part.data(), L"DropDown"))
259+
{
260+
return false;
261+
}
262+
258263
if (part.empty() || !_wcsicmp(part.data(), L"Menu"))
259264
{
260265
auto immersiveMenus{ wil::reg::try_get_value_dword(HKEY_CURRENT_USER, L"SOFTWARE\\StartIsBack", L"ImmersiveMenus") };

Common/RegHelper.hpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,24 @@ namespace TranslucentFlyouts
1414
#endif // _WIN64
1515

1616
template <typename T, bool reverse>
17-
inline std::optional<T> GetValueInternal(std::wstring_view root, std::vector<std::wstring_view> keyTree, std::wstring_view valueName, size_t maxFallThrough)
17+
inline std::optional<T> GetValueInternal(std::wstring_view root, std::vector<std::wstring_view> keyTree, std::wstring_view valueName, size_t maxFallThrough) try
1818
{
1919
std::optional<T> value{};
2020
std::wstring keyName{ root };
2121
maxFallThrough += 1;
2222

2323
if (!keyTree.empty())
2424
{
25-
for (auto index{ 0 }; index < keyTree.size(); index++)
25+
for (auto i{ 1ull }; i <= keyTree.size(); i++)
2626
{
2727
keyName = root;
28-
for (auto i{ keyTree.size() - 1 }; i >= index && maxFallThrough > 0; i--, maxFallThrough--)
28+
for (auto j{ 0ull }; j < i && maxFallThrough >= 0; j++, maxFallThrough--)
2929
{
30-
if (!keyTree[i].empty())
30+
auto index{ keyTree.size() - j - 1 };
31+
if (!keyTree[index].empty())
3132
{
3233
keyName += L"\\";
33-
keyName += keyTree[i];
34+
keyName += keyTree[index];
3435
}
3536
}
3637

@@ -98,6 +99,8 @@ namespace TranslucentFlyouts
9899

99100
return value;
100101
}
102+
catch(...) { return std::nullopt; }
103+
101104
template <typename T, bool reverse>
102105
inline HRESULT SetValueInternal(std::wstring_view root, std::vector<std::wstring_view> keyTree, std::wstring_view valueName, T value, size_t maxFallThrough)
103106
{

Common/Utils.hpp

+31-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ namespace TranslucentFlyouts::Utils
8585
return std::wstring{filePath};
8686
}
8787

88-
inline std::wstring get_process_name()
88+
inline const std::wstring& get_process_name()
8989
{
9090
static const auto s_processName{ get_module_base_file_name(nullptr) };
9191
return s_processName;
@@ -216,6 +216,36 @@ namespace TranslucentFlyouts::Utils
216216
return classNameOK && windowTextOK;
217217
}
218218

219+
inline bool IsCurrentThreadContainVisibleWindow()
220+
{
221+
bool contain{ false };
222+
EnumThreadWindows(GetCurrentThreadId(), [](HWND hWnd, LPARAM lParam)
223+
{
224+
if (IsWindowVisible(hWnd))
225+
{
226+
*reinterpret_cast<bool*>(lParam) = true;
227+
return FALSE;
228+
}
229+
return TRUE;
230+
}, reinterpret_cast<LPARAM>(&contain));
231+
return contain;
232+
}
233+
234+
template <UINT id>
235+
__forceinline const std::wstring_view GetResWStringView()
236+
{
237+
LPCWSTR buffer{ nullptr };
238+
auto length{ LoadStringW(wil::GetModuleInstanceHandle(), id, reinterpret_cast<LPWSTR>(&buffer), 0)};
239+
return { buffer, static_cast<size_t>(length) };
240+
}
241+
template <UINT id>
242+
__forceinline std::wstring GetResWString()
243+
{
244+
LPCWSTR buffer{ nullptr };
245+
auto length{ LoadStringW(wil::GetModuleInstanceHandle(), id, reinterpret_cast<LPWSTR>(&buffer), 0) };
246+
return std::wstring{ buffer, static_cast<size_t>(length) };
247+
}
248+
219249
static bool IsPopupMenu(HWND hWnd)
220250
{
221251
WCHAR pszClass[MAX_PATH + 1] {};

0 commit comments

Comments
 (0)