用C++判断Windows是否锁屏
点击查看代码
#include "windows.h"
#include "Windows.h"
#include "Wtsapi32.h"
#include <tchar.h>
#pragma comment(lib, "WtsApi32.lib")
using namespace std;
typedef HDESK(WINAPI *PFNOPENDESKTOP)(LPSTR, DWORD, BOOL, ACCESS_MASK);
typedef BOOL(WINAPI *PFNCLOSEDESKTOP)(HDESK);
typedef BOOL(WINAPI *PFNSWITCHDESKTOP)(HDESK);
bool DLL_isScreenLocked()
{
BOOL bLocked = FALSE;
static HMODULE hUser32 = LoadLibrary(_T("user32.dll"));
if (hUser32)
{
static PFNOPENDESKTOP fnOpenDesktop = (PFNOPENDESKTOP)GetProcAddress(hUser32, "OpenDesktopA");
static PFNCLOSEDESKTOP fnCloseDesktop = (PFNCLOSEDESKTOP)GetProcAddress(hUser32, "CloseDesktop");
static PFNSWITCHDESKTOP fnSwitchDesktop = (PFNSWITCHDESKTOP)GetProcAddress(hUser32, "SwitchDesktop");
if (fnOpenDesktop && fnCloseDesktop && fnSwitchDesktop)
{
HDESK hDesk = fnOpenDesktop("Default", 0, FALSE, DESKTOP_SWITCHDESKTOP);
if (hDesk)
{
bLocked = !fnSwitchDesktop(hDesk);
fnCloseDesktop(hDesk);
}
}
}
if (bLocked == FALSE)
{
return false;
}
else
{
return true;
}
}
https://stackoverflow.com/questions/29326685/c-check-if-computer-is-locked/32115698#32115698