C# to C++, drawing on windows wallpaper, under icons

Hi,
i could find lots of solutions to draw on windows wallpaper in c++ but none of them work with windows 10 (they're mostly answers for windows xp), and the handle they retrive is null.

I've tested the code from here (https://www.codeproject.com/Articles/856020/Draw-Behind-Desktop-Icons-in-Windows-plus) in C# and it works. I understood the explanation but i'm not experienced with windows api enough to replicate that process myself,
and i never used C# so i can't figure out how to translate that to C++. Can someone "translate" it for me?

NOTE: the window returned by GetDesktopWindow contains desktop icons too and is under regular windows. What i want is to draw under these icons.
Last edited on
An update. I did it using a global as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
HWND wallpaper_hwnd = nullptr;

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
	{
	HWND p = FindWindowEx(hwnd, NULL, L"SHELLDLL_DefView", NULL);
	if (p)
		{
		wallpaper_hwnd = FindWindowEx(NULL, hwnd, L"WorkerW", NULL);
		}
	return true;
	}

void get_wallpaper_window()
	{
	HWND progman = FindWindow(L"ProgMan", NULL);
	SendMessageTimeout(progman, 0x052C, 0, 0, SMTO_NORMAL, 1000, nullptr);

	EnumWindows(EnumWindowsProc, NULL);
	return;
	}


But while i'd prefer not to, the type expected for the callback by EnumWindows doesn't me allow to use [&] in order to have "wallpaper_hwnd" as local variable in the get_wallpaper_window function.

I'd prefer to do something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
HWND get_wallpaper_window()
	{
	HWND progman = FindWindow(L"ProgMan", NULL);
	SendMessageTimeout(progman, 0x052C, 0, 0, SMTO_NORMAL, 1000, nullptr);

	HWND wallpaper_hwnd;
	EnumWindows(
		[&](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;
	}
well it feels like i'm talking with myself hereā€¦
If anyone ends up in this topic here's the answer: https://stackoverflow.com/questions/56101925/windows-types-wont-let-my-callback-access-local-variables-any-workaround
Sorry I couldn't help, but thanks for posting what you found, as that can help others that might find this.
Registered users can post here. Sign in or register to post.