I'm trying to use the EnumWindows
function, which takes a WNDENUMPROC
as callback with a lambda in order to access local variables. Unfrotunately if i try to use [&]
the compiler will tell me types don't match.
What i'm trying:
HWND get_wallpaper_window()
{
HWND progman = FindWindow(L"ProgMan", NULL);
SendMessageTimeout(progman, 0x052C, 0, 0, SMTO_NORMAL, 1000, nullptr);
HWND wallpaper_hwnd;
EnumWindows(
// Error here
[&](HWND hwnd, LPARAM lParam) -> BOOL CALLBACK
{
HWND p = FindWindowEx(hwnd, NULL, L"SHELLDLL_DefView", NULL);
if (p) { wallpaper_hwnd = FindWindowEx(NULL, hwnd, L"WorkerW", NULL); }
}
, NULL);
return wallpaper_hwnd;
}
The only solution i could come up with is making wallpaper_hwnd global and defining the lambda with []
, but since it's only needed when returned from that function and not needed globally i'd rather avoid that.
I love using globals way more than people would advice, but i only do when the global variable is something that interacts with the whole program, and this is not the case.
Any better solution i'm missing?