Re: BitBlt failing under XP with a locked screen saver
From: Christopher Bohn (cbohn_at_nospammingrrinc.com)
Date: 03/08/04
- Next message: Feng Yuan [MSFT]: "Re: TransparentBlt() limitation?"
- Previous message: Mike D Sutton _at_ Work: "Re: Range of colors"
- In reply to: Christopher Bohn: "Re: BitBlt failing under XP with a locked screen saver"
- Next in thread: Christopher Bohn: "Re: BitBlt failing under XP with a locked screen saver"
- Reply: Christopher Bohn: "Re: BitBlt failing under XP with a locked screen saver"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 08 Mar 2004 13:57:41 -0500
I still haven't received a Microsoft reply on this post, but I can verify that the name comparison approach does work
(despite my question about GetThreadDesktop, which still doesn't make sense to me). If I don't attempt my BitBlt operation
(actually, I skip my entire paint routine) if the desktop isn't active, then I don't get any failures. I would still like to
know if there is a better way to do this, and some clarification on the GetThreadDesktop(GetCurrentThreadID()) issue below.
For anyone interested, I copied this code directly from a site I found while searching (minor mods only to use printf instead of
otherwise unavailable routines used in the original code):
BOOL InputDesktopSelected(void)
{
// Get the input and thread desktops
HDESK threaddesktop = GetThreadDesktop(GetCurrentThreadId());
HDESK inputdesktop = OpenInputDesktop(0, FALSE,
DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
DESKTOP_SWITCHDESKTOP | GENERIC_WRITE);
// Get the desktop names:
// *** I think this is horribly inefficient but I'm not sure.
if (inputdesktop == NULL)
return FALSE;
DWORD dummy;
char threadname[512];
char inputname[512];
if (!GetUserObjectInformation(threaddesktop, UOI_NAME, &threadname, 256, &dummy)) {
if (!CloseDesktop(inputdesktop))
printf("failed to close input desktop\n");
return FALSE;
}
assert(dummy <= 512);
if (!GetUserObjectInformation(inputdesktop, UOI_NAME, &inputname, 256, &dummy)) {
if (!CloseDesktop(inputdesktop))
printf("failed to close input desktop\n");
return FALSE;
}
assert(dummy <= 512);
if (!CloseDesktop(inputdesktop))
printf("failed to close input desktop\n");
if (strcmp(threadname, inputname) != 0)
return FALSE;
return TRUE;
}
I call this function, and if the desktop isn't active, then I skip my paint function body.
Chris
Christopher Bohn wrote:
> What is the best approach to determine what the active desktop actually
> is to determine if my app's desktop is active. If the app's desktop is
> active, it is a real error I need to handle. If the app's desktop isn't
> active (e.g., locked screen saver running in its own desktop), then I
> can ignore the error. I have searched some groups and found approaches
> that do things like:
>
> HDESK threaddesktop = GetThreadDesktop(GetCurrentThreadId());
> HDESK inputdesktop = OpenInputDesktop(...)
>
> then get the name of each desktop through the GetUserObjectInformation
> call, and then compare the names to see if they are the same. That
> doesn't seem like a great approach, but after looking more, I don't see
> many other choices. It would be nice if there was a simple way to get
> the name of the active desktop (in which case, if it wasn't the input
> desktop, as seen from OpenInputDesktop, then I could know the input
> desktop wasn't active).
>
> I haven't tried the example method indicated above yet, but it seemed
> like GetThreadDesktop(GetCurrentThreadId()) would always return the
> input desktop because the app is started on it, and I wouldn't think the
> thread would change desktops just because a locked screen saver starts.
>
> Chris
>
> Rhett Gong [MSFT] wrote:
>
>> Hi Dave,
>> I am succeeded to repro it in my xp machine. It looks like the same
>> problem with Chris. From my test, it returns ERROR_ACCESS_DENIED.
>> Based on my search, It seems that most native applications ignore GDI
>> errors so they never cause this problem. :(
>>
>> I agree with Chris that it should have an error named
>> ERROR_NOT_AN_ACTIVE_DESKTOP_SO_CANT_DRAW, since it won't be drawn if
>> the DC is not on an active desktop.
>> One possible resolution is to catch and ignore this error in your app.
>> I know this is not really a good approach, because there really is an
>> error which could be handled earlier in the code path. Thanks for your
>> understanding.
>>
>> Hope this helps.
>> Rhett Gong [MSFT]
>> Microsoft Online Partner Support
>>
>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>> Please reply to newsgroups only. Thanks.
- Next message: Feng Yuan [MSFT]: "Re: TransparentBlt() limitation?"
- Previous message: Mike D Sutton _at_ Work: "Re: Range of colors"
- In reply to: Christopher Bohn: "Re: BitBlt failing under XP with a locked screen saver"
- Next in thread: Christopher Bohn: "Re: BitBlt failing under XP with a locked screen saver"
- Reply: Christopher Bohn: "Re: BitBlt failing under XP with a locked screen saver"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|