C++ (Qt)#define _WIN32_WINNT 0x0500#define WINVER 0x0500 #include <windows.h> #include <cstdio> #pragma comment( lib, "user32.lib" ) int main(){ // Lock the workstation. if( !LockWorkStation() ) printf ("LockWorkStation failed with %d\n", GetLastError()); return 0;}
QLibrary myLib("./user32"); myLib.load(); myLib.loadHints(); if (!myLib.isLoaded()) exit(0); typedef void (*MyPrototype)(); MyPrototype myFunction = (MyPrototype) myLib.resolve("LockWorkStation"); // фун-я блокировки экрана typedef bool (*MyPrototype2)(HWND,DWORD); MyPrototype2 WTSRegisterSessionNotification = (MyPrototype2) myLib.resolve("WTSRegisterSessionNotification"); if (!WTSRegisterSessionNotification(GetDesktopWindow(),NOTIFY_FOR_THIS_SESSION)) qDebug()<<"no"; else qDebug()<<"yes";
LRESULT CALLBACK WindowProc( HWND hWnd, // handle to window UINT Msg, // WM_WTSSESSION_CHANGE WPARAM wParam, // session state change event LPARAM lParam // session ID);