Finding currently visible desktop

G

Guest

How can I find the currently visible desktop? By calling EnumWindowStations
and EnumDesktops I get a list of all available desktops. But is there a way
to figure out which one of them is currently visible?

I've tried to find the visible desktop by comparing the desktop handle,
returned by the OpenDesktop function, to the desktop handle received by
calling OpenInputDesktop. The result is that the default desktop is always
the one currently receiving user input.
But by using the default desktop my window always shows up at the desktop of
the first user logged on to the system after reboot. No matter if this
desktop is currently visible or not!

As a second attempt I've called GetUserObjectInformation for each desktop
and checked the visible flag. But the result is there is no visible desktop
at all !?

What am I doing wrong? Or what is the right way to search for the currently
visible desktop?
 
G

Guest

Okay, let me rephrase my question more precisely:
I want the desktop currently visible at the display connected directly to
the computer. No remote or inactive desktops. And if there's more then one,
fine, which one of them are visible?
The main thing is: I need to find the desktop which currently has full
access to the graphic adapters hardware acceleration.
 
S

SvenC

Hi,

Mephisto187 said:
Okay, let me rephrase my question more precisely:
I want the desktop currently visible at the display connected directly to
the computer. No remote or inactive desktops. And if there's more then
one,
fine, which one of them are visible?
The main thing is: I need to find the desktop which currently has full
access to the graphic adapters hardware acceleration.

hmm - can a desktop have full access to a GPU or parts of a GPU, sorry don't
know.
 
G

Guest

The problem is. On remote desktops there is only software rendering
available. And on invisible desktops the graphic driver is not performing any
rendering at all because there is no visible window.
So I need to get access to a visible desktop in order to get access to the
graphical hardware
 
D

David Ching

Mephisto187 said:
How can I find the currently visible desktop? By calling
EnumWindowStations
and EnumDesktops I get a list of all available desktops. But is there a
way
to figure out which one of them is currently visible?

If you have an hwnd that is on the desktop you are looking for, you can do a
GetWindowThreadProcessId() to get the thread id of it, then use
GetThreadDesktop() to get an HDESK of that thread.

-- David
http://www.dcsoft.com
 
B

Bruno van Dooren [MVP VC++]

The problem is. On remote desktops there is only software rendering
available. And on invisible desktops the graphic driver is not performing
any
rendering at all because there is no visible window.
So I need to get access to a visible desktop in order to get access to the
graphical hardware

But that is never going to work reliably.
If the Logon desktop is visible (for example, when you log on (duh) or
change your password) you can not get access to it.
Or if the visible desktop belongs to the administrator, I think you are also
out of luck.

There is a number of cases where you are not allowed access to the visible
desktop out of concern for security.
But if your desktop is not visible, it shouldn't matter if your stuff is
drawn or not.
What is is that you are trying to do?

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 
B

Bruno van Dooren [MVP VC++]

How can I find the currently visible desktop? By calling
If you have an hwnd that is on the desktop you are looking for, you can do
a GetWindowThreadProcessId() to get the thread id of it, then use
GetThreadDesktop() to get an HDESK of that thread.

Since he doesn't know which desktop is visible, he probably wouldn't know
which windows are visible either.
And of course, you cannot get access to the logon desktop - and possible
other desktops as well- for security reasons.

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 
G

Guest

Actually, I've already managed to open a window on the administrators desktop
from within my remote desktop.
What I'm doing is the graphical component for a benchmarking tool designed
to be used in hospitals for unattended system checks.
If the window is not visible the graphic driver is so clever that he is not
performing real rendering any more. At least the framerate reaches
astronomical values.
 
B

Bruno van Dooren [MVP VC++]

Actually, I've already managed to open a window on the administrators
desktop
from within my remote desktop.
What I'm doing is the graphical component for a benchmarking tool designed
to be used in hospitals for unattended system checks.
If the window is not visible the graphic driver is so clever that he is
not
performing real rendering any more. At least the framerate reaches
astronomical values.

There is 1 thing that I know that might help you. But be aware that this is
just thinking out loud.
For more info you should follow up with a post in the kernel programmers
groups, because they might know the details.
Note: explain what you want to do, because if they think you are writing
malware, they are less likely to help you.

If an application crashes, the system will launch a debugger, and a window
will appear to handle the problem.
this will happen, regardless of which desktop is on the main monitor. even
if it is the logon screen.
now if you could register your application as the active debugger, and then
simulate an application crash, you could -theoretically- open your
application with your custom window on that desktop, no matter which one
that might be.

I have never done this myself, but the principle should work. As I said, you
can probably get better info in the kernel programmer newsgroup, or in the
debugger newsgroup for this strategy.

Good luck.

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 
G

Guest

Okay, thank you very much for your advice! I will do so and start a request
in the kernel programmers group
 
D

David Ching

Mephisto187 said:
Actually, I've already managed to open a window on the administrators
desktop
from within my remote desktop.

Then you do have an hwnd, and you can use the GetWindowThreadProcessId(),
GetThreadDesktop() technique.

-- David
 
B

Ben Voigt

Mephisto187 said:
The problem is. On remote desktops there is only software rendering
available. And on invisible desktops the graphic driver is not performing
any
rendering at all because there is no visible window.
So I need to get access to a visible desktop in order to get access to the
graphical hardware

Maybe GetDeviceCaps or something similar (tested for each candidate desktop)
would help?
 
G

Guest

There are no options or parameters for GetDeviceCaps in order to use it for
searching a visible device. So I don't know how to use it in this context.

Anyway, meanwhile I've managed to access hardware acceleration from within a
service by using so called pbuffer offscreen rendering. Thus, it is no longer
a problem to work without a visible desktop as long as we're running as a
service.

Nevertheless, the problem remains the same for remote access. Via remote,
there are no pbuffers available. So you still have to get access to the
currently visible desktop somehow...
 
G

Guest

David Ching said:
Then you do have an hwnd, and you can use the GetWindowThreadProcessId(),
GetThreadDesktop() technique.

Hi David.
Sorry, somehow I must have read over your reply! The problem is that I don't
know if this window was created on a visible or an invisible desktop. So
there's no benefit from getting the desktop handle after creating the window.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top