switcher.c
/*********************************************************************
$RCSfile: switcher.c $
$Revision: 1.4 $
$Date: 1997/09/09 00:20:54 $
$Author: doomer $
Copyright (c) 1997 John Dumais. All rights reserved.
**********************************************************************
Description
A replacement for the default task manager. We register hot keys
to disable keyboard-driven window navigation.
*********************************************************************/
#include <windows.h>
#include <string.h>
#include <stdio.h>
/*
Function prototypes
*/
BOOL initThisInstance(HANDLE hThisInstance, int howToShow);
BOOL registerClass(HANDLE hThisInstance);
LRESULT APIENTRY winProc(HWND hWnd, UINT message, WPARAM intParam, LPARAM lParam);
/*
Standard window initialization and message pump.
*/
int APIENTRY WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR cmdLine,
int howToShow) {
MSG msg;
if (!initThisInstance(hThisInstance, howToShow)) {
return(FALSE);
}
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(msg.wParam);
}
/*
Create a window
*/
BOOL initThisInstance(HANDLE hThisInstance, int howToShow) {
HWND hWnd;
if (!registerClass(hThisInstance)) {
return(FALSE);
}
hWnd=CreateWindow(
"bogus", // window class name
"bogus", // window title
WS_OVERLAPPEDWINDOW, // window style
CW_USEDEFAULT, // x position
CW_USEDEFAULT, // y position
CW_USEDEFAULT, // width
CW_USEDEFAULT, // height
NULL, // parent window
NULL, // menu
hThisInstance, // who created this window
NULL // creation parameters
);
if (hWnd) {
ShowWindow(hWnd, howToShow);
UpdateWindow(hWnd);
}
return(hWnd != NULL);
}
/*
What's our window going to look like?
*/
BOOL registerClass(HANDLE hThisInstance) {
WNDCLASS wc;
wc.lpszClassName="bogus";
wc.hInstance=hThisInstance;
wc.lpfnWndProc=winProc;
wc.hCursor=LoadCursor(NULL, IDC_ARROW);
wc.hIcon=LoadIcon(NULL, IDI_APPLICATION);
wc.lpszMenuName=NULL;
wc.hbrBackground=(HANDLE)(COLOR_WINDOW + 1);
wc.style=CS_HREDRAW | CS_VREDRAW;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
return(RegisterClass(&wc));
}
/*
Oue event handler
*/
LRESULT APIENTRY winProc(HWND hWnd, UINT message, WPARAM intParam, LPARAM lParam) {
static ATOM ctrlEscAtom, ctrlSpaceAtom, altEscAtom;
static BOOL ctrlEscRegistered, ctrlSpaceRegistered, altEscRegistered;
HDC hdc;
char buffer[2048];
int nChars=0;
PAINTSTRUCT ps;
RECT rect;
switch(message){
/*
When our window is created, but before it is shown,
register hot keys to prevent keyboard window navigation.
*/
case WM_CREATE:
ctrlEscAtom=GlobalAddAtom("veeCtrlEsc");
if(ctrlEscAtom){
if(RegisterHotKey(hWnd, ctrlEscAtom, MOD_CONTROL, VK_ESCAPE)){
ctrlEscRegistered=1;
}
}
ctrlSpaceAtom=GlobalAddAtom("veeCtrlSpace");
if(ctrlSpaceAtom){
if(RegisterHotKey(hWnd, ctrlSpaceAtom, MOD_CONTROL, VK_SPACE)){
ctrlSpaceRegistered=1;
}
}
altEscAtom=GlobalAddAtom("veeAltEsc");
if(altEscAtom){
if(RegisterHotKey(hWnd, altEscAtom, MOD_ALT, VK_ESCAPE)){
altEscRegistered=1;
}
}
break;
/*
Our window is going away. Unregister the hot keys and
give back the atom resources used to identify them.
*/
case WM_DESTROY:
if(ctrlEscRegistered){
UnregisterHotKey(hWnd, ctrlEscAtom);
}
if(ctrlSpaceRegistered){
UnregisterHotKey(hWnd, ctrlSpaceAtom);
}
if(altEscRegistered){
UnregisterHotKey(hWnd, altEscAtom);
}
if(ctrlEscAtom){
GlobalDeleteAtom(ctrlEscAtom);
}
if(ctrlSpaceAtom){
GlobalDeleteAtom(ctrlSpaceAtom);
}
if(altEscAtom){
GlobalDeleteAtom(altEscAtom);
}
break;
/*
Put some statistics on the screen
*/
case WM_PAINT:
memset(buffer, '\0', sizeof(buffer));
nChars=sprintf(buffer, "ctrlEsc: %d\n", ctrlEscRegistered);
nChars += sprintf(buffer+nChars, "ctrlSpace: %d\n", ctrlSpaceRegistered);
sprintf(buffer+nChars, "altEsc: %d", altEscRegistered);
hdc=BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rect);
DrawText(hdc, buffer, -1, &rect, DT_CENTER | DT_VCENTER);
EndPaint(hWnd, &ps);
break;
/*
Eat the hot keys.
*/
case WM_HOTKEY:
break;
default:
return(DefWindowProc(hWnd, message, intParam, lParam));
}
return(0);
}
/*********************************************************************
$Log: switcher.c $
Revision 1.4 1997/09/09 00:20:54 doomer
damn. forgot to save before I checked in.
Revision 1.3 1997/09/09 00:11:50 doomer
documemtation.
Revision 1.2 1997/08/25 00:52:50 doomer
removed superfluous comment.
Revision 1.1 1997/08/17 04:58:20 doomer
Initial revision
*********************************************************************/