Thursday, June 12, 2008

Are you lazy?? Then this one is for you !!

Are you so lazy enough that you need a short cut for locking your system. The contemporary way is to press Ctrl+Alt+Del and choose "lock computer" or more simpler "Win key + L". Well now I am saying a more simpler one ;)
Double click an executable on your desktop and you are done.

I tried to upload an exe for you all but alas..blogger stopped me from uploading..So life is not so easy..But still..you can invest some time now and be lazy later, right? So, i can tell you the steps to get your exe done.. The whole magic is done by just a single Windows API "LockWorkStation() ". So if you know about this already, then you already know this stuff!!

For those who still think they want to know..Here we go!
1. Firstly create a Win32 application.
2. In the InitInstance, call LockWorkStation()
3. Call PostQuitMessage() to exit your application. That should do.

Double click your executable and your system is locked..


Code snippet:
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
return FALSE;
}

//I dont want any window to be seen by the user, so commenting it out
//ShowWindow(hWnd, nCmdShow);
//UpdateWindow(hWnd);

//Lock your workstation
LockWorkStation();

//Quit your application
PostQuitMessage(1);

return TRUE;
}

LockWorkStation() is defined in winuser.h and needs user32.lib library.
For details: http://msdn.microsoft.com/en-us/library/aa376875(VS.85).aspx

Ok so thats all for today!