home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windoware
/
WINDOWARE_1_6.iso
/
winutil
/
adg_4_6
/
echo.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-21
|
9KB
|
287 lines
/****************************************************************************
Module name: Echo.C
Programmer : Jeffrey M. Richter.
*****************************************************************************/
#include "..\nowindws.h"
#undef NOCOLOR
#undef NOCTLMGR
#undef NOHELP
#undef NOKERNEL
#undef NOMB
#undef NOMEMMGR
#undef NOMENUS
#undef NOMSG
#undef NOSHOWWINDOW
#undef NOUSER
#undef NOVIRTUALKEYCODES
#undef NOWH
#undef NOWINMESSAGES
#undef NOWINSTYLES
#include <windows.h>
#include "Echo.h"
#include "Recorder.h"
//****************************************************************************
char _szAppName[] = "Echo";
HANDLE _hInstance = NULL; // Our instance handle.
HWND _hWndApp = NULL; // Main application's window handle.
LONG FAR PASCAL AppWndProc (HWND hWnd, WORD wMsg, WORD wParam, LONG lParam);
BOOL FAR PASCAL AboutProc (HWND hDlg, WORD wMsg, WORD wParam, LONG lParam);
DWORD FAR PASCAL MsgFilterHookFunc (int nCode, WORD wParam, LPMSG lpMsg);
int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) {
WNDCLASS WndClass;
MSG msg;
_hInstance = hInstance;
WndClass.style = 0;
WndClass.lpfnWndProc = AppWndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(hInstance, _szAppName);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = COLOR_WINDOW + 1;
WndClass.lpszMenuName = _szAppName;
WndClass.lpszClassName = _szAppName;
RegisterClass(&WndClass);
// Create application window, store in global variable.
_hWndApp = CreateWindow(_szAppName, _szAppName, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, SW_SHOW, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, 0);
if (_hWndApp == NULL) return(0);
ShowWindow(_hWndApp, nCmdShow);
UpdateWindow(_hWndApp);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(0);
}
// Window defined message sent by the Recorder function in the RECORDER.C
// DLL when recording or playing of events is stopped.
#define USER_RECORDER (WM_USER + 0)
LONG FAR PASCAL AppWndProc (HWND hWnd, WORD wMsg, WORD wParam, LONG lParam) {
static BOOL fRecording = FALSE, fPlaying = FALSE;
static GLOBALHANDLE hMacro; // Global handle containing recorded events.
BOOL fCallDefProc = FALSE;
LONG lResult = 0;
FARPROC fpMsgFilter, fpDlgProc;
RECRESULT RecResult = REC_OK;
char *szRecMsg = NULL;
switch (wMsg) {
case WM_DESTROY:
// Close the Windows Help Engine.
WinHelp(hWnd, NULL, HELP_QUIT, NULL);
PostQuitMessage(0);
break;
case USER_RECORDER:
// Message sent when recording or playing is stopped.
if (wParam == 0) { // Playing stopped.
fPlaying = FALSE;
if ((RECRESULT) lParam == REC_SYSMODALON)
MessageBox(hWnd, "System Modal Dialog Box - Playing Halted",
_szAppName, MB_SYSTEMMODAL | MB_ICONHAND | MB_OK);
break;
}
// Recording stopped.
// wParam = GLOBALHANDLE of block, lParam = RECRESULT.
fRecording = FALSE;
hMacro = wParam;
if ((RECRESULT) lParam == REC_TOOMANY)
MessageBox(NULL, "Out of memory", _szAppName,
MB_SYSTEMMODAL | MB_ICONHAND | MB_OK);
if ((RECRESULT) lParam == REC_SYSMODALON)
MessageBox(hWnd, "System Modal Dialog Box - Recording Halted",
_szAppName, MB_SYSTEMMODAL | MB_ICONHAND | MB_OK);
break;
case WM_INITMENU:
// User is working with the menu, enable/disable options.
EnableMenuItem(GetMenu(hWnd), IDM_STARTRECORD,
MF_BYCOMMAND |
((fRecording || fPlaying) ? MF_GRAYED : MF_ENABLED));
EnableMenuItem(GetMenu(hWnd), IDM_STOPRECORD,
MF_BYCOMMAND | (fRecording ? MF_ENABLED : MF_GRAYED));
EnableMenuItem(GetMenu(hWnd), IDM_STARTPLAYBACK,
MF_BYCOMMAND |
((fRecording || fPlaying || hMacro == NULL)
? MF_GRAYED : MF_ENABLED));
break;
case WM_COMMAND:
switch (wParam) {
case IDM_EXIT:
SendMessage(hWnd, WM_CLOSE, 0, 0);
break;
case IDM_ABOUT:
// Create procedural-instance for task-specific filter function.
fpMsgFilter =
MakeProcInstance((FARPROC) MsgFilterHookFunc, _hInstance);
SetWindowsHook(WH_MSGFILTER, fpMsgFilter);
fpDlgProc = MakeProcInstance(AboutProc, _hInstance);
DialogBox(_hInstance, "About", hWnd, fpDlgProc);
FreeProcInstance(fpDlgProc);
// Remove the filter function from the chain.
UnhookWindowsHook(WH_MSGFILTER, fpMsgFilter);
FreeProcInstance(fpMsgFilter);
break;
case IDM_STARTRECORD:
// If a macro was already recorded, free it.
if (hMacro != NULL) GlobalFree(hMacro);
fRecording = TRUE;
// Last parameter is handle to this window and message that
// should be sent when recording is stopped.
RecResult = Recorder(RM_STARTRECORD, 0, MAKELONG(hWnd, USER_RECORDER));
break;
case IDM_STOPRECORD:
RecResult = Recorder(RM_STOPRECORD, 0, 0);
break;
case IDM_STARTPLAYBACK:
fPlaying = TRUE;
// Last parameter is handle to this window and message that
// should be sent when playing is stopped.
RecResult = Recorder(RM_STARTPLAY, hMacro, MAKELONG(hWnd, USER_RECORDER));
break;
default:
break;
}
// Inform user if an error occurred with the recorder.
switch (RecResult) {
case REC_ACTIVE:
szRecMsg = "Recorder already recording/playing.";
break;
case REC_INACTIVE:
szRecMsg = "Recorder already stopped.";
break;
case REC_NOMEMORY:
szRecMsg = "Insufficient memory to start recording.";
break;
case REC_NOEVENTS:
szRecMsg = "No events to playback.";
break;
}
if (szRecMsg != NULL)
MessageBox(hWnd, szRecMsg, _szAppName,
MB_OK | MB_ICONINFORMATION);
break;
default:
fCallDefProc = TRUE; break;
}
if (fCallDefProc)
lResult = DefWindowProc(hWnd, wMsg, wParam, lParam);
return(lResult);
}
// ***************************************************************************
static FARPROC _fnNextMsgFilterHookFunc = NULL;
DWORD FAR PASCAL MsgFilterHookFunc (int nCode, WORD wParam, LPMSG lpMsg) {
BOOL fCallDefProc = FALSE;
DWORD dwResult = 0;
switch (nCode) {
case MSGF_DIALOGBOX:
// Message is for the About dialog box because we know that
// this is the only dialog box created by this application.
if (lpMsg->message != WM_KEYDOWN || lpMsg->wParam != VK_F1) {
fCallDefProc = TRUE;
break;
}
// Message is WM_KEYDOWN and key is the F1 key, display help.
WinHelp(_hWndApp, NULL, HELP_HELPONHELP, NULL);
dwResult = 1; // Tell Windows we processed the message.
break;
case MSGF_MENU:
case MSGF_SCROLLBAR:
case MSGF_NEXTWINDOW:
default:
fCallDefProc = TRUE;
break;
}
if ((nCode < 0) || (fCallDefProc && (_fnNextMsgFilterHookFunc != NULL)))
dwResult = DefHookProc(nCode, wParam, (LONG) lpMsg,
&_fnNextMsgFilterHookFunc);
return (dwResult);
}
// ***************************************************************************
// This function processess all messages sent to the About dialog box.
BOOL FAR PASCAL AboutProc (HWND hDlg, WORD wMsg, WORD wParam, LONG lParam) {
BOOL fProcessed = TRUE;
char szBuffer[100];
switch (wMsg) {
case WM_INITDIALOG:
// Set version static window to have date and time of compilation.
wsprintf(szBuffer, "%s at %s", (LPSTR) __DATE__, (LPSTR) __TIME__);
SetWindowText(GetDlgItem(hDlg, ID_VERSION), szBuffer);
break;
case WM_COMMAND:
switch (wParam) {
case IDOK: case IDCANCEL:
if (HIWORD(lParam) == BN_CLICKED)
EndDialog(hDlg, wParam);
break;
default:
break;
}
break;
default:
fProcessed = FALSE; break;
}
return(fProcessed);
}