Page 1 of 1

How can I get the handle to the desktop?

Posted: Thu Apr 22, 2004 2:24 am
by deadmoap
So that I could use it for drawing commands and whatnot. I could use FindWindow, I think, but what would I put in the parameters? I don't know what the "caption" of the desktop is, if it has one.

Posted: Thu Apr 22, 2004 2:30 am
by El_Choni
Desktop window handle in Windows: GetDesktopWindow_()

You can use the Windows API with that handle. You can also use common PB fucntions on an image, and then draw it to the desktop window.

Posted: Thu Apr 22, 2004 2:43 am
by deadmoap
Yeah, looking through user32.dll, I JUST happend the find that function. Now I'm pondering about how to use it. I have the handle to the desktop, but most of the functions take the window's constant (like #MainWindow) instead of it's ID.

P.S. Sadly, I have to call GetDesktopWindow by opening user32.dll instead of just calling it regularly because I still have the demo. :( :P

... which also reminds me that I could use FindWindow to get the handle of the debug window, then DestroyWindow to close it. :idea:

*Finds CloseDesktop function in user32*

Hmm...

Posted: Thu Apr 22, 2004 4:02 am
by PB
> Desktop window handle in Windows: GetDesktopWindow_()

Actually, this doesn't return the handle to the Desktop at all.
Use desktop=FindWindow_(0,"Program Manager") instead.

When I used GetDesktopWindow_() I saw that it didn't return the Desktop
at all, but my code (that uses FindWindow) does. If you want to see what
I mean, then try running this code, and while it's running, switch the focus
between the Desktop and some other windows...

Code: Select all

Repeat

  Sleep_(1)
  
  fg=GetForegroundWindow_()
  
  If fg<>old
  
    old=fg
    
    If fg=GetDesktopWindow_()
      Debug "YOU WILL NEVER SEE THIS LINE!"
    ElseIf fg=FindWindow_(0,"Program Manager")
      Debug "Current focus is Desktop via FindWindow"
    EndIf
  
  EndIf

ForEver

Posted: Thu Apr 22, 2004 8:24 am
by gkaizer
to use with FindWindow_

FindWindow_("#32769","")

hope it helps

cya

Posted: Thu Apr 22, 2004 9:55 am
by blueznl
funny enough, some api calls accept '0' as the handle for the windows desktop...

Posted: Thu Apr 22, 2004 12:03 pm
by El_Choni
From WIN32.HLP:

"The GetDesktopWindow function returns the handle of the Windows desktop window. The desktop window covers the entire screen. The desktop window is the area on top of which all icons and other windows are painted. "

Posted: Thu Apr 22, 2004 4:09 pm
by freak
Drawing on the desktop is not a wise thing to do imho.
Better open a window (skinned maybe?) and draw on that.

Timo

Posted: Fri Apr 23, 2004 1:27 am
by PB
> From WIN32.HLP: "The GetDesktopWindow function returns the handle
> of the Windows desktop window [snip]"

Win32.hlp is wrong, as my code example proves. Avoid GetDesktopWindow.

Posted: Fri Apr 23, 2004 3:54 am
by cwhite
The GetDesktopWindow function is documented correctly, and does in fact return a valid handle to the desktop window. But...

The desktop window is the parent window to a SysListView32 window that completely covers the desktop window. It is this child window that is used to display desktop icons. So, when you click the "desktop", you are actually selecting the child SysListView32 window.

To see that the desktop window handle is valid, the following code returns the size and position of the desktop:

Code: Select all

DefType.RECT myRect
hwndDesktop = GetDesktopWindow_()
  
; Get size and position of desktop window
GetWindowRect_(hwndDesktop, @myRect)
  
Debug "hwndDesktop=" + Str(hwndDesktop)
Debug "rect=(" + Str(myRect\left) + "," + Str(myRect\top) + "," + Str(myRect\right) + "," + Str(myRect\bottom) + ")"
-Chris

Posted: Fri Apr 23, 2004 4:35 am
by PB
> The desktop window is the parent window to a SysListView32 window
> that completely covers the desktop window. It is this child window that
> is used to display desktop icons.

I see. But Win32.hlp states: the desktop window is the area on top of which
all icons [...] are painted
; which therefore isn't quite true -- it's the underlying
SysListView32 child window upon which they're painted, as you pointed out.
It's this child window that my tip returns, since it's what the user is actually
clicking on and using when accessing the Desktop.