How can I get the handle to the desktop?

Just starting out? Need help? Post your questions and find answers here.
deadmoap
User
User
Posts: 79
Joined: Sun Feb 22, 2004 11:45 pm
Location: Riverdale, Utah
Contact:

How can I get the handle to the desktop?

Post 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.
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post 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.
El_Choni
deadmoap
User
User
Posts: 79
Joined: Sun Feb 22, 2004 11:45 pm
Location: Riverdale, Utah
Contact:

Post 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...
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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
gkaizer
User
User
Posts: 40
Joined: Fri Oct 31, 2003 2:57 pm
Location: Italy

Post by gkaizer »

to use with FindWindow_

FindWindow_("#32769","")

hope it helps

cya
--:: Gkaizer ::--
Using PB 3.92 on WinXP SP2 and 3.91 on Mandrake Linux 10.0
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

funny enough, some api calls accept '0' as the handle for the windows desktop...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
El_Choni
TailBite Expert
TailBite Expert
Posts: 1007
Joined: Fri Apr 25, 2003 6:09 pm
Location: Spain

Post 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. "
El_Choni
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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
quidquid Latine dictum sit altum videtur
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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.
cwhite
New User
New User
Posts: 5
Joined: Fri Apr 23, 2004 3:32 am
Location: Maryland, USA

Post 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
Registered PB programmer since 3.30 (now using 3.90)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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.
Post Reply