Handmade Hero»Forums»Code
217 posts
How to draw directly to the desktop view without opening any window?

In handmade hero, we open a window then draw to it. I'm trying to just draw to the desktop view without opening any window. I also want to get all the current desktop icons and organize them through code. How can I do something like that?

Mārtiņš Možeiko
2562 posts / 2 projects
How to draw directly to the desktop view without opening any window?
Edited by Mārtiņš Možeiko on

To draw to "deskop" you simply create transparent window, place it at 0,0 position and make it's size to cover whole screen. Then whatever you'll draw there will be on your screen.

To rearrange desktop icons - here's the article that explains how to access & modify desktop icon position: https://devblogs.microsoft.com/oldnewthing/20130318-00/?p=4933

Basically you need to IFolderView object for desktop, then you can call GetDisplayNameOf/GetItemPosition/SelectAndPositionItems methods.

Documentation on IFolderView interface is here: https://docs.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ifolderview

217 posts
How to draw directly to the desktop view without opening any window?
Replying to mmozeiko (#25642)

To draw to "desktop" you simply create a transparent window, place it at 0,0 position and make it's size to cover the whole screen. Then whatever you'll draw there will be on your screen.

So this will draw on top of the desktop, right? What I want is to draw underneath all the desktop icons (but above the background).

Also, the blog and the IFolderView uses C++ (template, namespace) but I just code in C99. Is there any way to do that?

Mārtiņš Možeiko
2562 posts / 2 projects
How to draw directly to the desktop view without opening any window?
Edited by Mārtiņš Možeiko on
Replying to longtran2904 (#25643)

Seems this makes it possible to draw to contents of desktop background: https://www.codeproject.com/articles/856020/draw-behind-desktop-icons-in-windows-plus It's in C# code, but API functions it uses are pretty basic - get a special HWND handle, and then just get HDC and then drawing as usual. No idea if that still works on Windows 10 though, that's up to you to check.

IFolderView is COM object, you can use COM objects from C just fine. There are no template and namespaces involved. Just bunch of function pointers. For example how using COM objects looks in C check my Direct3D11 example: https://gist.github.com/mmozeiko/5e727f845db182d468a34d524508ad5f