📄 comdial.c
字号:
//---------------------------------------------------------------------------
//
// Module: comdial.c
//
// Purpose:
// The sample application demonstrates communications
// in Windows95.
//
// Description of functions:
// Descriptions are contained in the function headers.
//
//---------------------------------------------------------------------------
//
// Written by Charles Mirho.
// Copyright (c) 1996 Charles Mirho. All Rights Reserved.
//
//---------------------------------------------------------------------------
#include "tty.h"
#include "resource.h"
#include "comdial.h"
HINSTANCE ghInst; //global instance handle, for now.
PTTYINFO pTTYInfo;
extern MYTAPI mytapi;
HWND hTTYWnd;
#if !defined(_WIN32)
#include <ver.h>
#endif
// Windows NT defines APIENTRY, but 3.x doesn't
#if !defined (APIENTRY)
#define APIENTRY far pascal
#endif
// Windows 3.x uses a FARPROC for dialogs
#if !defined(_WIN32)
#define DLGPROC FARPROC
#endif
//
// FUNCTION: WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
//
// PURPOSE: calls initialization function, processes message loop
//
int APIENTRY WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
MSG msg;
BOOL bOldState = FALSE;
LONG lrc;
// Other instances of app running?
if (!hPrevInstance) {
// Initialize shared things
if (!InitApplication(hInstance)) {
return (FALSE); // Exits if unable to initialize
}
}
if (NULL == (hTTYWnd = InitInstance( hInstance, nCmdShow )))
return ( FALSE ) ;
ghInst = hInstance;
lrc = telephonyInitialize(hTTYWnd, ghInst);
if (lrc)
return FALSE;
while (GetMessage(&msg, NULL, 0, 0)) {
if (!TranslateAccelerator (msg.hwnd, ghAccel, &msg)) {
TranslateMessage(&msg);// Translates virtual key codes
DispatchMessage(&msg); // Dispatches message to window
}
} /* end while (not a quit message) */
telephonyShutdown();
// Returns the value from PostQuitMessage
return (msg.wParam);
// This will prevent 'unused formal parameter' warnings
lpCmdLine;
}
//---------------------------------------------------------------------------
// BOOL NEAR InitApplication( HANDLE hInstance )
//
// Description:
// First time initialization stuff. This registers information
// such as window classes.
//
// Parameters:
// HANDLE hInstance
// Handle to this instance of the application.
//
//---------------------------------------------------------------------------
BOOL NEAR InitApplication( HANDLE hInstance )
{
WNDCLASS wndclass ;
// register tty window class
wndclass.style = 0 ;
wndclass.lpfnWndProc = TTYWndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = sizeof( DWORD ) ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = NULL;
wndclass.hCursor = LoadCursor( NULL, IDC_ARROW ) ;
wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1) ;
wndclass.lpszMenuName = MAKEINTRESOURCE( IDR_MENU1) ;
wndclass.lpszClassName = gszTTYClass ;
return( RegisterClass( &wndclass ) ) ;
} // end of InitApplication()
//---------------------------------------------------------------------------
// HWND NEAR InitInstance( HANDLE hInstance, int nCmdShow )
//
// Description:
// Initializes instance specific information.
//
// Parameters:
// HANDLE hInstance
// Handle to instance
//
// int nCmdShow
// How do we show the window?
//
//---------------------------------------------------------------------------
HWND NEAR InitInstance( HANDLE hInstance, int nCmdShow )
{
HWND hTTYWnd ;
// create the TTY window
hTTYWnd = CreateWindow( gszTTYClass, gszAppName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL ) ;
if (NULL == hTTYWnd)
return ( NULL ) ;
ShowWindow( hTTYWnd, nCmdShow ) ;
UpdateWindow( hTTYWnd ) ;
return ( hTTYWnd ) ;
} // end of InitInstance()
//---------------------------------------------------------------------------
// LRESULT FAR PASCAL TTYWndProc( HWND hWnd, UINT uMsg,
// WPARAM wParam, LPARAM lParam )
//
// Description:
// This is the TTY Window Proc. This handles ALL messages
// to the tty window.
//
// Parameters:
// As documented for Window procedures.
//
//---------------------------------------------------------------------------
LRESULT FAR PASCAL TTYWndProc( HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam )
{
LONG lrc;
char name[50];
switch (uMsg)
{
case MM_WOM_DONE:
/* Unprepare the header */
waveOutUnprepareHeader((HWAVEOUT)wParam,(LPWAVEHDR)lParam,
sizeof(WAVEHDR));
waveOutClose((HWAVEOUT)wParam); /* close wave device */
free (((LPWAVEHDR)lParam)->lpData); /* free the wave data */
free ((LPWAVEHDR)lParam); /* free the header */
if (mytapi.iPlayState == PLAYSTATE_PLAYBACK) {
if (mytapi.nPlayCnt < mytapi.nMsgCnt) {
mytapi.nPlayCnt++;
wsprintf (name, "msg-%d.wav", mytapi.nPlayCnt);
mytapi.h_waveout=playSound (mytapi.dwWaveOutID, name, hTTYWnd);
} else {
mytapi.iPlayState = PLAYSTATE_IDLE;
mytapi.iPlaySubState = PLAYSUBSTATE_PASSWORD0;
mytapi.nPlayCnt = 0;
}
}
break;
case MM_WIM_DATA:
waveInUnprepareHeader (mytapi.h_wavein, (LPWAVEHDR)lParam, sizeof(WAVEHDR));
waveInClose (mytapi.h_wavein); /* close wave device */
/* drop the call */
if (mytapi.hCall) {
if ((lrc = lineDrop (mytapi.hCall, NULL, 0)) < 0) {
ProcessTAPIError (lrc);
MessageBox (hTTYWnd, "Error dropping call", "", MB_OK);
}
}
mytapi.nMsgCnt++;
wsprintf (name, "msg-%d.wav", mytapi.nMsgCnt);
saveMessage (name, (LPWAVEHDR)lParam); /* save the message */
GlobalFree ((HANDLE)((LPWAVEHDR)lParam)->dwUser); /* free 60s message buffer */
mytapi.iPlayState = PLAYSTATE_IDLE;
mytapi.iPlaySubState = PLAYSUBSTATE_PASSWORD0;
// set ring count for the message-waiting situation
lineSetNumRings (mytapi.hLine, 0, max(0,RINGCNT-2));
lineGetNumRings(mytapi.hLine, 0, &mytapi.nRingCnt);
break;
case WM_CREATE:
mytapi.bInitialized = FALSE;
break;
case WM_COMMAND:
{
switch ((DWORD) wParam)
{
case IDM_AUTOANSWER:
if (!mytapi.bLineopen) {
if (telephonyOpen(hWnd, ghInst)) {
MessageBox(hWnd, "Error", "Error opening line", MB_OK);
break;
}
}
mytapi.bWaitForCall = TRUE;
mytapi.dwWaveInID = mylineGetWaveID(LINECALLSELECT_LINE, "wave/in");
recordMessage (mytapi.dwWaveInID);
break;
case IDM_EXIT:
PostMessage( hWnd, WM_CLOSE, 0, 0L ) ;
break ;
}
}
break ;
case WM_PAINT: {
PaintTTY( hWnd ) ;
break ;
}
case WM_SIZE:
SizeTTY( hWnd, HIWORD( lParam ), LOWORD( lParam ) ) ;
break ;
case WM_DESTROY:
PostQuitMessage( 0 ) ;
break ;
default:
return( DefWindowProc( hWnd, uMsg, wParam, lParam ) ) ;
}
return 0L ;
} // end of TTYWndProc()
//---------------------------------------------------------------------------
// BOOL NEAR PaintTTY( HWND hWnd )
//
// Description:
// Paints the rectangle determined by the paint struct of
// the DC.
//
// Parameters:
// HWND hWnd
// handle to TTY window (as always)
//
//---------------------------------------------------------------------------
BOOL NEAR PaintTTY( HWND hWnd )
{
return ( TRUE ) ;
} // end of PaintTTY()
//---------------------------------------------------------------------------
// BOOL NEAR SizeTTY( HWND hWnd, WORD wVertSize, WORD wHorzSize )
//
// Description:
// Sizes TTY and sets up scrolling regions.
//
// Parameters:
// HWND hWnd
// handle to TTY window
//
// WORD wVertSize
// new vertical size
//
// WORD wHorzSize
// new horizontal size
//
//---------------------------------------------------------------------------
BOOL NEAR SizeTTY( HWND hWnd, WORD wVertSize, WORD wHorzSize )
{
return ( TRUE ) ;
} // end of SizeTTY()
//---------------------------------------------------------------------------
// End of File: comdial.c
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -