📄 answer.c
字号:
switch (nMessage) {
case WM_INITDIALOG:
replaying = FALSE;
msgMax = 50;
msgTable = (long *) GlobalAllocPtr(GPTR, msgMax * sizeof(long));
if (msgTable == NULL) {
MessageBox(hwnd, rstring(IDS_T_ALLOC_MSG_TABLE_ERR),
NULL, MB_OK | MB_ICONEXCLAMATION);
DestroyWindow(hwnd);
}
hDlgAnswer = hwnd;
scanMessageFile(hwnd);
setIdle: EnableWindow(GetDlgItem(hwnd, IDC_RP_PREV), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_REPLAY), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_REWIND), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_NEXT), answerFile && msgCount > 0);
EnableWindow(GetDlgItem(hwnd, IDC_RP_ERASE), answerFile && answerLen > 0);
EnableWindow(GetDlgItem(hwnd, IDC_RP_RECORD), answerFile != NULL);
EnableWindow(GetDlgItem(hwnd, IDC_RP_SAVE), FALSE);
answerResetFocus(hwnd);
CheckDlgButton(hwnd, IDC_RP_RECORD, answerFile && answerRecord);
if (answerFileName != NULL) {
SetDlgItemText(hwnd, IDC_RP_MSGFILE, answerFileName);
}
if (answerOutFileName != NULL) {
SetDlgItemText(hwnd, IDC_RP_OUTMSGFILE, answerOutFileName);
}
answerClearMessageInfo(hwnd);
currentMessage = -1; // Nothing played yet
buttonPushed = 0;
setMessageCount();
return TRUE;
case WM_CLOSE:
DestroyWindow(hwnd);
return TRUE;
case WM_COMMAND:
switch ((short) WM_COMMAND_ID(wParam)) {
case IDC_RP_PREV:
{
struct in_addr IPaddr;
char hostName[userIdMax];
time_t t;
if (currentMessage > 0) {
currentMessage--;
}
// Update message display
answerPlayPos = msgTable[currentMessage];
if (answerRead(&IPaddr, &t, hostName, &ebuf)) {
setMessageCount();
answerUpdateMessageInfo(hwnd, &t, &IPaddr, hostName);
}
answerPlayPos = msgTable[currentMessage];
EnableWindow(GetDlgItem(hwnd, IDC_RP_PREV), currentMessage > 0);
EnableWindow(GetDlgItem(hwnd, IDC_RP_NEXT), currentMessage < (msgCount - 1));
EnableWindow(GetDlgItem(hwnd, IDC_RP_REPLAY), currentMessage >= 0);
EnableWindow(GetDlgItem(hwnd, IDC_RP_REWIND), TRUE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_ERASE), TRUE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_BROWSE), TRUE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_SAVE), currentMessage >= 0);
answerResetFocus(hwnd);
break;
}
case IDC_RP_NEXT:
{
struct in_addr IPaddr;
char hostName[userIdMax];
time_t t;
if (currentMessage < msgCount) {
currentMessage++;
}
// Update message display
answerPlayPos = msgTable[currentMessage];
if (answerRead(&IPaddr, &t, hostName, &ebuf)) {
setMessageCount();
answerUpdateMessageInfo(hwnd, &t, &IPaddr, hostName);
}
answerPlayPos = msgTable[currentMessage];
EnableWindow(GetDlgItem(hwnd, IDC_RP_PREV), currentMessage > 0);
EnableWindow(GetDlgItem(hwnd, IDC_RP_NEXT), currentMessage < (msgCount - 1));
EnableWindow(GetDlgItem(hwnd, IDC_RP_REPLAY), currentMessage >= 0);
EnableWindow(GetDlgItem(hwnd, IDC_RP_REWIND), TRUE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_ERASE), TRUE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_BROWSE), TRUE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_SAVE), currentMessage >= 0);
answerResetFocus(hwnd);
/* When the user displays the last message in the file, stop
the tray icon's blinking. */
blinkTrayIcon(currentMessage < (msgCount - 1));
break;
}
case IDC_RP_REPLAY:
setMessageCount();
buttonPushed = WM_COMMAND_ID(wParam);
if (obtainOutput(hwndMDIFrame)) {
answerReplay();
answerPlayPos = msgTable[currentMessage];
// Disable controls to prevent mischief while we're playing
EnableWindow(GetDlgItem(hwnd, IDC_RP_PREV), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_NEXT), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_REPLAY), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_SAVE), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_ERASE), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_REWIND), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_BROWSE), FALSE);
replaying = TRUE;
firstPacket = TRUE;
hostShown = hostPrelim = FALSE;
SetTimer(hwnd, 5, 1, NULL);
}
break;
case IDC_RP_ERASE: // Erase all incoming messages
fclose(answerFile);
answerFile = fopen(answerFileName, "w+b");
msgCount = 0;
answerLen = 0;
blinkTrayIcon(FALSE);
// Note fall-through
case IDC_RP_REWIND: // Rewind to the first incoming message
goto setIdle;
case IDC_RP_BROWSE:
{
OPENFILENAME ofn;
char szString[MAX_PATH];
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = rfilter(IDS_T_ANSWER_MESSAGE_FILTER);
ofn.lpstrCustomFilter = NULL;
strcpy(szString, answerFileName);
if (strlen(szString) == 0) {
strcpy(szString, rstring(IDS_T_ANSWER_DEFAULT_FILE_NAME));
}
ofn.lpstrFile = (LPSTR) szString;
ofn.lpstrDefExt = rstring(IDS_T_ANSWER_DEFAULT_EXTENSION);
ofn.nMaxFile = sizeof(szString);
ofn.lpstrInitialDir = NULL;
ofn.lpstrTitle = rstring(IDS_T_ANSWER_OPEN_TITLE);
ofn.Flags = OFN_NOREADONLYRETURN | OFN_HIDEREADONLY | OFN_SHOWHELP;
fileHelpKey = rstring(IDS_HELP_ANSWER);
if (GetOpenFileName((LPOPENFILENAME) &ofn)) {
SetDlgItemText(hwnd, IDC_RP_MSGFILE, szString);
strcpy(answerFileName, szString);
answerClose();
answerOpen();
currentMessage = -1;
scanMessageFile(hwnd);
EnableWindow(GetDlgItem(hwnd, IDC_RP_PREV), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_REWIND), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_REPLAY), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_SAVE), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_NEXT), answerFile && msgCount > 0);
EnableWindow(GetDlgItem(hwnd, IDC_RP_ERASE), answerFile && answerLen > 0);
EnableWindow(GetDlgItem(hwnd, IDC_RP_RECORD), answerFile != NULL);
answerClearMessageInfo(hwnd);
setMessageCount();
answerResetFocus(hwnd);
}
}
break;
case IDC_RP_CLEAR_INCOMING: // Clear incoming message file, disabling answering machine
SetDlgItemText(hwnd, IDC_RP_MSGFILE, "");
strcpy(answerFileName, "");
answerClose();
currentMessage = -1;
scanMessageFile(hwnd);
EnableWindow(GetDlgItem(hwnd, IDC_RP_PREV), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_REWIND), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_REPLAY), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_NEXT), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_ERASE), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_RECORD), FALSE);
EnableWindow(GetDlgItem(hwnd, IDC_RP_SAVE), FALSE);
answerClearMessageInfo(hwnd);
setMessageCount();
answerResetFocus(hwnd);
blinkTrayIcon(FALSE);
break;
case IDC_RP_BROWSE_OUTGOING:
{
OPENFILENAME ofn;
char szString[MAX_PATH];
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = rfilter(IDS_T_SOUND_FILE_FILTER);
ofn.lpstrCustomFilter = NULL;
strcpy(szString, answerOutFileName);
ofn.lpstrFile = (LPSTR) szString;
ofn.nMaxFile = sizeof(szString);
ofn.lpstrInitialDir = NULL;
ofn.lpstrTitle = rstring(IDS_T_ANSWER_OUTOPEN_TITLE);
ofn.Flags = OFN_SHOWHELP;
fileHelpKey = rstring(IDS_HELP_ANSWER);
if (GetOpenFileName((LPOPENFILENAME) &ofn)) {
SetDlgItemText(hwnd, IDC_RP_OUTMSGFILE, szString);
strcpy(answerOutFileName, szString);
}
}
break;
case IDC_RP_CLEAR_OUTGOING:
strcpy(answerOutFileName, "");
SetDlgItemText(hwnd, IDC_RP_OUTMSGFILE, "");
break;
case IDC_RP_RECORD:
answerRecord = IsDlgButtonChecked(hwnd, IDC_RP_RECORD);
break;
case IDC_RP_CALL_IP:
{ char s[256];
char *cp;
GetDlgItemText(hwnd, IDC_RP_CALL_IP, s, sizeof s);
cp = strrchr(s, ' ');
if (cp != NULL) {
newConnection(hwndMDIFrame, NULL, cp + 1);
}
}
break;
case IDC_RP_CALL_DOMAIN_NAME:
{ char s[256];
char *cp;
GetDlgItemText(hwnd, IDC_RP_CALL_DOMAIN_NAME, s, sizeof s);
cp = strrchr(s, ' ');
if (cp != NULL) {
newConnection(hwndMDIFrame, NULL, cp + 1);
}
}
break;
case IDC_RP_LOOK_UP_USER:
{ char s[256];
char *cp;
GetDlgItemText(hwnd, IDC_RP_LOOK_UP_USER, s, sizeof s);
cp = strrchr(s, ' ');
if (cp != NULL) {
lwl_ask_set_target(cp + 1);
}
}
break;
case IDC_RP_SAVE:
{
OPENFILENAME ofn;
char szWaveMessage[MAX_PATH];
struct in_addr IPaddr;
char hostName[userIdMax];
time_t t;
long sfp;
int ateof = FALSE;
DWORD write_pos;
char szError[200];
HMMIO hmmioOut;
MMIOINFO mmioinfoOut;
MMCKINFO ckOutRIFF;
MMCKINFO ckOut;
LPSTR pcmdata;
DWORD dwPCMBytes;
WAVEFORMATEX pwf;
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = rfilter(IDS_T_WAVE_FILE_FILTER);
ofn.lpstrCustomFilter = NULL;
szWaveMessage[0] = '\0';
ofn.lpstrFile = (LPSTR) szWaveMessage;
ofn.nMaxFile = sizeof(szWaveMessage);
ofn.lpstrInitialDir = NULL;
ofn.lpstrTitle = rstring(IDS_T_ANSWER_SAVE_TITLE);
ofn.Flags = OFN_SHOWHELP;
fileHelpKey = rstring(IDS_HELP_ANSWER);
if (GetOpenFileName((LPOPENFILENAME) &ofn)) {
if (!strchr(szWaveMessage, '.')) {
strcat(szWaveMessage, ".wav");
}
SetCursor(LoadCursor(NULL, IDC_WAIT));
hmmioOut = mmioOpen(szWaveMessage, NULL,
MMIO_ALLOCBUF | MMIO_WRITE | MMIO_CREATE);
if (!hmmioOut) {
sprintf(szError,rstring(IDS_T_OPEN_WAVE_FILE_ERR), szWaveMessage);
MessageBox(NULL, szError, NULL, MB_OK | MB_ICONEXCLAMATION);
break;
}
// Create the output file RIFF chunk of form type WAVE.
ckOutRIFF.fccType = mmioFOURCC('W', 'A', 'V', 'E');
ckOutRIFF.cksize = 0;
if (mmioCreateChunk(hmmioOut, &ckOutRIFF, MMIO_CREATERIFF)
!= MMSYSERR_NOERROR) {
MessageBox(NULL, rstring(IDS_T_WRITE_FILE_ERR), NULL, MB_OK | MB_ICONEXCLAMATION);
mmioClose(hmmioOut, 0);
break;
}
// Initialise the WAVEFORMATEX structure
pwf.nChannels = audioChannels;
pwf.nSamplesPerSec = samplesPerSecond;
pwf.nAvgBytesPerSec = bytesPerSecond;
pwf.nBlockAlign = sampleAlignment;
pwf.wBitsPerSample = bitsPerSample;
pwf.wFormatTag = WAVE_FORMAT_PCM;
pwf.cbSize = 0;
// Create the fmt chunk
ckOut.ckid = mmioFOURCC('f', 'm', 't', ' ');
ckOut.cksize = sizeof(pwf);
if (mmioCreateChunk(hmmioOut, &ckOut, 0) != MMSYSERR_NOERROR) {
MessageBox(NULL, rstring(IDS_T_WRITE_FILE_ERR), NULL, MB_OK | MB_ICONEXCLAMATION);
mmioClose(hmmioOut, 0);
break;
}
// Write the WAVEFORMATEX structure to the fmt chunk.
if (mmioWrite(hmmioOut, (HPSTR) &pwf, sizeof(pwf))
!= sizeof(pwf)) {
MessageBox(NULL, rstring(IDS_T_WRITE_FILE_ERR), NULL, MB_OK | MB_ICONEXCLAMATION);
mmioClose(hmmioOut, 0);
break;
}
// Ascend out of the fmt chunk, back into the RIFF chunk.
if (mmioAscend(hmmioOut, &ckOut, 0) != MMSYSERR_NOERROR) {
MessageBox(NULL, rstring(IDS_T_WRITE_FILE_ERR), NULL, MB_OK | MB_ICONEXCLAMATION);
mmioClose(hmmioOut, 0);
break;
}
// Create the data chunk that holds the waveform samples.
ckOut.ckid = mmioFOURCC('d', 'a', 't', 'a');
ckOut.cksize = 0;
if (mmioCreateChunk(hmmioOut, &ckOut, 0) != MMSYSERR_NOERROR) {
MessageBox(NULL, rstring(IDS_T_WRITE_FILE_ERR), NULL, MB_OK | MB_ICONEXCLAMATION);
mmioClose(hmmioOut, 0);
break;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -