可以直接调用windows api:
#include <Windows.h>
#define MONITOR_ON -1
#define MONITOR_OFF 2
#define MONITOR_STANBY 1
int main()
{
//锁屏
LockWorkStation();
//息屏
PostMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, MONITOR_OFF);
return 0;
}
有关锁屏函数LockWorkStation
的介绍:https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-lockworkstation ;
有关息屏使用的函数PostMessage
介绍:https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-postmessagew 。