📄 mysimpletapi.h
字号:
//
// MySimpleTapi.h
//
// Source code from:
//
// Serial Communications: A C++ Developer's Guide, 2nd
// Edition by Mark Nelson, IDG Books, 1999
//
// Please see the book for information on usage.
//
// This class contains the entire definition and
// implementation of MySimpleTapi. This is a concrete class
// that is derived from SimpleTapi, and implements all of
// the virtual functions needed to implement the class.
// The implementations here provide notification that is
// specific to the demo program in Chapter 15, and will
// probably need modifications to work with your program.
//
// This class performs all notification by sending Windows
// messages to a notification window. That window is passed
// in as an argument to the constructor and is stored in
// member m_hNotificationWindow.
//
// A second member is used to hold the phone number that is
// going to be dialed. In the demo program of Chapter 15,
// this member is modified by a dialog box inovked from the
// main window's menu.
//
#ifndef _MY_SIMPLE_TAPI_H
#define _MY_SIMPLE_TAPI_H
#include "SimpleTapi.h"
//
// These are the three windows messages that are sent to the
// notification window.
//
const int WM_TAPI_CONNECTED_NOTIFY = WM_USER + 0x1002;
const int WM_TAPI_DISCONNECTED_NOTIFY = WM_USER + 0x1003;
const int WM_TAPI_STATE_CHANGE_NOTIFY = WM_USER + 0x1004;
class MySimpleTapi : public SimpleTapi
{
public :
//
// The constructor gets a copy of the handle of the
// notification window. That is where all messages
// will be sent.
//
MySimpleTapi( HWND hwnd )
{
m_hNotificationWindow = hwnd;
}
//
// This is a handly place to keep track of the number
// that is going to be used to dial out eventually.
//
string m_NumberToDial;
protected :
HWND m_hNotificationWindow;
//
// This virtual function is used by the base class when
// it creates the configuration dialog. GetWindow() is
// supposed to return the window that should be the parent
// window of the dialogs. In this particular
// implemenation, we assume that the notification window
// will be the same as the parent window for these
// dialogs.
//
virtual HWND GetWindow()
{
return m_hNotificationWindow;
}
//
// This event is called by the base class when a
// connection is completed, whether it is from an
// incoming or outgoing call. Once the connection is
// made, we take the important step of getting the
// handle and using it to open the port used by the
// terminal emulator. Once that port is opened, we are
// in business and will actually pass characters in and
// out from the communications port.
//
// Note that in addition to doing this work, we also
// send a notification message to the window associated
// with this object. In the case of the Chapter 15 demo
// program, that takes care of updating the menu and
// displaying a message indicating that we are now
// connected.
//
void ConnectedEvent()
{
AnsiTapiTerm *pTerm;
pTerm = (AnsiTapiTerm *)
GetWindowLong( m_hNotificationWindow, 0 );
HANDLE h = GetPortHandle();
if ( h )
pTerm->OpenPort( h );
SendMessage( m_hNotificationWindow,
WM_TAPI_CONNECTED_NOTIFY,
0,
0 );
}
//
// This is the other important routine that is called
// by the base class. This guy is called when a connection
// is dropped for whatever reason, including the
// possiblity that we ininitiated a disconnect. When
// this happens wh have to close the port being used by
// the terminal emulator, ASAP. Note that the Tapi32Port
// takes care of actually closing the handle that was
// used when the port was opened.
//
// Note that in addition to doing this work, we also
// send a notification message to the window associated
// with this object. In the case of the Chapter 15 demo
// program, that takes care of updating the menu and
// displaying a message indicating that we are now
// disconnected.
//
void DisconnectedEvent()
{
AnsiTapiTerm *pTerm;
pTerm = (AnsiTapiTerm *)
GetWindowLong( m_hNotificationWindow, 0 );
pTerm->ClosePort();
SendMessage( m_hNotificationWindow,
WM_TAPI_DISCONNECTED_NOTIFY,
0,
0 );
}
//
// The base class calls this routine whenever the TAPI
// state of the line changes. We perform an informative
// trace print here, and send a notification message to
// the main window of the app. That call should take
// care of updating an UI features, such as the menu,
// that need to be dealt with in the new state.
//
void NotifyCallStateChange( long new_state )
{
m_Trace << "Changing to state "
<< TranslateCallState( new_state )
<< endl;
SendMessage( m_hNotificationWindow,
WM_TAPI_STATE_CHANGE_NOTIFY,
0,
0 );
}
//
// At this time error messages just get a printout in
// the trace window. They are pretty rare, a message
// box might be a better choice.
//
void Error( const char *msg, LONG code )
{
m_Trace << "ERROR: "
<< msg
<< TranslateTapiError( code )
<< endl;
}
//
// When a call is made to MakeCall() with a phone number,
// we don't get immediate results. Instead, some things
// happen, TAPI waits around a while, and eventually
// the result is known. When that happens, this
// notification routine is called, and the main app then
// knows what is going on. We don't have any thing in
// the main task that needs this information, so instead
// we just dump the info to the trace window.
//
void MakeCallResult( bool result )
{
m_Trace << "MakeCall() returned "
<< TranslateTapiError( result )
<< endl;
}
//
// Exactly the same comments apply here as in the previous
// function.
//
void DropCallResult( bool result )
{
m_Trace << "DropCall() returned "
<< TranslateTapiError( result )
<< endl;
}
};
#endif //#ifndef _MY_SIMPLE_TAPI_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -