Re: BitBlt failing under XP with a locked screen saver

From: Christopher Bohn (cbohn_at_nospammingrrinc.com)
Date: 03/08/04


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.



Relevant Pages

  • Re: Saving state of toolbar control
    ... how can I create buttons for a toolbar that are ... > Chris Hanscom - Microsoft MVP ... Sign the petition to Microsoft. ... >> I'm writing an app in VB6 that uses the ToolBar control from the Microsoft ...
    (microsoft.public.vb.general.discussion)
  • Re: RAID 5
    ... Also thanks for Chris' kind inputs, ... please help me to capture a screen shot of the ... Open Paint or Microsoft Word or WordPad. ... >> This newsgroup only focuses on SBS technical issues. ...
    (microsoft.public.windows.server.general)
  • MSN.exe - what is it, how to fix it?
    ... A friend has a Verizon DSL account which appears to have a tricked-up ... nature of file naming and product management by Microsoft. ... keyword for searching for solutions or download packages. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: License Transfer
    ... And when I am the manufacturer? ... "Chris H." ... > not Microsoft setting things tied to their BIOS within that system. ... >>> upgrade just the CPU is it the same machine? ...
    (microsoft.public.windows.mediacenter)
  • Re: where to find information
    ... searching on the original Q number but came up with nothing. ... I find that Microsoft has a habit of redoing their article locations and ... > been a custom macro. ... >> I've been trying to locate documentation on macro word commands. ...
    (microsoft.public.word.docmanagement)