start tracking already topmost on start

This commit is contained in:
SeraphimaZ 2021-11-16 23:27:40 +03:00
parent 82cba89f7d
commit 4d888627e8
2 changed files with 34 additions and 0 deletions

View file

@ -11,6 +11,7 @@ AlwaysOnTop::AlwaysOnTop()
{
s_instance = this;
Init();
StartTrackingTopmostWindows();
}
AlwaysOnTop::~AlwaysOnTop()
@ -78,6 +79,38 @@ void AlwaysOnTop::ProcessCommand(HWND window)
}
}
void AlwaysOnTop::StartTrackingTopmostWindows()
{
using result_t = std::vector<HWND>;
result_t result;
auto enumWindows = [](HWND hwnd, LPARAM param) -> BOOL {
if (!IsWindowVisible(hwnd))
{
return TRUE;
}
auto windowName = GetWindowTextLength(hwnd);
if (windowName > 0)
{
result_t& result = *reinterpret_cast<result_t*>(param);
result.push_back(hwnd);
}
return TRUE;
};
EnumWindows(enumWindows, reinterpret_cast<LPARAM>(&result));
for (HWND window : result)
{
if (IsTopmost(window))
{
topmostWindows.push_back(window);
}
}
}
void AlwaysOnTop::ResetAll()
{
for (HWND topWindow : topmostWindows)

View file

@ -33,6 +33,7 @@ private:
LRESULT WndProc(HWND, UINT, WPARAM, LPARAM) noexcept;
void ProcessCommand(HWND window);
void StartTrackingTopmostWindows();
void ResetAll();
void CleanUp();