Question : Draw on Window Desktop Background

I need ot draw directly onto the windows desktop, behind the desktop icons.

Simply setting the desktop wallpaper is far to so, how can I draw onto this space directly in vb.net.

I know I can get the handle of the desktop from GetShellWindow, but I have no idea how to draw it behind the desktop icons.

I cant even get it to draw into this handle, even if it were to draw over the icons it would be a start!

Answer : Draw on Window Desktop Background

GetDC() should be paired with a ReleaseDC() call otherwise you'll get an eventual GDI leak.

See: http://msdn.microsoft.com/en-us/library/aa921543.aspx

    "After painting with a common device context, the ReleaseDC function must be called to release the device context."

If going that route I would do:

    Private Declare Function GetDesktopWindow Lib "user32" () As IntPtr
    Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As IntPtr) As IntPtr
    Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As IntPtr, ByVal hdc As Integer) As Integer
 
    ...
        Dim desktopHwnd As IntPtr = GetDesktopWindow()
        Dim desktopHdc As IntPtr = GetWindowDC(desktopHwnd)
        Dim G As Graphics = Graphics.FromHdc(desktopHdc)
        G.DrawLine(Pens.Red, 0, 0, 1024, 768)
        G.Dispose()
        ReleaseDC(desktopHwnd, desktopHdc)
Random Solutions  
 
programming4us programming4us