![]() |
General Reading »
Hardware & System »
Hardware
Beginner
License: The Code Project Open License (CPOL)
Turn off laptop monitor and lock the systemBy Weiwei.Fangsimple code to replace the win+L hotkey |
C++ (VC6, VC7, VC7.1, VC8.0), C, Windows (Win2K, WinXP, Vista), Win32, Visual Studio, Dev, Design, SysAdmin
|
||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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).
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 SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, (LPARAM) 2);
Second, use LockWorkStation function to lock the system.
LockWorkStation();
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 0x0500This 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.| You must Sign In to use this message board. | |||||||||||||||
|
|||||||||||||||
|
|||||||||||||||
|
|||||||||||||||
|
|||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 25 Jul 2008 Editor: |
Copyright 2008 by Weiwei.Fang Everything else Copyright © CodeProject, 1999-2009 Web12 | Advertise on the Code Project |