3



Usually I develop in Java but now I need to write an app that will block the whole computer's screen every X minutes for Y minutes. It needs to make a break (I want to have a similar app in Windows like in Linux).

So I suggest I need to use C++ and User32.dll to achieve it? Am i right? (I don't want to develop an application in C#). Could anybody give me an idea which methods to use to lock the screen, I'm a newby in WinAPI developing.

Thank you!

gennad
  • 5,335
  • 12
  • 44
  • 47
  • What do you mean "lock" the screen? Why do you want to do this? – David Heffernan Nov 23 '10 at 18:50
  • Well I want to place timer that counts time left until the end of the break and make the whole screen unresponsive to clicks – gennad Nov 23 '10 at 18:57
  • I thought that there were plenty of apps that do this already - why write your own? – David Heffernan Nov 24 '10 at 20:13
  • I would be very grateful if you hint me some open source application with this functional.... – gennad Nov 25 '10 at 19:53
  • 1
    Related question in [.Net](http://stackoverflow.com/questions/11812562/how-to-lock-windows-like-windows-l-from-net) and [VB6](http://stackoverflow.com/questions/11911548/simulate-windowskeyl-in-visual-basic) – Deanna Aug 14 '12 at 08:22

1 Answers1

8

Just link your application to user32.dll and call the LockWorkStation() function directly.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
kwantam
  • 431
  • 2
  • 3
  • Thank you for your reply, very helpful, but are there any variants to do not turn off the screen, just make it unresponsive? – gennad Nov 23 '10 at 19:00
  • Honestly, I'm not sure. You might be able to make a popup window that steals mouse and keyboard focus and is unresponsive until the timeout occurs. – kwantam Nov 23 '10 at 19:03
  • `Rundll32.exe` expects a specific [function signature](http://support.microsoft.com/kb/164787) which `LockWorkStation()` [does not have](http://msdn.microsoft.com/en-us/library/windows/desktop/aa376875(v=vs.85).aspx). You should not mix them. I've removed this from your answer. – Deanna Aug 06 '12 at 10:47