I've tried googling for this but it seems this question remains unanswered. Is there anyway to check if the user's current active window is the desktop?
#include <iostream>
#include <Windows.h>
int main ()
{
HWND desktop = GetDesktopWindow();
for (int i = 0; i < 20; i++)
{
HWND window = GetForegroundWindow();
if (desktop == window)
{
std::cout << "Desktop Active!\n";
}
else
{
std::cout << "Desktop NOT Active!\n";
}
Sleep(1000);
}
}
This always reports the desktop is inactive, even when all windows are minimized to the taskbar and only the desktop is visible. Doing a net search doesn't bring up any methods either.
Using GetActiveWindow() instead of GetForegroundWindow() gives the same output.
Maybe also there is some Win32 "trick" I am missing and it is quite easy to check if the Desktop is the active window.
Well, it would help if I actually checked each loop for what the active window is, code revised. Still won't detect the desktop as being the active window. Ooops! :|
#include <iostream>
#include <Windows.h>
int main ()
{
HWND desktop = GetDesktopWindow();
SetForegroundWindow(desktop);
for (int i = 0; i < 20; i++)
{
HWND window = GetForegroundWindow();
if (desktop == window)
{
std::cout << "Desktop Active!\n";
}
else
{
std::cout << "Desktop NOT Active!\n";
}
Sleep(1000);
}
}
Well, it would help if I actually checked each loop for what the active window is, code revised. Still won't detect the desktop as being the active window. Ooops! :|
Still won't detect the desktop as being the active window.
That's because it's actually a child of the desktop which gets the focus.
On my Windows 10 PC, it's a child window named "Program Manager"of window class "Progman", but if the system is showing wallpaper then different windows are involved.
This problem was discussed on this site a few years ago: