728x90
#include <iostream>
#include <memory> 
#include <windows.h>
#include <winuser.h>

bool IsScreenLocked()
{
	HDESK desktopHandle = OpenInputDesktop(0, false, DESKTOP_SWITCHDESKTOP);
	if (desktopHandle == 0)
	{
		desktopHandle = OpenDesktopA("Default", 0, false, DESKTOP_SWITCHDESKTOP);
	}
	if (desktopHandle != 0)
	{
		if (SwitchDesktop(desktopHandle))
		{
			CloseDesktop(desktopHandle);
		}
		else
		{
			CloseDesktop(desktopHandle);
			return true;
		}
	} return false;
}

bool IsScreenSaverRunning()
{
	int isRunning = 0;
	if (!SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, &isRunning, 0))
	{
		return false;
	}
	if (isRunning)
	{
		return true;
	}
	return false;
}

int main()
{
	while (true)
	{
		if (IsScreenLocked())
		{
			printf("LockScreen : true");
		}
		else
		{
			printf("LockScreen : false");
		}

		if (IsScreenSaverRunning())
		{
			printf("ScreenSaver : true");
		}
		else
		{
			printf("ScreenSaver : false");
		}

		Sleep(100);
	}
}

 

참조 : https://icodebroker.tistory.com/9207

728x90

+ Recent posts