home *** CD-ROM | disk | FTP | other *** search
- /*
- * Resident segment for KEYMAP
- * Copyright (c) 1991 by William S. Hall and Peter Belew
- */
-
- #define NOCOMM
- #define NOKANJI
- #define NOATOM
- #define NOSOUND
- #include <windows.h>
- #include <string.h>
- #include "winutils.h"
- /* all global variables are declared in this module */
- #define EXTERN
- #include "keymap.h"
-
- /* local functions */
- static void NEAR ResetKeys(HWND hWnd);
-
- /* Entry point for program */
- int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance,
- LPSTR lpszCmdLine, int cmdShow)
- {
-
- MSG msg;
-
- /* If initialization is not successful then exit */
- if (!InitProgram(hInstance,hPrevInstance,lpszCmdLine,cmdShow))
- return FALSE;
-
- /* Retrieve messages from Windows */
- while (GetMessage(&msg, NULL, 0, 0)) {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return msg.wParam; /* exit program */
- }
-
- /* All messages are processed here */
- long FAR PASCAL MainWndProc(register HWND hWnd, unsigned message,
- register WORD wParam,LONG lParam)
- {
-
- switch(message) {
-
- case WM_WININICHANGE:
- if ((lstrcmpi((LPSTR)lParam, "intl") == 0))
- ResetKeys(hWnd);
- break;
-
- case WM_COMMAND:
- switch(wParam) {
- case IDM_ABOUT: /* show ego box */
- OpenDlgBox(hWnd, AboutDlg, DT_ABOUT);
- break;
- case IDM_CLEAR: /* clear practice window */
- SetWindowText(hEdit, "");
- break;
- case IDM_GRAY: /* switch key color */
- case IDM_WHITE:
- if (KeyColor != wParam) {
- HMENU hMenu = GetMenu(hWnd);
- CheckMenuItem(hMenu,KeyColor,MF_UNCHECKED);
- KeyColor = wParam;
- CheckMenuItem(hMenu,wParam,MF_CHECKED);
- ResetKeys(hWnd);
- }
- break;
- }
- break;
-
- case WM_SETFOCUS: /* keep the focus on the edit box */
- if (IsWindow(hEdit))
- SetFocus(hEdit);
- break;
-
- case WM_CREATE: /* create the key windows */
- MainWndCreate(hWnd);
- break;
-
- case WM_DESTROY: /* leaving */
- PostQuitMessage(0);
- break;
-
- case WM_NCDESTROY: /* final cleanup, fall thru */
- if (fpEditWndProc)
- FreeProcInstance(fpEditWndProc);
- if (fpLocalEditWndProc)
- FreeProcInstance(fpLocalEditWndProc);
-
- default:
- return (long)DefWindowProc(hWnd,message,wParam,lParam);
- break;
- }
- return(0L);
- }
-
- /* reset the keys */
- static void NEAR ResetKeys(HWND hWnd)
- {
- register int i;
- register hctl;
- char buf[80];
- HCURSOR hCursor;
-
- SetCapture(hWnd); /* we now own the mouse cursor */
- hCursor = SetCursor(LoadCursor(NULL,IDC_WAIT)); /* hourglass */
- for (i = 0; i < MAXKEYS; i++) { /* redraw the keys */
- hctl = GetDlgItem(hWnd, kdata[i].scancode);
- ChildCreate(hctl);
- InvalidateRect(hctl, NULL, TRUE);
- }
- LoadString(hInst,IDS_TITLE,buf,sizeof(buf)); /* redraw title */
- SetWindowText(hWnd, buf);
- ModifyWindowsTitle(hWnd); /* show the current keyboard */
- SetCursor(hCursor); /* reset mouse cursor */
- ReleaseCapture(); /* release control */
-
- }
-
- /* Read the keyboard's name from Setup.inf. Lot's of embedded
- strings here, but they are universal in Windows and are
- not language dependent.
- */
- #define MAXPATHLEN 144
- #define MAXFILENAMELEN 12
- void FAR ModifyWindowsTitle(HWND hWnd)
- {
- char kbdll[20];
- char keystr[512];
- char winpath[MAXPATHLEN + MAXFILENAMELEN + 2];
- char *keyptr;
- register int len;
- char kbstring[80];
- char title[256];
- char *result;
-
- /* find out where SETUP.INF is located and add in its name */
- len = GetSystemDirectory(winpath, sizeof(winpath));
- if ((len == 0) || (len > MAXPATHLEN))
- return; /* error */
- if (winpath[len - 1] != '\\') /* are we in a subdirectory? */
- lstrcat(winpath, "\\");
- lstrcat(winpath, "SETUP.INF");
-
- /* now read in the keyboard dll from system.ini */
- len = GetPrivateProfileString("keyboard", "keyboard.dll",
- "", kbdll, sizeof(kbdll),
- "system.ini");
- if (len == 0)
- strcpy(keystr, "nodll"); /* none in use */
- else /* found one, so enumerate all possibilities */
- GetPrivateProfileString("keyboard.tables", NULL, "",
- keystr, sizeof(keystr), winpath);
- keyptr = keystr;
- while (len = strlen(keyptr)) { /* loop thru strings until target found */
- GetPrivateProfileString("keyboard.tables", keyptr, "",
- kbstring,sizeof(kbstring),winpath);
- if (result = strstr(kbstring, kbdll)) {
- strtok(kbstring, "\""); /* found one, parse and add to tile */
- GetWindowText(hWnd, title, sizeof(title));
- strcat(title, strtok(NULL, "\""));
- SetWindowText(hWnd, title);
- break;
- }
- keyptr += len + 1;
- }
- }
-
- /* show ego box */
- BOOL FAR PASCAL AboutDlg(HWND hDlg, unsigned message, WORD wParam, LONG lParam)
- {
- switch(message) {
-
- case WM_INITDIALOG:
- break;
-
- case WM_COMMAND:
- switch(wParam) {
- case IDOK:
- case IDCANCEL:
- EndDialog(hDlg, TRUE);
- break;
- default:
- return FALSE;
- }
- break;
-
- default:
- return FALSE;
- }
- return TRUE;
- }
-