Alright, I was able to test and that does seem to work. I'm not sure what I did differently before. I'll need to do some testing to see what IsRealWindow accepts in addition to WS_BORDER and WS_VISIBLE.
One minor issue remains - new style Windows Store apps (such as "Settings") seem to persist after close. Somewhere on that blog I referenced earlier I read that they are cached by the OS similar to how Android caches applications. A user has to go out of their way to close them.
Does anyone know any way to check if a window is a cached application?
To see what I mean, run this code:
C++ Code:
#include <windows.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
BOOL CALLBACK EnumWindowsCallback(
_In_ HWND hWnd,
_In_ LPARAM lParam
);
int
main(int argc, char *argv[])
{
EnumWindows(EnumWindowsCallback, 0);
return 0;
}
BOOL CALLBACK
EnumWindowsCallback(
_In_ HWND hWnd,
_In_ LPARAM lParam
)
{
int nMax = GetWindowTextLengthW(hWnd) + 1;
LPWSTR lpStr = new wchar_t[nMax];
if (!(nMax - 1))
return TRUE;
if (!GetWindowTextW(hWnd, lpStr, nMax)) {
// TODO: Call SetLastError.
// TODO: Return FALSE to stop enumeration.
}
LONG lStyle;
if (!(lStyle = GetWindowLong(hWnd, GWL_STYLE))) {
// TODO: Call SetLastError.
// TODO: Return FALSE to stop enumeration.
}
// These conditions are fulfilled by windows with a desktop presence.
if ((lStyle & (WS_BORDER | WS_VISIBLE)) != (WS_BORDER | WS_VISIBLE))
return TRUE;
wcout << lpStr << std::endl;
delete[] lpStr;
return TRUE;
}
If you open the Settings program (labelled "Trusted Windows Store app" in the start menu) and then close it, you should still see it in the output of this program.