I want to write a programm which uses OpenGL to create a animated desktop background. Therefore i need to know the HWND that contains the picture from the desktop. Perfect would be a code-example how i find that specific window.
-
1`GetDesktopWindow` doesn't cut it? – Igor Tandetnik Jan 24 '15 at 04:28
-
No. GetDesktopWindow() Is not the window that contains the desktop background. I've tried that. – Unwissender Philosoph Jan 24 '15 at 04:47
-
I think what you'r looking for is this http://stackoverflow.com/questions/14186400/setting-wallpaper-with-win-api – Young Hyun Yoo Jan 24 '15 at 04:55
-
No not directly. I dont want to set the desktop to a static picture, i want to animate a 3D object in real time on it. I saw that allready, but thats not what i am looking for. – Unwissender Philosoph Jan 24 '15 at 05:08
-
GetDC(NULL) give you the main context, not sure background image is accessible thrue api. but you may try this: http://www.codeproject.com/Questions/588027/Win-plusAPIplusbackgroundplusimageplusproblems – j-p Jan 24 '15 at 14:47
1 Answers
If you carefully read the documentation you will find that you must not set the pixel format on the root / desktop window. Also the DC of the desktop window is not owned exclusively. Either constraint make it impossible to create a OpenGL context on the desktop window directly. Also note, that for your typical Windows shell (explorer.exe), the desktop is actually a Win32 Icon View, owned by a explorer.exe process and being a child of the desktop window.
What you can do is create a FBO the same size of the desktop window, with a pixelformat that's compatible with the DC of the desktop window. Then render to the FBO read its contents into a DIBSection use CreateDIBPatternBrushPt to create a HBRUSH and set the background brush of the desktop window with SetClassLongPtr.

- 159,371
- 13
- 185
- 298