TAPICaseView.cpp
上传用户:fstfhk1234
上传日期:2007-06-12
资源大小:67k
文件大小:12k
源码类别:

TAPI编程

开发平台:

Visual C++

  1. // TAPICaseView.cpp : implementation of the CTAPICaseView class
  2. //
  3. #include "stdafx.h"
  4. #include "TAPICase.h"
  5. #include "global.h"
  6. #include "TAPI.h"
  7. #include "TAPILine.h"
  8. #include "TAPICaseDoc.h"
  9. #include "TAPICaseView.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. extern CTAPILine* myTAPILine;//引用外部变量
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CTAPICaseView
  18. IMPLEMENT_DYNCREATE(CTAPICaseView, CFormView)
  19. BEGIN_MESSAGE_MAP(CTAPICaseView, CFormView)
  20. //{{AFX_MSG_MAP(CTAPICaseView)
  21. ON_BN_CLICKED(IDC_DIAL, OnDial)
  22. ON_BN_CLICKED(IDC_DISCONNECTED, OnDisconnected)
  23. ON_BN_CLICKED(IDC_LINECONFIGURE, OnLineconfigure)
  24. ON_BN_CLICKED(IDC_DIALPROPERTY, OnDialproperty)
  25. ON_CBN_SELCHANGE(IDC_LINE, OnSelchangeLine)
  26. //}}AFX_MSG_MAP
  27. // Standard printing commands
  28. ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
  29. ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
  30. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
  31. END_MESSAGE_MAP()
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CTAPICaseView construction/destruction
  34. CTAPICaseView::CTAPICaseView()
  35. : CFormView(CTAPICaseView::IDD)
  36. {
  37. //{{AFX_DATA_INIT(CTAPICaseView)
  38. m_strLine = _T("");
  39. m_strPhoneNumber = _T("1111111");
  40. //}}AFX_DATA_INIT
  41. // TODO: add construction code here
  42. }
  43. CTAPICaseView::~CTAPICaseView()
  44. {
  45. }
  46. void CTAPICaseView::DoDataExchange(CDataExchange* pDX)
  47. {
  48. CFormView::DoDataExchange(pDX);
  49. //{{AFX_DATA_MAP(CTAPICaseView)
  50. DDX_Control(pDX, IDC_PROGRESS, m_ctrlProgress);
  51. DDX_Control(pDX, IDC_DIALICON, m_ctrlIcon);
  52. DDX_Control(pDX, IDC_DIAL, m_ctrlDial);
  53. DDX_Control(pDX, IDC_DISCONNECTED, m_ctrlDisconnect);
  54. DDX_Control(pDX, IDC_LINE, m_ctrlLine);
  55. DDX_Control(pDX, IDC_LIST1, m_ctrlListBox);
  56. DDX_CBString(pDX, IDC_LINE, m_strLine);
  57. DDX_Text(pDX, IDC_PHONENUMBER, m_strPhoneNumber);
  58. //}}AFX_DATA_MAP
  59. }
  60. BOOL CTAPICaseView::PreCreateWindow(CREATESTRUCT& cs)
  61. {
  62. // TODO: Modify the Window class or styles here by modifying
  63. //  the CREATESTRUCT cs
  64. return CFormView::PreCreateWindow(cs);
  65. }
  66. //对线路进行初始化
  67. void CTAPICaseView::OnInitialUpdate()
  68. {
  69. CFormView::OnInitialUpdate();
  70. GetParentFrame()->RecalcLayout();
  71. ResizeParentToFit();
  72. DWORD line;
  73. BOOL bSuccess;
  74. char strItem[100];
  75. //开始时候,挂断按钮无效
  76. m_ctrlDisconnect.EnableWindow(FALSE);
  77. myTAPILine = new CTAPILine;
  78. //将要协商的版本:1.3到3.0
  79. myTAPILine->SetLowAPI(0x00010003);
  80. myTAPILine->SetHighAPI(0x00030000);
  81. //在列表框中设置返回信息
  82. m_ctrlListBox.AddString(_T("TAPI版本协商"));
  83. //为每条线路进行初始化和协商
  84. bSuccess = myTAPILine->Create();
  85. //如果成功,列出所有的有效地TAPI线路
  86. if(bSuccess)
  87. {
  88. for(line = 0; line < myTAPILine->GetNumLines(); line++)
  89. {
  90. myTAPILine->SetCurrentLineID(line);
  91. if(myTAPILine->GetNegoAPIVersion())
  92. {
  93. sprintf(strItem, "%d", line); 
  94. m_ctrlLine.AddString((const char*)strItem);
  95. }
  96. }
  97. //设置当前的选择为第一条线路
  98. m_ctrlLine.SetCurSel(0);
  99. OnSelchangeLine();
  100. }
  101. else
  102. {
  103. //返回用户信息,但不支持TAPI 2.1
  104. m_ctrlListBox.ResetContent();
  105. m_ctrlListBox.AddString(myTAPILine->ErrorString(myTAPILine->GetLasterror()));
  106. m_ctrlListBox.AddString("试探TaPI1.3 - 1.4");
  107. myTAPILine->SetLowAPI(0x00010003);
  108. myTAPILine->SetHighAPI(0x00010004);
  109. bSuccess = myTAPILine->Create();
  110. if(bSuccess)
  111. {
  112. for(line = 0; line < myTAPILine->GetNumLines(); line++)
  113. {
  114. myTAPILine->SetCurrentLineID(line);
  115. if(myTAPILine->GetNegoAPIVersion())
  116. {
  117. sprintf(strItem, "%d", line); 
  118. m_ctrlLine.AddString((const char*)strItem);
  119. }
  120. }
  121. OnSelchangeLine();
  122. }
  123. else
  124. m_ctrlListBox.AddString("致命的错误, TAPI版本协商失败");
  125. }
  126. }
  127. /////////////////////////////////////////////////////////////////////////////
  128. // CTAPICaseView printing
  129. BOOL CTAPICaseView::OnPreparePrinting(CPrintInfo* pInfo)
  130. {
  131. // default preparation
  132. return DoPreparePrinting(pInfo);
  133. }
  134. void CTAPICaseView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  135. {
  136. // TODO: add extra initialization before printing
  137. }
  138. void CTAPICaseView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  139. {
  140. // TODO: add cleanup after printing
  141. }
  142. void CTAPICaseView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
  143. {
  144. // TODO: add customized printing code here
  145. }
  146. /////////////////////////////////////////////////////////////////////////////
  147. // CTAPICaseView diagnostics
  148. #ifdef _DEBUG
  149. void CTAPICaseView::AssertValid() const
  150. {
  151. CFormView::AssertValid();
  152. }
  153. void CTAPICaseView::Dump(CDumpContext& dc) const
  154. {
  155. CFormView::Dump(dc);
  156. }
  157. CTAPICaseDoc* CTAPICaseView::GetDocument() // non-debug version is inline
  158. {
  159. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTAPICaseDoc)));
  160. return (CTAPICaseDoc*)m_pDocument;
  161. }
  162. #endif //_DEBUG
  163. /////////////////////////////////////////////////////////////////////////////
  164. // CTAPICaseView message handlers
  165. //"拨号"按钮的响应函数
  166. void CTAPICaseView::OnDial() 
  167. {
  168. // TODO: Add your control notification handler code here
  169. BOOL bSuccess;
  170. CString strTemp;
  171. UpdateData(TRUE);
  172. m_ctrlDial.EnableWindow(FALSE);
  173. m_ctrlProgress.ResetContent();
  174. //提示用户进度
  175. strTemp.Format("打开线路: #%dn", myTAPILine->GetCurrentLineID());
  176. m_ctrlProgress.AddString(strTemp);
  177. UpdateData(FALSE);
  178. bSuccess = myTAPILine->OpenLine();
  179. if(!bSuccess)
  180. {
  181. strTemp = "TAPI错误n" + myTAPILine->ErrorString(myTAPILine->GetLasterror());
  182. ::MessageBox(NULL, strTemp, "错误提示", MB_OK);
  183. m_ctrlDial.EnableWindow(TRUE);
  184. return;
  185. }
  186. strTemp.Format("正准备呼叫: %sn", m_strPhoneNumber);
  187. m_ctrlProgress.AddString(strTemp);
  188. UpdateData(FALSE);
  189. //调用呼叫函数进行呼叫
  190. bSuccess = myTAPILine->MakeCallAsynch(m_strPhoneNumber);
  191. if(!bSuccess)
  192. {
  193. myTAPILine->CloseLine();
  194. strTemp = "TAPI错误n" + myTAPILine->ErrorString(myTAPILine->GetLasterror());
  195. ::MessageBox(NULL, strTemp, "错误提示", MB_OK);
  196. m_ctrlDial.EnableWindow(TRUE);
  197. return;
  198. }
  199. }
  200. //"挂断"按钮的响应函数
  201. void CTAPICaseView::OnDisconnected() 
  202. {
  203. // TODO: Add your control notification handler code here
  204. BOOL bSuccess;
  205. m_ctrlProgress.ResetContent();
  206. m_ctrlProgress.AddString("请求挂断呼叫");
  207. bSuccess = myTAPILine->DropCallAsynch();
  208. if(!bSuccess)
  209. {
  210. ::MessageBox(NULL, myTAPILine->ErrorString(myTAPILine->GetLasterror()), "错误提示", MB_OK);
  211. }
  212. }
  213. //"线路配置"按钮的响应函数
  214. void CTAPICaseView::OnLineconfigure() 
  215. {
  216. // TODO: Add your control notification handler code here
  217. BOOL bSuccess;
  218. bSuccess = myTAPILine->ConfigDialog(NULL);
  219. if(!bSuccess)
  220. ::MessageBox(NULL, myTAPILine->ErrorString(myTAPILine->GetLasterror()), "错误提示", MB_OK);
  221. }
  222. //"拨号属性"按钮的响应函数
  223. void CTAPICaseView::OnDialproperty() 
  224. {
  225. // TODO: Add your control notification handler code here
  226. BOOL bSuccess;
  227. UpdateData(TRUE);
  228. bSuccess = myTAPILine->DialoingPropertiesDialog(NULL, m_strPhoneNumber);
  229. if(!bSuccess)
  230. ::MessageBox(NULL, myTAPILine->ErrorString(myTAPILine->GetLasterror()), "错误提示", MB_OK);
  231. }
  232. //"线路"组合框焦点改变的响应函数
  233. void CTAPICaseView::OnSelchangeLine() 
  234. {
  235. // TODO: Add your control notification handler code here
  236. //清空信息框
  237. //int i;
  238. char buffer[100];
  239. CString strTemp;
  240. m_ctrlListBox.ResetContent();
  241. UpdateData(TRUE);
  242. sprintf(buffer, "%d", m_ctrlLine.GetCurSel());
  243. m_strLine = (const char*)buffer;
  244. if( m_strLine != "")
  245. {
  246. //类的信息转换为当前的线路
  247. myTAPILine->SetCurrentLineID(atol(m_strLine));
  248. //在列表框中显示当前线路的信息
  249. strTemp.Format("TAPI线路: #%d", myTAPILine->GetCurrentLineID());
  250. m_ctrlListBox.AddString(strTemp);
  251. strTemp.Format("TAPI线路名称: %s", myTAPILine->GetLineName());
  252. m_ctrlListBox.AddString(strTemp);
  253. strTemp.Format("TAPI服务提供商名称: %s", myTAPILine->GetProviderInfo());
  254. m_ctrlListBox.AddString(strTemp);
  255. strTemp.Format("TAPI转换信息: %s", myTAPILine->GetSwitchInfo());
  256. m_ctrlListBox.AddString(strTemp);
  257. strTemp.Format("固定的线路标识: %d", myTAPILine->GetPermanentLineID());
  258. m_ctrlListBox.AddString(strTemp);
  259. switch(myTAPILine->GetStringFormat())
  260. {
  261. case STRINGFORMAT_ASCII:
  262. m_ctrlListBox.AddString("字符串格式: STRINGFORMAT_ASCII");
  263. break;
  264. case STRINGFORMAT_DBCS:
  265. m_ctrlListBox.AddString("字符串格式: STRINGFORMAT_DBCS");
  266. break;
  267. case STRINGFORMAT_UNICODE:
  268. m_ctrlListBox.AddString("字符串格式: STRINGFORMAT_UNICODe");
  269. break;
  270. case STRINGFORMAT_BINARY:
  271. m_ctrlListBox.AddString("字符串格式: STRINGFORMAT_BINARY");
  272. break;
  273. }
  274. strTemp.Format("与本线路相关联的地址数目: %d", myTAPILine->GetNumAddress());
  275. m_ctrlListBox.AddString(strTemp);
  276. strTemp.Format("最大数据传输率: %d", myTAPILine->GetmaxDataRate());
  277. m_ctrlListBox.AddString(strTemp);
  278. m_ctrlListBox.AddString("支持的载荷模式:");
  279. if(LINEBEARERMODE_VOICE & myTAPILine->GetBearerModes())
  280. m_ctrlListBox.AddString("tLINEBEARERMODE_VOICE");
  281. if(LINEBEARERMODE_SPEECH & myTAPILine->GetBearerModes())
  282. m_ctrlListBox.AddString("tLINEBEARERMODE_SPEECH");
  283. if(LINEBEARERMODE_DATA & myTAPILine->GetBearerModes())
  284. m_ctrlListBox.AddString("tLINEBEARERMODE_DATA");
  285. if(LINEBEARERMODE_ALTSPEECHDATA & myTAPILine->GetBearerModes())
  286. m_ctrlListBox.AddString("tLINEBEARERMODE_ALTSPEECHDATA");
  287. if(LINEBEARERMODE_MULTIUSE & myTAPILine->GetBearerModes())
  288. m_ctrlListBox.AddString("tLINEBEARERMODE_MULTIUSE");
  289. if(LINEBEARERMODE_NONCALLSIGNALING & myTAPILine->GetBearerModes())
  290. m_ctrlListBox.AddString("tLINEBEARERMODE_NONCALLSIGNALING");
  291. m_ctrlListBox.AddString("支持的地址模式");
  292. if(LINEADDRESSMODE_ADDRESSID & myTAPILine->GetAddressModes())
  293. m_ctrlListBox.AddString("tLINEADDRESSMODE_ADDRESSID");
  294. if(LINEADDRESSMODE_DIALABLEADDR & myTAPILine->GetAddressModes())
  295. m_ctrlListBox.AddString("tLINEADDRESSMODE_DIALABLEADDR");
  296. m_ctrlListBox.AddString("支持的媒体形式");
  297. if(LINEMEDIAMODE_ADSI & myTAPILine->GetMediaModes())
  298. m_ctrlListBox.AddString("tLINEMEDIAMODE_ADSI");
  299. if(LINEMEDIAMODE_AUTOMATEDVOICE & myTAPILine->GetMediaModes())
  300. m_ctrlListBox.AddString("tLINEMEDIAMODE_AUTOMATEDVOICE");
  301. if(LINEMEDIAMODE_DATAMODEM & myTAPILine->GetMediaModes())
  302. m_ctrlListBox.AddString("tLINEMEDIAMODE_DATAMODEM");
  303. if(LINEMEDIAMODE_DIGITALDATA & myTAPILine->GetMediaModes())
  304. m_ctrlListBox.AddString("tLINEMEDIAMODE_DITAIGALDATA");
  305. if(LINEMEDIAMODE_G3FAX & myTAPILine->GetMediaModes())
  306. m_ctrlListBox.AddString("tLINEMEDIAMODE_G3FAX");
  307. if(LINEMEDIAMODE_G4FAX & myTAPILine->GetMediaModes())
  308. m_ctrlListBox.AddString("tLINEMEDIAMODE_G4FAX");
  309. if(LINEMEDIAMODE_INTERACTIVEVOICE & myTAPILine->GetMediaModes())
  310. m_ctrlListBox.AddString("tLINEMEDIAMODE_INTERACTIVEVOICE");
  311. if(LINEMEDIAMODE_MIXED & myTAPILine->GetMediaModes())
  312. m_ctrlListBox.AddString("tLINEMEDIAMODE_MIXED");
  313. if(LINEMEDIAMODE_TDD & myTAPILine->GetMediaModes())
  314. m_ctrlListBox.AddString("tLINEMEDIAMODE_TDD");
  315. if(LINEMEDIAMODE_TELETEX & myTAPILine->GetMediaModes())
  316. m_ctrlListBox.AddString("tLINEMEDIAMODE_TELETEX");
  317. if(LINEMEDIAMODE_UNKNOWN & myTAPILine->GetMediaModes())
  318. m_ctrlListBox.AddString("tLINEMEDIAMODE_UNKNOWN");
  319. if(LINEMEDIAMODE_VIDEOTEX & myTAPILine->GetMediaModes())
  320. m_ctrlListBox.AddString("tLINEMEDIAMODE_VIDEOTEX");
  321. if(myTAPILine->GetGenerateToneMaxNumFreq() == 0)
  322. m_ctrlListBox.AddString("是否支持Line Tone Generation: 否");
  323. else
  324. {
  325. m_ctrlListBox.AddString("是否支持Line Tone Generation: 是");
  326. if(LINETONEMODE_BEEP & myTAPILine->GetGenerateToneModes())
  327. m_ctrlListBox.AddString("tLINETONEMODE_BEEP");
  328. if(LINETONEMODE_BILLING & myTAPILine->GetGenerateToneModes())
  329. m_ctrlListBox.AddString("tLINETONEMODE_BILLING");
  330. if(LINETONEMODE_BUSY & myTAPILine->GetGenerateToneModes())
  331. m_ctrlListBox.AddString("tLINETONEMODE_BUSY");
  332. if(LINETONEMODE_CUSTOM & myTAPILine->GetGenerateToneModes())
  333. m_ctrlListBox.AddString("tLINETONEMODE_CUSTOM");
  334. if(LINETONEMODE_RINGBACK & myTAPILine->GetGenerateToneModes())
  335. m_ctrlListBox.AddString("tLINETONEMODE_RINGBACK");
  336. }
  337. strTemp.Format("线路终端数目: %d", myTAPILine->GetNumTerminals());
  338. m_ctrlListBox.AddString(strTemp);
  339. }
  340. else
  341. m_ctrlListBox.AddString("没有有效的TAPI线路选中");
  342. //是否支持语音呼叫
  343. if(myTAPILine->GetLineSupportsVoice())
  344. m_ctrlDial.EnableWindow(TRUE);
  345. else
  346. m_ctrlDial.EnableWindow(FALSE);
  347. //绘制线路图标
  348. HICON hIcon;
  349. LONG rc;
  350. rc = lineGetIcon(myTAPILine->GetCurrentLineID(), "", &hIcon);
  351. if(hIcon != NULL)
  352. m_ctrlIcon.SetIcon(hIcon);
  353. }