473,382 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Finding currently visible desktop

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
15 2990
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
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
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
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
"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
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
>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
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
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
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
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
"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
"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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mike Turco | last post by:
How do I go about finding the location of the desktop, temp folder, program files folder, my documents, etc. For example, say that I want to programmatically export a table to a file on the...
5
by: Dan Pavel | last post by:
Hi, I am starting a new process (Notepad) on a remote machine but it is not visible. When I start it on my machine it is visible. What I am doing wrong ? private void run_notepad(string machina)...
7
by: Richard | last post by:
If the grid is dragged off the screen and back on the data is visible. Tried a dg.refresh() and Inactivate(). Can I do this by overriding custom base class OnPaint that my form inherits from? I...
3
by: simonc | last post by:
I am writing a program that runs doing a repetitive task for several minutes. When I start it calculating the program's form only stays visible as long as it is the top window on the desktop. As...
4
by: Ahmed Perlom | last post by:
Hi all, How can I know if the session ID that a certain process is running on is actually the active session that he consol is connected to. I can get the session id of a process by
4
by: Abhishek | last post by:
Hi All, how do I find the handle of a child window and get a screenshot of that in a hbitmap at present i tried the below method but am getting the screenshot of the desktop. the Egyptian...
6
by: Lee | last post by:
how can i do this? I have a form, which i do not want to keep on top of all others (TopMost), yet i dont want it dissapearing when the "show desktop" button is pressed. Now i know that the...
0
by: Mani | last post by:
Hi All, I have a terminal server running in Windows 2000. I have an MFC application "A.exe" developed in VC++ 2005, which runs in this machine. This application shows a tray icon in the task bar...
1
by: Ganesh | last post by:
Dear Experts, I have an application that has several graphical components on it. The state of these components is decided by some data which is available in some data store. The graphical...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.