Click here to Skip to main content
13,354,132 members (55,562 online)
Click here to Skip to main content
Add your own
alternative version


18 bookmarked
Posted 25 Jul 2008

Turn off laptop monitor and lock the system

, 25 Jul 2008
Rate this:
Please Sign up or sign in to vote.
simple code to replace the win+L hotkey


I use the Thinkpad laptop for my research work. Usually, I keep it working in the night for the simulation work. Therefore, when I wake up at the next morning, I can analyze the results immediately. I need to lock the WinXP system and turn off the monitor when I leave the laptop. Then I write this program to help me. It is more convenient to use than the traditional way (Win+L hotkey to lock the system and turn off monitor through power schemes).

Code explanation

The code is very simple.

First, turn off the monitor by using SendMessage function. You can find more introduction about it from this article.

// Turn off monitor
Sleep(500); // Eliminate user's interaction for 500 ms

Second, use LockWorkStation function to lock the system.


Third, the LockWorkStation function requires Windows Vista, Windows XP, or Windows 2000 Professional. To compile the program successfully, we need to add the following macro in the StdAfx.h.

#define _WIN32_WINNT 0x0500
This program is very simple yet very useful. It keeps your task running on the laptop while turns off the monitor for saving energy and protects the laptop from unauthorized use.



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Beihang University
China China

You may also be interested in...


Comments and Discussions

GeneralRemove intermediate files from source archive Pin
MrARSoft27-Jul-08 20:14
memberMrARSoft27-Jul-08 20:14 
GeneralYou shouldn't broadcast the monitor power message. [modified] Pin
Leo Davidson26-Jul-08 22:42
memberLeo Davidson26-Jul-08 22:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 26 Jul 2008
Article Copyright 2008 by Weiwei.Fang
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid