By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,215 Members | 1,936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,215 IT Pros & Developers. It's quick & easy.

Finding currently visible desktop

P: n/a
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?
Sep 6 '06 #1
Share this Question
Share on Google+
15 Replies


P: n/a
Take a look at this blog entry, which explains why there is no "currentyl
visible desktop"

http://blogs.msdn.com/oldnewthing/ar...22/712677.aspx

--
SvenC

"Mephisto187" <Me*********@discussions.microsoft.comwrote in message
news:40**********************************@microsof t.com...
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?

Sep 6 '06 #2

P: n/a
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.

"SvenC" wrote:
Take a look at this blog entry, which explains why there is no "currentyl
visible desktop"

http://blogs.msdn.com/oldnewthing/ar...22/712677.aspx

--
SvenC

"Mephisto187" <Me*********@discussions.microsoft.comwrote in message
news:40**********************************@microsof t.com...
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?


Sep 6 '06 #3

P: n/a
Hi,

"Mephisto187" <Me*********@discussions.microsoft.comwrote in message
news:04**********************************@microsof t.com...
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.

--
SvenC
"SvenC" wrote:
>Take a look at this blog entry, which explains why there is no "currentyl
visible desktop"

http://blogs.msdn.com/oldnewthing/ar...22/712677.aspx

--
SvenC

"Mephisto187" <Me*********@discussions.microsoft.comwrote in message
news:40**********************************@microso ft.com...
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?



Sep 6 '06 #4

P: n/a
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

"SvenC" wrote:
Hi,

"Mephisto187" <Me*********@discussions.microsoft.comwrote in message
news:04**********************************@microsof t.com...
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.

--
SvenC
"SvenC" wrote:
Take a look at this blog entry, which explains why there is no "currentyl
visible desktop"

http://blogs.msdn.com/oldnewthing/ar...22/712677.aspx

--
SvenC

"Mephisto187" <Me*********@discussions.microsoft.comwrote in message
news:40**********************************@microsof t.com...
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?


Sep 6 '06 #5

P: n/a
"Mephisto187" <Me*********@discussions.microsoft.comwrote in message
news:40**********************************@microsof t.com...
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
Sep 6 '06 #6

P: n/a
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
br**********************@hotmail.com
Remove only "_nos_pam"
Sep 6 '06 #7

P: n/a
>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.
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
br**********************@hotmail.com
Remove only "_nos_pam"
Sep 6 '06 #8

P: n/a
Pretty smart, unfortunately I don't have such a handle.

"David Ching" wrote:
"Mephisto187" <Me*********@discussions.microsoft.comwrote in message
news:40**********************************@microsof t.com...
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
Sep 6 '06 #9

P: n/a
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.

"Bruno van Dooren [MVP VC++]" wrote:
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
br**********************@hotmail.com
Remove only "_nos_pam"
Sep 6 '06 #10

P: n/a
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
br**********************@hotmail.com
Remove only "_nos_pam"
Sep 6 '06 #11

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

"Bruno van Dooren [MVP VC++]" wrote:
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
br**********************@hotmail.com
Remove only "_nos_pam"
Sep 7 '06 #12

P: n/a
"Mephisto187" <Me*********@discussions.microsoft.comwrote in message
news:4D**********************************@microsof t.com...
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
Sep 7 '06 #13

P: n/a
"Mephisto187" <Me*********@discussions.microsoft.comwrote in message
news:D0**********************************@microsof t.com...
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?
>
"SvenC" wrote:
>Hi,

"Mephisto187" <Me*********@discussions.microsoft.comwrote in message
news:04**********************************@microso ft.com...
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.

--
SvenC
"SvenC" wrote:

Take a look at this blog entry, which explains why there is no
"currentyl
visible desktop"

http://blogs.msdn.com/oldnewthing/ar...22/712677.aspx

--
SvenC

"Mephisto187" <Me*********@discussions.microsoft.comwrote in message
news:40**********************************@microso ft.com...
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?



Sep 8 '06 #14

P: n/a
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...

"Ben Voigt" wrote:
"Mephisto187" <Me*********@discussions.microsoft.comwrote in message
news:D0**********************************@microsof t.com...
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?

"SvenC" wrote:
Hi,

"Mephisto187" <Me*********@discussions.microsoft.comwrote in message
news:04**********************************@microsof t.com...
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.

--
SvenC

"SvenC" wrote:

Take a look at this blog entry, which explains why there is no
"currentyl
visible desktop"

http://blogs.msdn.com/oldnewthing/ar...22/712677.aspx

--
SvenC

"Mephisto187" <Me*********@discussions.microsoft.comwrote in message
news:40**********************************@microsof t.com...
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?



Sep 11 '06 #15

P: n/a
"David Ching" wrote:
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.
Sep 12 '06 #16

This discussion thread is closed

Replies have been disabled for this discussion.