How to detect Windows is locked (Win+L or locked by screensaver)? Is it possible?
There is no documented way to check if the session is locked. There is however a way to detect that the session is getting locked. Use WTSRegisterSessionNotification(), you'll get a WM_WTSSESSION_CHANGE message with the WTS_SESSION_LOCK value when the workstation is being locked.
If you are planning to do this from a service then be sure to google "session 0 isolation" to find out why that doesn't work.