⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.h

📁 C++Builder网络应用例程. C++Builder网络应用例程.
💻 H
字号:
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <vcl\Classes.hpp>
#include <vcl\Controls.hpp>
#include <vcl\StdCtrls.hpp>
#include <vcl\Forms.hpp>

//Uncomment the following line if you receive a linker error
//Undefined symbol lineGetCallInfoA (and several others)
#define TAPI_CURRENT_VERSION 0x00010004
//Include the TAPI headers
#include <tapi.h>
#define BUFSIZE 255
//---------------------------------------------------------------------------
//Basic file event handling thread
class TFileThread : public TThread
{
  private:
    //Internal routine that will update screen with error message
    void __fastcall ShowError(void);

  protected:
    //Handles for the communications file and an event
    HANDLE hFileEvent, hCommDevice;
    //Overlap structure for overlapped i/o
    OVERLAPPED oOverlap;
    //Holding area for the last error message
    String ErrorMess;
    //Buffer for communications data
    char Buffer[BUFSIZE];

    //Actual error routine
    void __fastcall Error(String ErrMess);

  public:
    //Override constructor, destructor and terminate method
    virtual __fastcall TFileThread(HANDLE CommFile);
    virtual __fastcall ~TFileThread(void);
    void __fastcall Terminate(void);
};

//Thread to manage writing data to comm file
class TFileWriteThread : public TFileThread
{
private:
  //Holding area for string to write
  String WriteString;
  //Critical section used to protect the write string
  CRITICAL_SECTION CriticalSection;

  //Override TThread main loop
  void __fastcall Execute(void);
public:
  //Override constructor and destructor
  __fastcall TFileWriteThread(HANDLE CommFile);
  __fastcall ~TFileWriteThread(void);
  //Called by main thread to write data to communications device
  void __fastcall WriteData(String s);
};

//Object to manage reading from comm file
class TFileReadThread : public TFileThread
{
private:
  //Override TThread main loop
  void __fastcall Execute(void);
  //Routine to update main window display
  void __fastcall UpdateWindow(void);
public:
  //Override constructor
  __fastcall TFileReadThread(HANDLE);
};

//Structure to hold information on comm device returned by TAPI
typedef struct modem_info_tag {
  VARSTRING vs;
  HANDLE hComm;
  char szDeviceName[255];
} MODEM_INFO, FAR *LPMODEM_INFO;

//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:	// IDE-managed Components
	TMemo *mMessage;
        TButton *bCall;
	TEdit *Edit1;
	TLabel *Label1;
        TMemo *Input;
        TMemo *Output;
	TLabel *Label2;
	TLabel *Label3;
        TButton *HangUp;
	TLabel *Label4;
	void __fastcall FormCreate(TObject *Sender);
	void __fastcall FormDestroy(TObject *Sender);
	void __fastcall bCallClick(TObject *Sender);

	void __fastcall FormShow(TObject *Sender);

	void __fastcall InputKeyPress(TObject *Sender, char &Key);
	void __fastcall HangUpClick(TObject *Sender);
private:	// User declarations
  //Handle to TAPI DLL connection
  HLINEAPP LineApp;
  //Handle to TAPI line
  HLINE Line;
  //Handle to TAPI call
  HCALL Call;
  //Parameters of call
  LINECALLPARAMS CallParams;
  //Communications file handle
  HANDLE hCommDevice;
  //Pointers to the file reading and file writing threads
  TFileWriteThread *FileWriteThread;
  TFileReadThread *FileReadThread;
  //Holds state of terminal
  bool TerminalConnected;

public:		// User declarations
	virtual __fastcall TForm1(TComponent* Owner);
    //Function to start up terminal after modem has connected
    void __fastcall ConnectTerminal(void);
    //Function to shut down terminal when modem has disconnected
    void __fastcall ShutdownTerminal(void);
};
//---------------------------------------------------------------------------
extern TForm1 *Form1;

//Function called by TAPI functions when events occur
void CALLBACK lineCallback(DWORD hDevice, DWORD dwMsg, DWORD dwCallbackInstance
                            , DWORD dwParam1, DWORD dwParam2, DWORD dwParam3);

//---------------------------------------------------------------------------
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -