Odd question but needy solution

ImDaFrEaK

Well-known member
Joined
Jan 7, 2006
Messages
416
Location
California
Programming Experience
5-10
This may be an odd question but I need to find away to make this work. I want to either reference the Desktop ClientRectangle and or simulate this by making a form that is always at the bottom of the z order. Either way I want to paint the desktop with like a video as a background so to speak. Any ideas on accomplishing this please let me know. Thanks. I understand I may have to do some sub classing to watch and change the Z order of the form and or use an API to get the desktop but if anyone has a good start or an answer i'm all ears.
 
I can't say i've ever done this but here's how you would get DeskTopWindow

VB.NET:
<DLLImport("user32.Dll")> _
Private shared Function GetDesktopWindow Lib "user32.dll" () As intptr

You can then create a graphics object with which to draw....

VB.NET:
Dim Hdc as intptr = GetDeskTopWindow
Dim G as graphics = Graphics.FromHdc(Hdc)
 
I've seen that with several TV-tuner cards, they display the video on the desktop background behind the icons. Very cool effect!

vis781, suggestion won't work for two reasons, one is that a handle to a window is not the same as a handle to a DC, though Graphics.FromHwnd would get that sorted - or also using GetDC/GetWindowDC, but even if the GetDesktopWindow is the root window it basically returns the same as GetDC(0) which draws over all windows and not at background at all.

If you search for internal windows/classes with Spy++ or similar tool and point to the desktop background you'll find that it is a 'Folderview' window of class 'SysListView32', this is the listview that displays the icons on the desktop, and it is a child of 'SHELLDLL_DefView' class which in turn is a child of 'Program Manager' window of class 'Progman'. Not sure if it is possible to do the same with GetDCEx specifying a clipping region the excludes all visible windows, but if so it would also not exclude desktop icons.

When creating graphics and drawing to either of these three hwnds what is drawn stays behind all windows, but still not behind the icons on desktop.

I also did a faint try with Win32 API SetWindowPos and HWND_BOTTON which does sent app furthest to the back but on top of icons, you also have to work with the WM_Activate message. (SetParent with different windows doesn't help either.) Normal windows are already childs of Desktop window (which here always returns handle 65556, perhaps insignificant info?).

For a moment I was thinking 'SysListView32' is a regular system listview that you can change the background image of with API method, but it is yet another bad idea, it's image file system based, and same as changing the wallpaper.

Attachment:
I've attached a project that draws to SysListView32, it's quite entertaining to watch desktop background drawing and paint invalidation at 100ms timer. :)

Included is code commented out easy to change to see the effect of
drawing to DC of GetDesktopWindow, you will then also notice that the rectangle invalidation doesn't work, and this is because of what I explained above, the DC returned is the equivalent of DC(0). Trying to then invalidate the RECT for hwnd 0 instead of hwnd 65556 works but flickers a lot at 100ms.

Another thing you should try is to change the InvalidateRECT call from True to False for bErase parameter (while drawing to SysListview32 hwnd), the funny thing you will see now is that what is drawn to background does not disappear except for that drawn over the icons, now the icons do invalidate!! I don't think this is exactly how they do it, but imagine that you draw the whole background at 25fps live video and invalidate without Erase - the result is actually the same - live video on the background behind the icons of desktop ;)
 

Attachments

  • drawBackground.zip
    13.8 KB · Views: 34
Wow

JohnH, You are full of great knowledge obviously and seem to have a much better understanding of what is happening. I will review your attachment, thanks for the post as well and all the info. I have been slightly successful with SetWindowPos but as you mentioned it is drawn over the icons. The only other option I have for now is to display a seperate form transparently on top of the video form and have the second form with Icons that resemble the desktop icons and of course work the same way. Maybe more work than I thought but were on the right course so far. This is tricky business but it can be accomplished with full success im sure. Thanks again for your help.... your awesome.
 
also if it's just a set simple video, you might want to consider making it a GIF file and using it as your desktop background, as it will animate
 
Back
Top