Snippets

Amin Ahmadi isDesktopAvailable

Created by Amin Ahmadi last modified
/*
    Here is how you can check and see if Windows is locked in Qt/C++. This same function will also let you know if the user is switched to another. 

    Make sure you add the following line in your Qt PRO file.
    LIBS += -lUser32
    
    This code will only work with Windows.
    
    http://www.amin-ahmadi.com
*/

#include "Windows.h"


bool isDesktopAvailable()
{
    HDESK desktop = OpenDesktop(TEXT("Default"), 0, false, DESKTOP_SWITCHDESKTOP);
    if(desktop)
    {
        if (SwitchDesktop(desktop))
        {
            CloseDesktop(desktop);
            return true;
        }
        else
        {
            CloseDesktop(desktop);
        }
    }

    return false;
}

Comments (0)