asked on
static bool OnDefaultDesktop() {
// UOI_IO checks whether given desktop is currently receiving input, but it's >=Vista.
// So we check whether thread desktop and input desktop have the same name.
HDESK hdeskInput=OpenInputDesktop(0, FALSE, 0); // does not set GetLastError(), so GetLastError() is arbitrary if NULL is returned
if( hdeskInput==NULL ) {
TRACE( "hdeskInput==NULL" );
return false;
}
DWORD nLengthNeeded;
TCHAR szInputDesktop[16];
APIERR( GetUserObjectInformation( hdeskInput, UOI_NAME, &szInputDesktop, sizeof(szInputDesktop), &nLengthNeeded ) && nLengthNeeded<=sizeof(szInputDesktop) );
APIERR( CloseDesktop( hdeskInput ) );
HDESK hdeskThread=GetThreadDesktop( GetCurrentThreadId() ); // MSDN says no need to close this handle
APIERR( hdeskThread );
TCHAR szThreadDesktop[16];
APIERR( GetUserObjectInformation( hdeskThread, UOI_NAME, &szThreadDesktop, sizeof(szThreadDesktop), &nLengthNeeded ) && nLengthNeeded<=sizeof(szThreadDesktop) );
_ASSERTNOTIFY( _tcsicmp( szThreadDesktop, _T("DEFAULT") )==0 ); // I think it is always named "DEFAULT"
return _tcsicmp( szThreadDesktop, szInputDesktop )==0;
}