tags:

views:

419

answers:

1

The Windows API provides an API GetDesktopWindow( ) which returns the window handle

But I tested with Spy++ and I find that the window handle of the desktop and the window handle of the "Windows Desktop" is not the same.

As the "Windows Desktop" is a list view, do I need to do the following

1) HANDLE hWnd = GetDesktopWindow() ;
2) FindWindow(hWnd, ..... ) with the SyslistView32 as the Window class.

Once I get the Window handle, I want to use SendMessage() for operations like getting selected file name, the number of files selected , etc.

Please give your opinions. I am doing this using the Windows SDk

+4  A: 

If you want the Desktop window as defined in GetDesktopWindow(), use that window handle. This is the window handle you should use to look for top-level windows and other related activities.

What you're seeing in Spy++ is just the content drawn as the desktop in your session. If you use the auto-locate in Spy++, you'll see that the SysListView32-declared window is a child window of your explorer shell. It is quite infrequent for someone to need access to this window. Also, the existence of this window may be subject to changes between versions of windows.

Edit (additional info)

If you are looking to interact or place things on the actual shell desktop, you may be better served by other APIs. Here are two such APIs that can accomplish this, depending on the target version of windows.

Windows Sidebar @ MSDN
This is available on Vista and Windows 7

Using the Active Desktop @ MSDN
This is available on Windows 2000 and XP, although frequently disabled by users and sysadmins.

meklarian
But Spy++ also returns the handle of the window, and the handle retunred by Spy++ and the GetDesktopWindow is different
Sujay Ghosh