Click here to Skip to main content
15,894,180 members
Articles / Programming Languages / Visual Basic

Lock Windows Desktop

Rate me:
Please Sign up or sign in to vote.
4.84/5 (160 votes)
3 May 20059 min read 1.5M   63.8K   445  
Restricting Windows access by hiding desktop windows and disabling special keys.
#include  <windows.h>

HWND	hSASWnd;
WNDPROC	OldSASProc;

//////////////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK SASWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	if (uMsg == WM_HOTKEY)
	{
		// Ctrl+Alt+Del
		if (lParam == MAKELONG(MOD_CONTROL | MOD_ALT, VK_DELETE))
			return 1;

		// Ctrl+Shift+Esc
		if (lParam == MAKELONG(MOD_CONTROL | MOD_SHIFT, VK_ESCAPE))
			return 1;
	}

	return CallWindowProc(OldSASProc, hWnd, uMsg, wParam, lParam);
}


///////////////////////////////////////////////////////////////////////////
BOOL WINAPI DllMain(HINSTANCE hInstDll, DWORD fdwReason, LPVOID lpReserved)
{
	switch(fdwReason)
	{
    case DLL_PROCESS_ATTACH:
		 hSASWnd = FindWindow(TEXT("SAS Window class"), TEXT("SAS window"));

		 if (hSASWnd)
			 OldSASProc = (WNDPROC)SetWindowLong(hSASWnd, GWL_WNDPROC, (LONG)SASWindowProc);
		 break;

    case DLL_PROCESS_DETACH:
         if (hSASWnd)
			 SetWindowLong(hSASWnd, GWL_WNDPROC, (LONG)OldSASProc);
		 break;
	}
    
	return TRUE;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Portugal Portugal
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions