Click to See Complete Forum and Search --> : How to get currently active desktop?


Matthias Kring
July 24th, 2003, 08:56 AM
I want to create an application that runs on a system which uses different desktops.
My appl. is always to be run on the "default" desktop.
However, error messages (simple message boxes) from my app. should be shown on the desktop that is currently in use.
I'm not allowed to switch back to the default desktop.

GetThreadDesktop() only leads to the desktop where my app. runs, i.e. the default one.
OpenInputDesktop() plus SetThreadDesktop() didn't work either.

MessageBox with MB_SERVICE_NOTIFICATION is rejected by the compiler.

Any ideas?

THX,
Matthias

Matthias Kring
July 24th, 2003, 09:48 AM
It works with MB_SERVICE_NOTIFICATION !

The compiler rejected it, because first, I had to
#define _WIN32_WINNT 0x0400
and 2nd,
I had to define it before windows.h is used :)

But anyway:

Is there any known API call to get the currently active desktop?

rxbagain
July 25th, 2003, 03:46 AM
MB_SERVICE_NOTIFICATION is useful only if the service has the "allow service to interract with desktop" setting. If this is not set, you cannot use the flag or the OpenInputDesktop. What you can do is to assocciate the "Winsta0" windowstation first and then get the active desktop and associate it to your thread. After this, you can now show your message box or other GUI objectsHWINSTA oldWndSta, hWnsta;
HDESK hDesk, oldDesk;
if (NULL != (oldWndSta = GetProcessWindowStation())) {
if (NULL != (oldDesk = GetThreadDesktop(GetCurrentThreadId()))) {
if (NULL != (hWnsta = ::OpenWindowStation("WinSta0", FALSE, MAXIMUM_ALLOWED))) {
if (::SetProcessWindowStation(hWnsta)) {
if (NULL != (hDesk = ::OpenInputDesktop(0, FALSE, MAXIMUM_ALLOWED))) {
if (::SetThreadDesktop(hDesk)) {
::MessageBox(NULL, "This is a regular messagebox from a service",
"My Service", MB_ICONINFORMATION);
::SetThreadDesktop(oldDesk);
}
}
::SetProcessWindowStation(oldWndSta);
}
::CloseWindowStation(hWnsta);
}
}
}
Hope it will help you

Matthias Kring
July 25th, 2003, 04:41 AM
Thanks, I will try.

I know, that MB_SERVICE_NOTIFICATION can only be used from a service that is allowed to interacr with the desktop.
In this particular case, the application will not run as as service.
It's just a simple program on the default desktop. (I didn't want to make it a service for some other reasons).

However, the normal users do not have access to the NT default desktop, and they are working on another desktop. So, the error messages from my app. should go there.
And this works with MB_SERVICE_NOTIFICATION, because this automatically uses the active desktop.
(So, there must be some way to get it. Maybe some undocumented feature)

Using GetThreadDesktop may not be helpful in this case, because my app is on the default desktop, and GetThreadDesktop will probably point to that one, not to the one which is really active.