Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3417 lines
76 KiB

  1. // t3testDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include <control.h> // for IVideoWindow
  5. #include "t3test.h"
  6. #include "t3testD.h"
  7. #include "calldlg.h"
  8. #include "callnot.h"
  9. #include "uuids.h"
  10. #include "autoans.h"
  11. #include "confdlg.h"
  12. #include "ilsdlg.h"
  13. #include "rate.h"
  14. #ifdef _DEBUG
  15. #ifndef _WIN64 // mfc 4.2's heap debugging features generate warnings on win64
  16. #define new DEBUG_NEW
  17. #endif
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. ITTAPI * gpTapi;
  22. IConnectionPoint * gpCP;
  23. HWND ghAddressesWnd;
  24. HWND ghTerminalsWnd;
  25. HWND ghMediaTypesWnd;
  26. HWND ghCallsWnd;
  27. HWND ghPhonesWnd;
  28. HWND ghSelectedCallsWnd;
  29. HWND ghSelectedWnd;
  30. HWND ghCreatedWnd;
  31. HWND ghClassesWnd;
  32. HWND ghListenWnd;
  33. HTREEITEM ghAddressesRoot;
  34. HTREEITEM ghTerminalsRoot;
  35. HTREEITEM ghMediaTypesRoot;
  36. HTREEITEM ghCallsRoot;
  37. HTREEITEM ghPhonesRoot;
  38. HTREEITEM ghSelectedCallsRoot;
  39. HTREEITEM ghSelectedRoot;
  40. HTREEITEM ghCreatedRoot;
  41. HTREEITEM ghClassesRoot;
  42. HTREEITEM ghListenRoot;
  43. #ifdef ENABLE_DIGIT_DETECTION_STUFF
  44. CDigitDetectionNotification * gpDigitNotification;
  45. #endif // ENABLE_DIGIT_DETECTION_STUFF
  46. long gulAdvise;
  47. BOOL gbUpdatingStuff = FALSE;
  48. BOOL gfShuttingDown = FALSE;
  49. DataPtrList gDataPtrList;
  50. extern CT3testApp theApp;
  51. const BSTR TAPIMEDIATYPE_String_Audio = L"{028ED8C2-DC7A-11D0-8ED3-00C04FB6809F}";
  52. const BSTR TAPIMEDIATYPE_String_Video = L"{028ED8C4-DC7A-11D0-8ED3-00C04FB6809F}";
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CAboutDlg dialog used for App About
  55. class CAboutDlg : public CDialog
  56. {
  57. public:
  58. CAboutDlg();
  59. // Dialog Data
  60. //{{AFX_DATA(CAboutDlg)
  61. enum { IDD = IDD_ABOUTBOX };
  62. //}}AFX_DATA
  63. // ClassWizard generated virtual function overrides
  64. //{{AFX_VIRTUAL(CAboutDlg)
  65. protected:
  66. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  67. //}}AFX_VIRTUAL
  68. // Implementation
  69. protected:
  70. //{{AFX_MSG(CAboutDlg)
  71. //}}AFX_MSG
  72. DECLARE_MESSAGE_MAP()
  73. };
  74. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  75. {
  76. //{{AFX_DATA_INIT(CAboutDlg)
  77. //}}AFX_DATA_INIT
  78. }
  79. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  80. {
  81. CDialog::DoDataExchange(pDX);
  82. //{{AFX_DATA_MAP(CAboutDlg)
  83. //}}AFX_DATA_MAP
  84. }
  85. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  86. //{{AFX_MSG_MAP(CAboutDlg)
  87. // No message handlers
  88. //}}AFX_MSG_MAP
  89. END_MESSAGE_MAP()
  90. /////////////////////////////////////////////////////////////////////////////
  91. // CT3testDlg dialog
  92. CT3testDlg::CT3testDlg(CWnd* pParent /*=NULL*/)
  93. : CDialog(CT3testDlg::IDD, pParent)
  94. {
  95. //{{AFX_DATA_INIT(CT3testDlg)
  96. // NOTE: the ClassWizard will add member initialization here
  97. //}}AFX_DATA_INIT
  98. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  99. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  100. }
  101. void CT3testDlg::DoDataExchange(CDataExchange* pDX)
  102. {
  103. CDialog::DoDataExchange(pDX);
  104. //{{AFX_DATA_MAP(CT3testDlg)
  105. // NOTE: the ClassWizard will add DDX and DDV calls here
  106. //}}AFX_DATA_MAP
  107. }
  108. BEGIN_MESSAGE_MAP(CT3testDlg, CDialog)
  109. //{{AFX_MSG_MAP(CT3testDlg)
  110. ON_WM_SYSCOMMAND()
  111. ON_WM_PAINT()
  112. ON_WM_QUERYDRAGICON()
  113. ON_WM_DESTROY()
  114. ON_NOTIFY(TVN_SELCHANGED, IDC_ADDRESSES, OnSelchangedAddresses)
  115. ON_BN_CLICKED(IDC_ADDTERMINAL, OnAddterminal)
  116. ON_BN_CLICKED(IDC_REMOVETERMINAL, OnRemoveterminal)
  117. ON_BN_CLICKED(IDC_CREATECALL, OnCreatecall)
  118. ON_BN_CLICKED(IDC_CONNECT, OnConnect)
  119. ON_BN_CLICKED(IDC_DROP, OnDrop)
  120. ON_BN_CLICKED(IDC_ANSWER, OnAnswer)
  121. ON_BN_CLICKED(IDC_LISTEN, OnListen)
  122. ON_NOTIFY(TVN_SELCHANGED, IDC_CALLS, OnSelchangedCalls)
  123. ON_NOTIFY(TVN_SELCHANGED, IDC_PHONES, OnSelchangedPhones)
  124. ON_BN_CLICKED(IDC_RELEASE, OnRelease)
  125. ON_BN_CLICKED(IDC_CREATE, OnCreateTerminal)
  126. ON_BN_CLICKED(IDC_RELEASETERMINAL, OnReleaseterminal)
  127. ON_BN_CLICKED(IDC_ADDCREATED, OnAddcreated)
  128. ON_BN_CLICKED(IDC_ADDNULL, OnAddnull)
  129. ON_BN_CLICKED(IDC_ADDTOLISTEN, OnAddtolisten)
  130. ON_BN_CLICKED(IDC_LISTENALL, OnListenall)
  131. ON_BN_CLICKED(IDC_CONFIGAUTOANSWER, OnConfigAutoAnswer)
  132. ON_BN_CLICKED(IDC_ILS, OnILS)
  133. ON_BN_CLICKED(IDC_RATE, OnRate)
  134. ON_BN_CLICKED(IDC_OPENPHONE, OnOpenPhone)
  135. ON_BN_CLICKED(IDC_CLOSEPHONE, OnClosePhone)
  136. ON_BN_CLICKED(IDC_STARTTONE, OnStartTone)
  137. ON_BN_CLICKED(IDC_STOPTONE, OnStopTone)
  138. ON_BN_CLICKED(IDC_STARTRING, OnStartRing)
  139. ON_BN_CLICKED(IDC_STOPRING, OnStopRing)
  140. ON_BN_CLICKED(IDC_BUSYTONE, OnBusyTone)
  141. ON_BN_CLICKED(IDC_RINGBACKTONE, OnRingBackTone)
  142. ON_BN_CLICKED(IDC_ERRORTONE, OnErrorTone)
  143. ON_BN_CLICKED(IDC_PHONEAUTOON, OnPhoneAutoOn)
  144. ON_BN_CLICKED(IDC_PHONEAUTOOFF, OnPhoneAutoOff)
  145. ON_BN_CLICKED(IDC_PHONESPEAKERONHOOK, OnPhoneSpeakerOnHook)
  146. ON_BN_CLICKED(IDC_PHONESPEAKEROFFHOOK, OnPhoneSpeakerOffHook)
  147. ON_BN_CLICKED(IDC_SELECTCALL, OnSelectCall)
  148. ON_BN_CLICKED(IDC_UNSELECTCALL, OnUnselectCall)
  149. ON_NOTIFY(TVN_SELCHANGED, IDC_MEDIATYPES, OnSelchangedMediatypes)
  150. ON_NOTIFY(NM_RCLICK, IDC_SELECTEDTERMINALS, OnRclickSelectedterminals)
  151. #ifdef ENABLE_DIGIT_DETECTION_STUFF
  152. ON_COMMAND(ID_GENERATE, OnGenerate)
  153. ON_COMMAND(ID_MODESUPPORTED, OnModesSupported)
  154. ON_COMMAND(ID_MODESUPPORTED2, OnModesSupported2)
  155. ON_COMMAND(ID_STARTDETECT, OnStartDetect)
  156. ON_COMMAND(ID_STOPDETECT, OnStopDetect)
  157. #endif // ENABLE_DIGIT_DETECTION_STUFF
  158. ON_COMMAND(ID_PARK1, OnPark1)
  159. ON_COMMAND(ID_PARK2, OnPark2)
  160. ON_COMMAND(ID_HANDOFF1, OnHandoff1)
  161. ON_COMMAND(ID_HANDOFF2, OnHandoff2)
  162. ON_COMMAND(ID_UNPARK, OnUnpark)
  163. ON_COMMAND(ID_PICKUP1, OnPickup1)
  164. ON_COMMAND(ID_PICKUP2, OnPickup2)
  165. ON_WM_CLOSE()
  166. ON_MESSAGE(WM_USER+101, OnTapiEvent)
  167. ON_NOTIFY(NM_RCLICK, IDC_CALLS, OnRclickCalls)
  168. //}}AFX_MSG_MAP
  169. END_MESSAGE_MAP()
  170. /////////////////////////////////////////////////////////////////////////////
  171. // CT3testDlg message handlers
  172. BOOL CT3testDlg::OnInitDialog()
  173. {
  174. CDialog::OnInitDialog();
  175. // IDM_ABOUTBOX must be in the system command range.
  176. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  177. ASSERT(IDM_ABOUTBOX < 0xF000);
  178. CMenu* pSysMenu = GetSystemMenu(FALSE);
  179. if (pSysMenu != NULL)
  180. {
  181. CString strAboutMenu;
  182. strAboutMenu.LoadString(IDS_ABOUTBOX);
  183. if (!strAboutMenu.IsEmpty())
  184. {
  185. pSysMenu->AppendMenu(MF_SEPARATOR);
  186. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  187. }
  188. }
  189. // Set the icon for this dialog. The framework does this automatically
  190. // when the application's main window is not a dialog
  191. SetIcon(m_hIcon, TRUE); // Set big icon
  192. SetIcon(m_hIcon, FALSE); // Set small icon
  193. HRESULT hr;
  194. //
  195. // coinit
  196. //
  197. hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  198. //hr = CoInitialize(NULL);
  199. if (hr != S_OK)
  200. {
  201. MessageBox(L"CoInitialize failed", MB_OK);
  202. return FALSE;
  203. }
  204. //
  205. // create the tapi object
  206. //
  207. hr = CoCreateInstance(
  208. CLSID_TAPI,
  209. NULL,
  210. CLSCTX_INPROC_SERVER,
  211. IID_ITTAPI,
  212. (LPVOID *)&gpTapi
  213. );
  214. if (hr != S_OK)
  215. {
  216. ::MessageBox(NULL, L"CoCreateInstance on TAPI failed", NULL, MB_OK);
  217. return TRUE;
  218. }
  219. //
  220. // initialize tapi
  221. //
  222. hr = gpTapi->Initialize();
  223. if (hr != S_OK)
  224. {
  225. ::MessageBox(NULL, L"TAPI initialize failed", NULL, MB_OK);
  226. gpTapi->Release();
  227. return TRUE;
  228. }
  229. // Set the Event filter to only give us only the events we process
  230. gpTapi->put_EventFilter(TE_CALLNOTIFICATION | \
  231. TE_CALLSTATE | \
  232. TE_CALLHUB | \
  233. TE_CALLMEDIA | \
  234. TE_TAPIOBJECT | \
  235. TE_ADDRESS | \
  236. TE_PHONEEVENT );
  237. //
  238. // intialize the tree controls
  239. //
  240. InitializeTrees();
  241. //
  242. // intialize the address tree control
  243. //
  244. InitializeAddressTree();
  245. //
  246. // register the main event interface
  247. //
  248. RegisterEventInterface();
  249. //
  250. // register for call notification for
  251. // all addresses for outgoing calls
  252. //
  253. RegisterForCallNotifications();
  254. return TRUE; // return TRUE unless you set the focus to a control
  255. }
  256. void CT3testDlg::OnSysCommand(UINT nID, LPARAM lParam)
  257. {
  258. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  259. {
  260. CAboutDlg dlgAbout;
  261. dlgAbout.DoModal();
  262. }
  263. else
  264. {
  265. CDialog::OnSysCommand(nID, lParam);
  266. }
  267. }
  268. // If you add a minimize button to your dialog, you will need the code below
  269. // to draw the icon. For MFC applications using the document/view model,
  270. // this is automatically done for you by the framework.
  271. void CT3testDlg::OnPaint()
  272. {
  273. if (IsIconic())
  274. {
  275. CPaintDC dc(this); // device context for painting
  276. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  277. // Center icon in client rectangle
  278. int cxIcon = GetSystemMetrics(SM_CXICON);
  279. int cyIcon = GetSystemMetrics(SM_CYICON);
  280. CRect rect;
  281. GetClientRect(&rect);
  282. int x = (rect.Width() - cxIcon + 1) / 2;
  283. int y = (rect.Height() - cyIcon + 1) / 2;
  284. // Draw the icon
  285. dc.DrawIcon(x, y, m_hIcon);
  286. }
  287. else
  288. {
  289. CDialog::OnPaint();
  290. }
  291. }
  292. // The system calls this to obtain the cursor to display while the user drags
  293. // the minimized window.
  294. HCURSOR CT3testDlg::OnQueryDragIcon()
  295. {
  296. return (HCURSOR) m_hIcon;
  297. }
  298. void CT3testDlg::OnFinalRelease()
  299. {
  300. // TODO: Add your specialized code here and/or call the base class
  301. CDialog::OnFinalRelease();
  302. }
  303. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  304. //
  305. // SelectFirstItem
  306. //
  307. // selects the first item under the hroot node in hwnd.
  308. // this is used to make sure that something is selected
  309. // in the window at all times.
  310. //
  311. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  312. void CT3testDlg::SelectFirstItem(
  313. HWND hWnd,
  314. HTREEITEM hRoot
  315. )
  316. {
  317. HTREEITEM hChild;
  318. //
  319. // get the first item
  320. //
  321. hChild = TreeView_GetChild(
  322. hWnd,
  323. hRoot
  324. );
  325. //
  326. // select it
  327. //
  328. TreeView_SelectItem(
  329. hWnd,
  330. hChild
  331. );
  332. }
  333. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  334. //
  335. // DeleteSelectedItem
  336. //
  337. //
  338. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  339. void CT3testDlg::DeleteSelectedItem(
  340. HWND hWnd
  341. )
  342. {
  343. HTREEITEM hItem;
  344. //
  345. // get current selections
  346. //
  347. hItem = TreeView_GetSelection( hWnd );
  348. //
  349. // delete it
  350. //
  351. TreeView_DeleteItem(
  352. hWnd,
  353. hItem
  354. );
  355. }
  356. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  357. //
  358. // InitializeAddressTree
  359. // initialize the address tree control with
  360. // the address objects
  361. //
  362. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  363. void CT3testDlg::InitializeAddressTree()
  364. {
  365. IEnumAddress * pEnumAddress;
  366. ITAddress * pAddress;
  367. HTREEITEM hChild;
  368. HRESULT hr;
  369. long l;
  370. DWORD dwCount = 0;
  371. //
  372. // get the address enumerator
  373. //
  374. hr = gpTapi->EnumerateAddresses( &pEnumAddress );
  375. if (S_OK != hr)
  376. {
  377. gpTapi->Release();
  378. gpTapi = NULL;
  379. return;
  380. }
  381. //
  382. // go through all the address objects
  383. // and add them to the address treecontrol
  384. //
  385. while (TRUE)
  386. {
  387. AADATA * pData;
  388. hr = pEnumAddress->Next( 1, &pAddress, NULL );
  389. if (S_OK != hr)
  390. {
  391. break;
  392. }
  393. AddAddressToTree( pAddress );
  394. pAddress->Release();
  395. pData = (AADATA *)CoTaskMemAlloc( sizeof ( AADATA ) );
  396. pData->pAddress = pAddress;
  397. pData->pTerminalPtrList = new TerminalPtrList;
  398. gDataPtrList.push_back( pData );
  399. dwCount++;
  400. }
  401. //
  402. // release the enumerator
  403. //
  404. pEnumAddress->Release();
  405. //
  406. // select the first item
  407. //
  408. if (dwCount > 0)
  409. {
  410. SelectFirstItem(
  411. ghAddressesWnd,
  412. ghAddressesRoot
  413. );
  414. }
  415. }
  416. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  417. //
  418. // RegisterEventInterface
  419. //
  420. // registers the ITTAPIEventNotification interface
  421. //
  422. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  423. void CT3testDlg::RegisterEventInterface()
  424. {
  425. CTAPIEventNotification * pTAPIEventNotification;
  426. IConnectionPointContainer * pCPC;
  427. IConnectionPoint * pCP;
  428. IUnknown * pUnk;
  429. //
  430. // create the object
  431. //
  432. pTAPIEventNotification = new CTAPIEventNotification;
  433. //
  434. // get the connectionpointcontainer interface
  435. // from the tapi object
  436. //
  437. gpTapi->QueryInterface(
  438. IID_IConnectionPointContainer,
  439. (void **) &pCPC
  440. );
  441. //
  442. // get the connectionpoint we are
  443. // looking for
  444. //
  445. pCPC->FindConnectionPoint(
  446. IID_ITTAPIEventNotification,
  447. &gpCP
  448. );
  449. pCPC->Release();
  450. pTAPIEventNotification->QueryInterface(
  451. IID_IUnknown,
  452. (void **)&pUnk
  453. );
  454. //
  455. // call the advise method to tell tapi
  456. // about the interface
  457. //
  458. gpCP->Advise(
  459. pUnk,
  460. (ULONG *)&gulAdvise
  461. );
  462. //
  463. // release our reference to
  464. // it
  465. //
  466. pUnk->Release();
  467. }
  468. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  469. //
  470. // RegisterForCallNotifications
  471. //
  472. // registers for call state notifications for all
  473. // addresses for outgoing calls
  474. //
  475. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  476. void CT3testDlg::RegisterForCallNotifications()
  477. {
  478. VARIANT var;
  479. var.vt = VT_ARRAY;
  480. var.parray = NULL;
  481. gpTapi->SetCallHubTracking(var, VARIANT_TRUE);
  482. }
  483. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  484. //
  485. // InitializeTrees
  486. //
  487. // Create and labels the tree controls
  488. //
  489. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  490. void CT3testDlg::InitializeTrees()
  491. {
  492. TV_INSERTSTRUCT tvi;
  493. tvi.hParent = TVI_ROOT;
  494. tvi.hInsertAfter = TVI_FIRST;
  495. tvi.item.mask = TVIF_TEXT;
  496. //
  497. // address tree
  498. //
  499. tvi.item.pszText = L"Addresses";
  500. ghAddressesWnd = GetDlgItem( IDC_ADDRESSES )->m_hWnd;
  501. ghAddressesRoot = TreeView_InsertItem(
  502. ghAddressesWnd,
  503. &tvi
  504. );
  505. //
  506. // mediatypes tree
  507. //
  508. tvi.item.pszText = L"MediaTypes";
  509. ghMediaTypesWnd = GetDlgItem( IDC_MEDIATYPES )->m_hWnd;
  510. ghMediaTypesRoot = TreeView_InsertItem(
  511. ghMediaTypesWnd,
  512. &tvi
  513. );
  514. //
  515. // terminals tree
  516. //
  517. tvi.item.pszText = L"Terminals";
  518. ghTerminalsWnd = GetDlgItem( IDC_TERMINALS )->m_hWnd;
  519. ghTerminalsRoot = TreeView_InsertItem(
  520. ghTerminalsWnd,
  521. &tvi
  522. );
  523. //
  524. // calls tree
  525. //
  526. tvi.item.pszText = L"Calls";
  527. ghCallsWnd = GetDlgItem( IDC_CALLS )->m_hWnd;
  528. ghCallsRoot = TreeView_InsertItem(
  529. ghCallsWnd,
  530. &tvi
  531. );
  532. //
  533. // phones tree
  534. //
  535. tvi.item.pszText = L"Phones";
  536. ghPhonesWnd = GetDlgItem( IDC_PHONES )->m_hWnd;
  537. ghPhonesRoot = TreeView_InsertItem(
  538. ghPhonesWnd,
  539. &tvi
  540. );
  541. //
  542. // selected calls tree
  543. //
  544. tvi.item.pszText = L"Selected Calls";
  545. ghSelectedCallsWnd = GetDlgItem( IDC_SELECTEDCALLS )->m_hWnd;
  546. ghSelectedCallsRoot = TreeView_InsertItem(
  547. ghSelectedCallsWnd,
  548. &tvi
  549. );
  550. //
  551. // selected media terminals tree
  552. //
  553. tvi.item.pszText = L"Selected Media Terminals";
  554. ghSelectedWnd = GetDlgItem( IDC_SELECTEDTERMINALS )->m_hWnd;
  555. ghSelectedRoot = TreeView_InsertItem(
  556. ghSelectedWnd,
  557. &tvi
  558. );
  559. //
  560. // dynamic terminal classes tree
  561. //
  562. tvi.item.pszText = L"Dynamic Terminal Classes";
  563. ghClassesWnd = GetDlgItem( IDC_DYNAMICCLASSES )->m_hWnd;
  564. ghClassesRoot = TreeView_InsertItem(
  565. ghClassesWnd,
  566. &tvi
  567. );
  568. //
  569. // created terminals tree
  570. //
  571. tvi.item.pszText = L"Created Terminals";
  572. ghCreatedWnd = GetDlgItem( IDC_CREATEDTERMINALS )->m_hWnd;
  573. ghCreatedRoot = TreeView_InsertItem(
  574. ghCreatedWnd,
  575. &tvi
  576. );
  577. //
  578. // listen mediatypes tree
  579. //
  580. tvi.item.pszText = L"Listen MediaTypes";
  581. ghListenWnd = GetDlgItem( IDC_LISTENMEDIAMODES )->m_hWnd;
  582. ghListenRoot = TreeView_InsertItem(
  583. ghListenWnd,
  584. &tvi
  585. );
  586. }
  587. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  588. //
  589. // OnDestroy
  590. //
  591. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  592. void CT3testDlg::OnDestroy()
  593. {
  594. CDialog::OnDestroy();
  595. gfShuttingDown = TRUE;
  596. //
  597. // Release everything
  598. //
  599. ReleaseMediaTypes();
  600. ReleaseTerminals();
  601. ReleaseCalls();
  602. ReleasePhones();
  603. ReleaseSelectedTerminals();
  604. ReleaseSelectedCalls();
  605. ReleaseCreatedTerminals();
  606. ReleaseTerminalClasses();
  607. ReleaseListen();
  608. ReleaseAddresses();
  609. DataPtrList::iterator iter, end;
  610. iter = gDataPtrList.begin();
  611. end = gDataPtrList.end();
  612. for( ; iter != end; iter++ )
  613. {
  614. FreeData( *iter );
  615. delete (*iter)->pTerminalPtrList;
  616. CoTaskMemFree( *iter );
  617. }
  618. gDataPtrList.clear();
  619. if (NULL != gpCP)
  620. {
  621. gpCP->Unadvise(gulAdvise);
  622. gpCP->Release();
  623. }
  624. //
  625. // shutdown TAPI
  626. //
  627. if (NULL != gpTapi)
  628. {
  629. gpTapi->Shutdown();
  630. gpTapi->Release();
  631. }
  632. }
  633. void
  634. DoAddressCapStuff(ITTAPI * pTapi);
  635. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  636. //
  637. // OnSelChangedAddresses
  638. //
  639. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  640. void CT3testDlg::OnSelchangedAddresses(NMHDR* pNMHDR, LRESULT* pResult)
  641. {
  642. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  643. ITAddress * pAddress;
  644. *pResult = 0;
  645. //
  646. // free all the stuff related to
  647. // the address selected. this stuff
  648. // will all be refilled in
  649. //
  650. ReleaseMediaTypes();
  651. ReleaseListen();
  652. ReleaseCalls();
  653. ReleasePhones();
  654. ReleaseSelectedCalls();
  655. ReleaseSelectedTerminals();
  656. ReleaseCreatedTerminals();
  657. //
  658. // get the currently selected address
  659. //
  660. if (!GetAddress( &pAddress ))
  661. {
  662. return;
  663. }
  664. //
  665. // update these trees
  666. //
  667. if ( !gfShuttingDown )
  668. {
  669. UpdateMediaTypes( pAddress );
  670. UpdateCalls( pAddress );
  671. UpdatePhones( pAddress );
  672. }
  673. }
  674. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  675. //
  676. // OnSelChangedPhones
  677. //
  678. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  679. void CT3testDlg::OnSelchangedPhones(NMHDR* pNMHDR, LRESULT* pResult)
  680. {
  681. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  682. ITPhone * pPhone;
  683. *pResult = 0;
  684. //
  685. // free all the stuff related to
  686. // the phone selected. this stuff
  687. // will all be refilled in
  688. //
  689. ReleaseSelectedCalls();
  690. //
  691. // get the currently selected phone
  692. //
  693. if (!GetPhone( &pPhone ))
  694. {
  695. return;
  696. }
  697. //
  698. // update these trees
  699. //
  700. if ( !gfShuttingDown )
  701. {
  702. UpdateSelectedCalls( pPhone );
  703. }
  704. }
  705. /////////////////////////////////////////////////////////////////
  706. // IsVideoCaptureStream
  707. //
  708. // Returns true if the stream is for video capture
  709. /////////////////////////////////////////////////////////////////
  710. BOOL
  711. CT3testDlg::IsVideoCaptureStream(
  712. ITStream * pStream
  713. )
  714. {
  715. TERMINAL_DIRECTION tdStreamDirection;
  716. long lStreamMediaType;
  717. if ( FAILED( pStream ->get_Direction(&tdStreamDirection) ) ) { return FALSE; }
  718. if ( FAILED( pStream ->get_MediaType(&lStreamMediaType) ) ) { return FALSE; }
  719. return (tdStreamDirection == TD_CAPTURE) &&
  720. (lStreamMediaType == TAPIMEDIATYPE_VIDEO);
  721. }
  722. /////////////////////////////////////////////////////////////////
  723. // EnablePreview
  724. //
  725. // Selects a video render terminal on a video capture stream,
  726. // thereby enabling video preview.
  727. /////////////////////////////////////////////////////////////////
  728. HRESULT
  729. CT3testDlg::EnablePreview(
  730. ITStream * pStream
  731. )
  732. {
  733. ITTerminal * pTerminal;
  734. HRESULT hr = GetVideoRenderTerminal(&pTerminal);
  735. if ( SUCCEEDED(hr) )
  736. {
  737. hr = pStream->SelectTerminal(pTerminal);
  738. pTerminal->Release();
  739. }
  740. return hr;
  741. }
  742. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  743. //
  744. // SelectTerminalOnCall
  745. //
  746. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  747. HRESULT
  748. CT3testDlg::SelectTerminalOnCall(
  749. ITTerminal * pTerminal,
  750. ITCallInfo * pCall
  751. )
  752. {
  753. ITStreamControl * pStreamControl;
  754. TERMINAL_DIRECTION termtd;
  755. long lTermMediaType;
  756. HRESULT hr;
  757. pTerminal->get_Direction( &termtd );
  758. pTerminal->get_MediaType( &lTermMediaType );
  759. hr = pCall->QueryInterface(
  760. IID_ITStreamControl,
  761. (void**) &pStreamControl
  762. );
  763. if ( SUCCEEDED(hr) )
  764. {
  765. IEnumStream * pEnumStreams;
  766. hr = pStreamControl->EnumerateStreams( &pEnumStreams );
  767. if ( SUCCEEDED(hr) )
  768. {
  769. while (TRUE)
  770. {
  771. ITStream * pStream;
  772. long lMediaType;
  773. TERMINAL_DIRECTION td;
  774. hr = pEnumStreams->Next( 1, &pStream, NULL );
  775. if ( S_OK != hr )
  776. {
  777. hr = E_FAIL; // didn't select it anywhere
  778. break;
  779. }
  780. pStream->get_MediaType( &lMediaType );
  781. pStream->get_Direction( &td );
  782. if ( ( lMediaType == lTermMediaType ) &&
  783. ( td == termtd) )
  784. {
  785. hr = pStream->SelectTerminal( pTerminal );
  786. if ( FAILED(hr) )
  787. {
  788. ::MessageBox(NULL, L"SelectTerminals failed", NULL, MB_OK);
  789. }
  790. else
  791. {
  792. //
  793. // Also enable preview on the video capture stream.
  794. //
  795. if ( IsVideoCaptureStream( pStream ) )
  796. {
  797. EnablePreview( pStream );
  798. }
  799. pStream->Release();
  800. break;
  801. }
  802. }
  803. pStream->Release();
  804. }
  805. pEnumStreams->Release();
  806. }
  807. pStreamControl->Release();
  808. }
  809. return hr;
  810. }
  811. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  812. //
  813. // OnAddTerminal
  814. //
  815. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  816. void CT3testDlg::OnAddterminal()
  817. {
  818. ITCallInfo * pCall;
  819. ITTerminal * pTerminal;
  820. HRESULT hr = S_OK;
  821. //
  822. // get the selected call
  823. //
  824. if (!(GetCall( &pCall )))
  825. {
  826. return;
  827. }
  828. //
  829. // get the selected terminal
  830. //
  831. if (!(GetTerminal( &pTerminal )))
  832. {
  833. return;
  834. }
  835. if (S_OK != hr)
  836. {
  837. ::MessageBox(NULL, L"SelectTerminals failed", NULL, MB_OK);
  838. return;
  839. }
  840. hr = SelectTerminalOnCall(pTerminal, pCall);
  841. if ( FAILED(hr) )
  842. {
  843. return;
  844. }
  845. //
  846. // put the terminal in the
  847. // tree
  848. //
  849. AddSelectedTerminal(
  850. pTerminal
  851. );
  852. }
  853. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  854. //
  855. // RemovePreview
  856. //
  857. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  858. void CT3testDlg::RemovePreview( ITStream * pStream )
  859. {
  860. //
  861. // This is a video capture stream and we've unselected the
  862. // video capture terminal. If there is a video render
  863. // terminal on the stream, then unselect it now.
  864. //
  865. IEnumTerminal * pEnum;
  866. if ( FAILED( pStream->EnumerateTerminals( &pEnum ) ) )
  867. {
  868. return;
  869. }
  870. ITTerminal * pTerminal;
  871. if ( S_OK == pEnum->Next(1, &pTerminal, NULL) )
  872. {
  873. pStream->UnselectTerminal( pTerminal );
  874. pTerminal->Release();
  875. }
  876. pEnum->Release();
  877. }
  878. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  879. //
  880. // OnRemoveTerminal
  881. //
  882. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  883. void CT3testDlg::OnRemoveterminal()
  884. {
  885. ITTerminal * pTerminal;
  886. ITCallInfo * pCall;
  887. HTREEITEM hItem;
  888. HRESULT hr;
  889. ITBasicCallControl * pBCC;
  890. //
  891. // get current call
  892. //
  893. if (!GetCall( &pCall ))
  894. {
  895. return;
  896. }
  897. //
  898. // get current terminal
  899. //
  900. if (!GetSelectedTerminal(&pTerminal))
  901. {
  902. return;
  903. }
  904. TERMINAL_DIRECTION termtd;
  905. long lTermMediaType;
  906. pTerminal->get_Direction( &termtd );
  907. pTerminal->get_MediaType( &lTermMediaType );
  908. ITStreamControl * pStreamControl;
  909. hr = pCall->QueryInterface(
  910. IID_ITStreamControl,
  911. (void**) &pStreamControl
  912. );
  913. BOOL bFound = FALSE;
  914. if ( SUCCEEDED(hr) )
  915. {
  916. IEnumStream * pEnumStreams;
  917. hr = pStreamControl->EnumerateStreams( &pEnumStreams );
  918. if ( SUCCEEDED(hr) )
  919. {
  920. while ( ! bFound )
  921. {
  922. ITStream * pStream;
  923. long lMediaType;
  924. TERMINAL_DIRECTION td;
  925. hr = pEnumStreams->Next( 1, &pStream, NULL );
  926. if ( S_OK != hr )
  927. {
  928. break;
  929. }
  930. pStream->get_MediaType( &lMediaType );
  931. pStream->get_Direction( &td );
  932. if ( ( lMediaType == lTermMediaType ) &&
  933. ( td == termtd) )
  934. {
  935. hr = pStream->UnselectTerminal( pTerminal );
  936. if ( !SUCCEEDED(hr) )
  937. {
  938. ::MessageBox(NULL, L"UnselectTerminals failed", NULL, MB_OK);
  939. }
  940. else
  941. {
  942. if ( IsVideoCaptureStream( pStream ) )
  943. {
  944. RemovePreview( pStream );
  945. }
  946. bFound = TRUE;
  947. }
  948. }
  949. pStream->Release();
  950. }
  951. pEnumStreams->Release();
  952. }
  953. pStreamControl->Release();
  954. }
  955. if ( !bFound )
  956. {
  957. return;
  958. }
  959. //
  960. // remove it from tree
  961. //
  962. hItem = TreeView_GetSelection( ghSelectedWnd );
  963. TreeView_DeleteItem(
  964. ghSelectedWnd,
  965. hItem
  966. );
  967. //
  968. // release tree's reference to
  969. // the terminal
  970. //
  971. pTerminal->Release();
  972. }
  973. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  974. //
  975. // OnCreateCall
  976. //
  977. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  978. void CT3testDlg::OnCreatecall()
  979. {
  980. ITAddress * pAddress;
  981. HRESULT hr;
  982. ITBasicCallControl * pCall;
  983. ITCallInfo * pCallInfo;
  984. BOOL bConference = FALSE;
  985. BOOL lAddressType = LINEADDRESSTYPE_PHONENUMBER;
  986. BSTR bstrDestAddress;
  987. ITAddressCapabilities * pAddressCaps;
  988. long lType = 0;
  989. ITMediaSupport * pMediaSupport;
  990. long lSupportedMediaTypes, lMediaTypes = 0;
  991. //
  992. // get the current address
  993. //
  994. if (!GetAddress( &pAddress ))
  995. {
  996. return;
  997. }
  998. hr = pAddress->QueryInterface(IID_ITAddressCapabilities, (void**)&pAddressCaps);
  999. hr = pAddressCaps->get_AddressCapability( AC_ADDRESSTYPES, &lType );
  1000. if ( SUCCEEDED(hr) && (LINEADDRESSTYPE_SDP & lType) )
  1001. {
  1002. bConference = TRUE;
  1003. lAddressType = LINEADDRESSTYPE_SDP;
  1004. }
  1005. if ( SUCCEEDED(hr) && (LINEADDRESSTYPE_DOMAINNAME & lType) )
  1006. {
  1007. lAddressType = LINEADDRESSTYPE_DOMAINNAME;
  1008. }
  1009. pAddressCaps->Release();
  1010. if ( !bConference )
  1011. {
  1012. //
  1013. // create the dialog to get the
  1014. // dial string
  1015. //
  1016. CCreateCallDlg Dlg( this );
  1017. if (IDOK == Dlg.DoModal())
  1018. {
  1019. //
  1020. // create a call with the
  1021. // string input in the dialog
  1022. //
  1023. bstrDestAddress = SysAllocString( Dlg.m_pszDestAddress );
  1024. }
  1025. else
  1026. {
  1027. return;
  1028. }
  1029. }
  1030. else
  1031. {
  1032. CConfDlg Dlg;
  1033. if ( IDOK == Dlg.DoModal() )
  1034. {
  1035. bstrDestAddress = Dlg.m_bstrDestAddress;
  1036. }
  1037. else
  1038. {
  1039. return;
  1040. }
  1041. }
  1042. //
  1043. // Find out if the address supports audio, video, or both.
  1044. //
  1045. pAddress->QueryInterface(
  1046. IID_ITMediaSupport,
  1047. (void**)&pMediaSupport
  1048. );
  1049. pMediaSupport->get_MediaTypes( &lSupportedMediaTypes );
  1050. pMediaSupport->Release();
  1051. if ( lSupportedMediaTypes & TAPIMEDIATYPE_AUDIO )
  1052. {
  1053. lMediaTypes |= TAPIMEDIATYPE_AUDIO;
  1054. }
  1055. if ( lSupportedMediaTypes & TAPIMEDIATYPE_VIDEO )
  1056. {
  1057. lMediaTypes |= TAPIMEDIATYPE_VIDEO;
  1058. }
  1059. if ( lMediaTypes == 0 )
  1060. {
  1061. if ( lSupportedMediaTypes & TAPIMEDIATYPE_DATAMODEM )
  1062. {
  1063. lMediaTypes |= TAPIMEDIATYPE_DATAMODEM;
  1064. }
  1065. }
  1066. //
  1067. // Create the call.
  1068. //
  1069. hr = pAddress->CreateCall(
  1070. bstrDestAddress,
  1071. lAddressType,
  1072. lMediaTypes,
  1073. &pCall
  1074. );
  1075. SysFreeString( bstrDestAddress );
  1076. if (S_OK != hr)
  1077. {
  1078. ::MessageBox(NULL, L"CreateCall failed", NULL, MB_OK);
  1079. return;
  1080. }
  1081. //
  1082. // get the callinfo interface
  1083. //
  1084. pCall->QueryInterface( IID_ITCallInfo, (void **)&pCallInfo );
  1085. //
  1086. // add the call to the tree
  1087. //
  1088. AddCall(pCallInfo);
  1089. //
  1090. // update the callinfo
  1091. //
  1092. UpdateCall( pCallInfo );
  1093. //
  1094. // release this inteface
  1095. //
  1096. pCallInfo->Release();
  1097. //
  1098. // note that we keep a global reference to the call
  1099. // (CreateCall returns with a reference count of 1)
  1100. // so the call does not get destroyed. When we want
  1101. // the call to actually be destroyed, then we
  1102. // release twice.
  1103. //
  1104. }
  1105. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1106. //
  1107. // OnOpenPhone
  1108. //
  1109. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1110. void CT3testDlg::OnOpenPhone()
  1111. {
  1112. ITPhone * pPhone;
  1113. HRESULT hr = S_OK;
  1114. //
  1115. // get the current phone
  1116. //
  1117. if (!GetPhone( &pPhone))
  1118. {
  1119. return;
  1120. }
  1121. //
  1122. // call connect
  1123. //
  1124. hr = pPhone->Open( PP_OWNER );
  1125. if (S_OK != hr)
  1126. {
  1127. ::MessageBox(NULL, L"Open failed", NULL, MB_OK);
  1128. return;
  1129. }
  1130. UpdatePhone( pPhone );
  1131. }
  1132. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1133. //
  1134. // OnClosePhone
  1135. //
  1136. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1137. void CT3testDlg::OnClosePhone()
  1138. {
  1139. ITPhone * pPhone;
  1140. HRESULT hr = S_OK;
  1141. //
  1142. // get the current phone
  1143. //
  1144. if (!GetPhone( &pPhone))
  1145. {
  1146. return;
  1147. }
  1148. //
  1149. // call connect
  1150. //
  1151. hr = pPhone->Close();
  1152. if (S_OK != hr)
  1153. {
  1154. ::MessageBox(NULL, L"Close failed", NULL, MB_OK);
  1155. return;
  1156. }
  1157. UpdatePhone( pPhone );
  1158. }
  1159. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1160. //
  1161. // OnStartTone
  1162. //
  1163. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1164. void CT3testDlg::OnStartTone()
  1165. {
  1166. ITPhone * pPhone;
  1167. ITAutomatedPhoneControl * pPhoneControl;
  1168. HRESULT hr = S_OK;
  1169. //
  1170. // get the current phone
  1171. //
  1172. if (!GetPhone( &pPhone))
  1173. {
  1174. return;
  1175. }
  1176. //
  1177. // get the automated phone control interface
  1178. //
  1179. hr = pPhone->QueryInterface(IID_ITAutomatedPhoneControl, (void **)&pPhoneControl);
  1180. if (S_OK != hr)
  1181. {
  1182. ::MessageBox(NULL, L"QueryInterface failed", NULL, MB_OK);
  1183. return;
  1184. }
  1185. //
  1186. // call connect
  1187. //
  1188. hr = pPhoneControl->StartTone(PT_NORMALDIALTONE, 5000);
  1189. pPhoneControl->Release();
  1190. if (S_OK != hr)
  1191. {
  1192. ::MessageBox(NULL, L"StartTone failed", NULL, MB_OK);
  1193. return;
  1194. }
  1195. }
  1196. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1197. //
  1198. // OnBusyTone
  1199. //
  1200. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1201. void CT3testDlg::OnBusyTone()
  1202. {
  1203. ITPhone * pPhone;
  1204. ITAutomatedPhoneControl * pPhoneControl;
  1205. HRESULT hr = S_OK;
  1206. //
  1207. // get the current phone
  1208. //
  1209. if (!GetPhone( &pPhone))
  1210. {
  1211. return;
  1212. }
  1213. //
  1214. // get the automated phone control interface
  1215. //
  1216. hr = pPhone->QueryInterface(IID_ITAutomatedPhoneControl, (void **)&pPhoneControl);
  1217. if (S_OK != hr)
  1218. {
  1219. ::MessageBox(NULL, L"QueryInterface failed", NULL, MB_OK);
  1220. return;
  1221. }
  1222. //
  1223. // call connect
  1224. //
  1225. hr = pPhoneControl->StartTone(PT_BUSY, 10000);
  1226. pPhoneControl->Release();
  1227. if (S_OK != hr)
  1228. {
  1229. ::MessageBox(NULL, L"StartTone failed", NULL, MB_OK);
  1230. return;
  1231. }
  1232. }
  1233. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1234. //
  1235. // OnRingBackTone
  1236. //
  1237. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1238. void CT3testDlg::OnRingBackTone()
  1239. {
  1240. ITPhone * pPhone;
  1241. ITAutomatedPhoneControl * pPhoneControl;
  1242. HRESULT hr = S_OK;
  1243. //
  1244. // get the current phone
  1245. //
  1246. if (!GetPhone( &pPhone))
  1247. {
  1248. return;
  1249. }
  1250. //
  1251. // get the automated phone control interface
  1252. //
  1253. hr = pPhone->QueryInterface(IID_ITAutomatedPhoneControl, (void **)&pPhoneControl);
  1254. if (S_OK != hr)
  1255. {
  1256. ::MessageBox(NULL, L"QueryInterface failed", NULL, MB_OK);
  1257. return;
  1258. }
  1259. //
  1260. // call connect
  1261. //
  1262. hr = pPhoneControl->StartTone(PT_RINGBACK, 10000);
  1263. pPhoneControl->Release();
  1264. if (S_OK != hr)
  1265. {
  1266. ::MessageBox(NULL, L"StartTone failed", NULL, MB_OK);
  1267. return;
  1268. }
  1269. }
  1270. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1271. //
  1272. // OnErrorTone
  1273. //
  1274. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1275. void CT3testDlg::OnErrorTone()
  1276. {
  1277. ITPhone * pPhone;
  1278. ITAutomatedPhoneControl * pPhoneControl;
  1279. HRESULT hr = S_OK;
  1280. //
  1281. // get the current phone
  1282. //
  1283. if (!GetPhone( &pPhone))
  1284. {
  1285. return;
  1286. }
  1287. //
  1288. // get the automated phone control interface
  1289. //
  1290. hr = pPhone->QueryInterface(IID_ITAutomatedPhoneControl, (void **)&pPhoneControl);
  1291. if (S_OK != hr)
  1292. {
  1293. ::MessageBox(NULL, L"QueryInterface failed", NULL, MB_OK);
  1294. return;
  1295. }
  1296. //
  1297. // call connect
  1298. //
  1299. hr = pPhoneControl->StartTone(PT_ERRORTONE, 10000);
  1300. pPhoneControl->Release();
  1301. if (S_OK != hr)
  1302. {
  1303. ::MessageBox(NULL, L"StartTone failed", NULL, MB_OK);
  1304. return;
  1305. }
  1306. }
  1307. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1308. //
  1309. // OnStopTone
  1310. //
  1311. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1312. void CT3testDlg::OnStopTone()
  1313. {
  1314. ITPhone * pPhone;
  1315. ITAutomatedPhoneControl * pPhoneControl;
  1316. HRESULT hr = S_OK;
  1317. //
  1318. // get the current phone
  1319. //
  1320. if (!GetPhone( &pPhone))
  1321. {
  1322. return;
  1323. }
  1324. //
  1325. // get the automated phone control interface
  1326. //
  1327. hr = pPhone->QueryInterface(IID_ITAutomatedPhoneControl, (void **)&pPhoneControl);
  1328. if (S_OK != hr)
  1329. {
  1330. ::MessageBox(NULL, L"QueryInterface failed", NULL, MB_OK);
  1331. return;
  1332. }
  1333. //
  1334. // call connect
  1335. //
  1336. hr = pPhoneControl->StopTone();
  1337. pPhoneControl->Release();
  1338. if (S_OK != hr)
  1339. {
  1340. ::MessageBox(NULL, L"StopTone failed", NULL, MB_OK);
  1341. return;
  1342. }
  1343. }
  1344. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1345. //
  1346. // OnSelectCall
  1347. //
  1348. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1349. void CT3testDlg::OnSelectCall()
  1350. {
  1351. ITPhone * pPhone;
  1352. ITAutomatedPhoneControl * pPhoneControl;
  1353. ITCallInfo * pCall;
  1354. HRESULT hr = S_OK;
  1355. //
  1356. // get the current phone
  1357. //
  1358. if (!GetPhone( &pPhone))
  1359. {
  1360. return;
  1361. }
  1362. //
  1363. // get the current call
  1364. //
  1365. if (!GetCall( &pCall ))
  1366. {
  1367. return;
  1368. }
  1369. //
  1370. // get the automated phone control interface
  1371. //
  1372. hr = pPhone->QueryInterface(IID_ITAutomatedPhoneControl, (void **)&pPhoneControl);
  1373. if (S_OK != hr)
  1374. {
  1375. ::MessageBox(NULL, L"QueryInterface failed", NULL, MB_OK);
  1376. return;
  1377. }
  1378. hr = pPhoneControl->SelectCall( pCall, VARIANT_TRUE );
  1379. pPhoneControl->Release();
  1380. if (S_OK != hr)
  1381. {
  1382. ::MessageBox(NULL, L"OnSelectCall failed", NULL, MB_OK);
  1383. return;
  1384. }
  1385. //
  1386. // put the call in the
  1387. // tree
  1388. //
  1389. AddSelectedCall(
  1390. pCall
  1391. );
  1392. //
  1393. // add the selected terminals to the tree
  1394. //
  1395. ITTerminal * pTerminal;
  1396. IEnumTerminal * pEnum;
  1397. ITAddress * pAddress;
  1398. if (!GetAddress( &pAddress ))
  1399. {
  1400. return;
  1401. }
  1402. if ( FAILED( pPhone->EnumerateTerminals( pAddress, &pEnum ) ) )
  1403. {
  1404. return;
  1405. }
  1406. while ( S_OK == pEnum->Next(1, &pTerminal, NULL) )
  1407. {
  1408. AddSelectedTerminal( pTerminal );
  1409. pTerminal->Release();
  1410. }
  1411. pEnum->Release();
  1412. }
  1413. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1414. //
  1415. // OnUnselectCall
  1416. //
  1417. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1418. void CT3testDlg::OnUnselectCall()
  1419. {
  1420. ITPhone * pPhone;
  1421. ITAutomatedPhoneControl * pPhoneControl;
  1422. ITCallInfo * pCall;
  1423. HRESULT hr = S_OK;
  1424. HTREEITEM hItem;
  1425. //
  1426. // get the current phone
  1427. //
  1428. if (!GetPhone( &pPhone))
  1429. {
  1430. return;
  1431. }
  1432. //
  1433. // get the selected call
  1434. //
  1435. if (!GetSelectedCall( &pCall ))
  1436. {
  1437. return;
  1438. }
  1439. //
  1440. // get the automated phone control interface
  1441. //
  1442. hr = pPhone->QueryInterface(IID_ITAutomatedPhoneControl, (void **)&pPhoneControl);
  1443. if (S_OK != hr)
  1444. {
  1445. ::MessageBox(NULL, L"QueryInterface failed", NULL, MB_OK);
  1446. return;
  1447. }
  1448. hr = pPhoneControl->UnselectCall( pCall );
  1449. pPhoneControl->Release();
  1450. if (S_OK != hr)
  1451. {
  1452. ::MessageBox(NULL, L"OnUnselectCall failed", NULL, MB_OK);
  1453. return;
  1454. }
  1455. //
  1456. // remove it from tree
  1457. //
  1458. hItem = TreeView_GetSelection( ghSelectedCallsWnd );
  1459. TreeView_DeleteItem(
  1460. ghSelectedCallsWnd,
  1461. hItem
  1462. );
  1463. //
  1464. // release tree's reference to
  1465. // the terminal
  1466. //
  1467. pCall->Release();
  1468. }
  1469. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1470. //
  1471. // OnPhoneAutoOn
  1472. //
  1473. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1474. void CT3testDlg::OnPhoneAutoOn()
  1475. {
  1476. ITPhone * pPhone;
  1477. ITAutomatedPhoneControl * pPhoneControl;
  1478. HRESULT hr = S_OK;
  1479. //
  1480. // get the current phone
  1481. //
  1482. if (!GetPhone( &pPhone))
  1483. {
  1484. return;
  1485. }
  1486. //
  1487. // get the automated phone control interface
  1488. //
  1489. hr = pPhone->QueryInterface(IID_ITAutomatedPhoneControl, (void **)&pPhoneControl);
  1490. if (S_OK != hr)
  1491. {
  1492. ::MessageBox(NULL, L"QueryInterface failed", NULL, MB_OK);
  1493. return;
  1494. }
  1495. hr = pPhoneControl->put_PhoneHandlingEnabled(VARIANT_TRUE);
  1496. pPhoneControl->Release();
  1497. if (S_OK != hr)
  1498. {
  1499. ::MessageBox(NULL, L"OnPhoneAutoOn failed", NULL, MB_OK);
  1500. return;
  1501. }
  1502. }
  1503. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1504. //
  1505. // OnPhoneAutoOff
  1506. //
  1507. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1508. void CT3testDlg::OnPhoneAutoOff()
  1509. {
  1510. ITPhone * pPhone;
  1511. ITAutomatedPhoneControl * pPhoneControl;
  1512. HRESULT hr = S_OK;
  1513. //
  1514. // get the current phone
  1515. //
  1516. if (!GetPhone( &pPhone))
  1517. {
  1518. return;
  1519. }
  1520. //
  1521. // get the automated phone control interface
  1522. //
  1523. hr = pPhone->QueryInterface(IID_ITAutomatedPhoneControl, (void **)&pPhoneControl);
  1524. if (S_OK != hr)
  1525. {
  1526. ::MessageBox(NULL, L"QueryInterface failed", NULL, MB_OK);
  1527. return;
  1528. }
  1529. hr = pPhoneControl->put_PhoneHandlingEnabled(VARIANT_FALSE);
  1530. pPhoneControl->Release();
  1531. if (S_OK != hr)
  1532. {
  1533. ::MessageBox(NULL, L"OnPhoneAutoOff failed", NULL, MB_OK);
  1534. return;
  1535. }
  1536. }
  1537. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1538. //
  1539. // OnPhoneSpeakerOnHook
  1540. //
  1541. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1542. void CT3testDlg::OnPhoneSpeakerOnHook()
  1543. {
  1544. ITPhone * pPhone;
  1545. ITAutomatedPhoneControl * pPhoneControl;
  1546. HRESULT hr = S_OK;
  1547. //
  1548. // get the current phone
  1549. //
  1550. if (!GetPhone( &pPhone))
  1551. {
  1552. return;
  1553. }
  1554. hr = pPhone->put_HookSwitchState( PHSD_SPEAKERPHONE, PHSS_ONHOOK );
  1555. if (S_OK != hr)
  1556. {
  1557. ::MessageBox(NULL, L"OnPhoneSpeakerOnHook failed", NULL, MB_OK);
  1558. return;
  1559. }
  1560. }
  1561. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1562. //
  1563. // OnPhoneSpeakerOffHook
  1564. //
  1565. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1566. void CT3testDlg::OnPhoneSpeakerOffHook()
  1567. {
  1568. ITPhone * pPhone;
  1569. ITAutomatedPhoneControl * pPhoneControl;
  1570. HRESULT hr = S_OK;
  1571. //
  1572. // get the current phone
  1573. //
  1574. if (!GetPhone( &pPhone))
  1575. {
  1576. return;
  1577. }
  1578. hr = pPhone->put_HookSwitchState( PHSD_SPEAKERPHONE, PHSS_OFFHOOK );
  1579. if (S_OK != hr)
  1580. {
  1581. ::MessageBox(NULL, L"OnPhoneSpeakerOffHook failed", NULL, MB_OK);
  1582. return;
  1583. }
  1584. }
  1585. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1586. //
  1587. // OnStartRing
  1588. //
  1589. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1590. void CT3testDlg::OnStartRing()
  1591. {
  1592. ITPhone * pPhone;
  1593. ITAutomatedPhoneControl * pPhoneControl;
  1594. HRESULT hr = S_OK;
  1595. //
  1596. // get the current phone
  1597. //
  1598. if (!GetPhone( &pPhone))
  1599. {
  1600. return;
  1601. }
  1602. //
  1603. // get the automated phone control interface
  1604. //
  1605. hr = pPhone->QueryInterface(IID_ITAutomatedPhoneControl, (void **)&pPhoneControl);
  1606. if (S_OK != hr)
  1607. {
  1608. ::MessageBox(NULL, L"QueryInterface failed", NULL, MB_OK);
  1609. return;
  1610. }
  1611. //
  1612. // call connect
  1613. //
  1614. hr = pPhoneControl->StartRinger(0, 0);
  1615. pPhoneControl->Release();
  1616. if (S_OK != hr)
  1617. {
  1618. ::MessageBox(NULL, L"StartRing failed", NULL, MB_OK);
  1619. return;
  1620. }
  1621. }
  1622. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1623. //
  1624. // OnStopRing
  1625. //
  1626. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1627. void CT3testDlg::OnStopRing()
  1628. {
  1629. ITPhone * pPhone;
  1630. ITAutomatedPhoneControl * pPhoneControl;
  1631. HRESULT hr = S_OK;
  1632. //
  1633. // get the current phone
  1634. //
  1635. if (!GetPhone( &pPhone))
  1636. {
  1637. return;
  1638. }
  1639. //
  1640. // get the automated phone control interface
  1641. //
  1642. hr = pPhone->QueryInterface(IID_ITAutomatedPhoneControl, (void **)&pPhoneControl);
  1643. if (S_OK != hr)
  1644. {
  1645. ::MessageBox(NULL, L"QueryInterface failed", NULL, MB_OK);
  1646. return;
  1647. }
  1648. //
  1649. // call connect
  1650. //
  1651. hr = pPhoneControl->StopRinger();
  1652. pPhoneControl->Release();
  1653. if (S_OK != hr)
  1654. {
  1655. ::MessageBox(NULL, L"StopRing failed", NULL, MB_OK);
  1656. return;
  1657. }
  1658. }
  1659. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1660. //
  1661. // OnConnect
  1662. //
  1663. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1664. void CT3testDlg::OnConnect()
  1665. {
  1666. ITBasicCallControl * pCall;
  1667. ITCallInfo * pCallInfo;
  1668. HRESULT hr = S_OK;
  1669. //
  1670. // get the current call
  1671. //
  1672. if (!GetCall( &pCallInfo))
  1673. {
  1674. return;
  1675. }
  1676. //
  1677. // get the call control interface
  1678. //
  1679. hr = pCallInfo->QueryInterface(IID_ITBasicCallControl, (void **)&pCall);
  1680. if (S_OK != hr)
  1681. {
  1682. ::MessageBox(NULL, L"Connect failed", NULL, MB_OK);
  1683. return;
  1684. }
  1685. //
  1686. // call connect
  1687. //
  1688. hr = pCall->Connect( FALSE );
  1689. //
  1690. // release this interface
  1691. //
  1692. pCall->Release();
  1693. if (S_OK != hr)
  1694. {
  1695. ::MessageBox(NULL, L"Connect failed", NULL, MB_OK);
  1696. return;
  1697. }
  1698. }
  1699. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1700. //
  1701. // OnDrop
  1702. //
  1703. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1704. void CT3testDlg::OnDrop()
  1705. {
  1706. ITBasicCallControl * pCall;
  1707. ITCallInfo * pCallInfo;
  1708. HRESULT hr = S_OK;
  1709. //
  1710. // get the current call
  1711. //
  1712. if (!GetCall( &pCallInfo ))
  1713. {
  1714. return;
  1715. }
  1716. //
  1717. // get the bcc interface
  1718. //
  1719. hr = pCallInfo->QueryInterface(
  1720. IID_ITBasicCallControl,
  1721. (void **)&pCall
  1722. );
  1723. if (S_OK != hr)
  1724. {
  1725. ::MessageBox(NULL, L"Disconnect failed", NULL, MB_OK);
  1726. return;
  1727. }
  1728. //
  1729. // call disconnect
  1730. //
  1731. hr = pCall->Disconnect( DC_NORMAL );
  1732. //
  1733. // release this reference
  1734. //
  1735. pCall->Release();
  1736. if (S_OK != hr)
  1737. {
  1738. ::MessageBox(NULL, L"Disconnect failed", NULL, MB_OK);
  1739. }
  1740. }
  1741. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1742. //
  1743. // OnDrop
  1744. //
  1745. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1746. void CT3testDlg::OnAnswer()
  1747. {
  1748. ITCallInfo * pCallInfo;
  1749. ITBasicCallControl * pCall;
  1750. HRESULT hr = S_OK;
  1751. //
  1752. // get the current call
  1753. //
  1754. if (!GetCall( &pCallInfo))
  1755. {
  1756. return;
  1757. }
  1758. //
  1759. // get the bcc interface
  1760. //
  1761. hr = pCallInfo->QueryInterface(IID_ITBasicCallControl, (void **)&pCall);
  1762. if (S_OK != hr)
  1763. {
  1764. ::MessageBox(NULL, L"Answer failed", NULL, MB_OK);
  1765. return;
  1766. }
  1767. //
  1768. // answer it
  1769. //
  1770. hr = pCall->Answer( );
  1771. //
  1772. // release this interface
  1773. //
  1774. pCall->Release();
  1775. if (S_OK != hr)
  1776. {
  1777. ::MessageBox(NULL, L"Answer failed", NULL, MB_OK);
  1778. }
  1779. }
  1780. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1781. //
  1782. // OnListen
  1783. //
  1784. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1785. void CT3testDlg::OnListen()
  1786. {
  1787. ITAddress * pAddress;
  1788. HRESULT hr = S_OK;
  1789. DWORD dwCookie;
  1790. HTREEITEM hItem;
  1791. long ulRegister;
  1792. DWORD dwMediaMode = 0;
  1793. //
  1794. // get the current address
  1795. //
  1796. if (!GetAddress( &pAddress ))
  1797. {
  1798. return;
  1799. }
  1800. hItem = TreeView_GetChild(
  1801. ghListenWnd,
  1802. ghListenRoot
  1803. );
  1804. while (NULL != hItem)
  1805. {
  1806. TV_ITEM item;
  1807. item.mask = TVIF_HANDLE | TVIF_PARAM;
  1808. item.hItem = hItem;
  1809. //
  1810. // get it
  1811. //
  1812. TreeView_GetItem(
  1813. ghListenWnd,
  1814. &item
  1815. );
  1816. dwMediaMode |= (DWORD)(item.lParam);
  1817. hItem = TreeView_GetNextSibling(
  1818. ghAddressesWnd,
  1819. hItem
  1820. );
  1821. }
  1822. hr = gpTapi->RegisterCallNotifications(
  1823. pAddress,
  1824. VARIANT_TRUE,
  1825. VARIANT_TRUE,
  1826. (long)dwMediaMode,
  1827. gulAdvise,
  1828. &ulRegister
  1829. );
  1830. if (S_OK != hr)
  1831. {
  1832. ::MessageBox(NULL, L"RegisterCallNotifications failed", NULL, MB_OK);
  1833. }
  1834. //
  1835. // release all the mediatypes
  1836. // in the listen tree
  1837. //
  1838. ReleaseListen();
  1839. }
  1840. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1841. //
  1842. // OnSelChangedCalls
  1843. //
  1844. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1845. void CT3testDlg::OnSelchangedCalls(NMHDR* pNMHDR, LRESULT* pResult)
  1846. {
  1847. }
  1848. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1849. //
  1850. // OnRelease()
  1851. //
  1852. // this is called to release all references to a call
  1853. //
  1854. // if a call is selected it has two references - once for
  1855. // the tree control, and once for our global reference.
  1856. // release both here.
  1857. //
  1858. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1859. void CT3testDlg::OnRelease()
  1860. {
  1861. ITCallInfo * pCallInfo;
  1862. //
  1863. // get the call
  1864. //
  1865. if (!GetCall( &pCallInfo ))
  1866. {
  1867. return;
  1868. }
  1869. //
  1870. // these depend on the call,
  1871. // so release them
  1872. //
  1873. ReleaseSelectedTerminals();
  1874. ReleaseCreatedTerminals();
  1875. //
  1876. // delete it from the tree
  1877. //
  1878. DeleteSelectedItem(
  1879. ghCallsWnd
  1880. );
  1881. //
  1882. // release once for the tree view
  1883. //
  1884. pCallInfo->Release();
  1885. //
  1886. // release a second time for our global reference
  1887. //
  1888. pCallInfo->Release();
  1889. }
  1890. void
  1891. CT3testDlg::HelpCreateTerminal(
  1892. ITTerminalSupport * pTerminalSupport,
  1893. BSTR bstrClass,
  1894. long lMediaType,
  1895. TERMINAL_DIRECTION dir
  1896. )
  1897. {
  1898. ITTerminal * pTerminal;
  1899. HRESULT hr;
  1900. //
  1901. // create it
  1902. //
  1903. hr = pTerminalSupport->CreateTerminal(
  1904. bstrClass,
  1905. lMediaType,
  1906. dir,
  1907. &pTerminal
  1908. );
  1909. if (S_OK != hr)
  1910. {
  1911. return;
  1912. }
  1913. //
  1914. // ZoltanS:
  1915. // We do nothing special with our video windows. Just make them visible
  1916. // all the time. If this isn't a video window we just skip this step.
  1917. //
  1918. IVideoWindow * pWindow;
  1919. if ( SUCCEEDED( pTerminal->QueryInterface(IID_IVideoWindow,
  1920. (void **) &pWindow) ) )
  1921. {
  1922. pWindow->put_AutoShow( VARIANT_TRUE );
  1923. pWindow->Release();
  1924. }
  1925. //
  1926. // add the terminal
  1927. //
  1928. AddCreatedTerminal(
  1929. pTerminal
  1930. );
  1931. //
  1932. // release our reference
  1933. //
  1934. pTerminal->Release();
  1935. }
  1936. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1937. //
  1938. // GetVideoRenderTerminal
  1939. //
  1940. // this is used to create a video render terminal for preview
  1941. //
  1942. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1943. HRESULT CT3testDlg::GetVideoRenderTerminal(ITTerminal ** ppTerminal)
  1944. {
  1945. //
  1946. // Get the current address
  1947. //
  1948. ITAddress * pAddress;
  1949. if (!GetAddress( &pAddress ))
  1950. {
  1951. return E_FAIL;
  1952. }
  1953. //
  1954. // get the terminal support interface
  1955. //
  1956. ITTerminalSupport * pTerminalSupport;
  1957. HRESULT hr;
  1958. hr = pAddress->QueryInterface(
  1959. IID_ITTerminalSupport,
  1960. (void **) &pTerminalSupport
  1961. );
  1962. if ( FAILED(hr) )
  1963. {
  1964. return hr;
  1965. }
  1966. //
  1967. // Construct a BSTR for the correct IID.
  1968. //
  1969. LPOLESTR lpTerminalClass;
  1970. hr = StringFromIID(CLSID_VideoWindowTerm,
  1971. &lpTerminalClass);
  1972. BSTR bstrTerminalClass;
  1973. if ( FAILED(hr) )
  1974. {
  1975. pTerminalSupport->Release();
  1976. return hr;
  1977. }
  1978. bstrTerminalClass = SysAllocString ( lpTerminalClass );
  1979. CoTaskMemFree( lpTerminalClass );
  1980. if ( bstrTerminalClass == NULL )
  1981. {
  1982. pTerminalSupport->Release();
  1983. return E_OUTOFMEMORY;
  1984. }
  1985. //
  1986. // create it
  1987. //
  1988. hr = pTerminalSupport->CreateTerminal(
  1989. bstrTerminalClass,
  1990. TAPIMEDIATYPE_VIDEO,
  1991. TD_RENDER,
  1992. ppTerminal
  1993. );
  1994. pTerminalSupport->Release();
  1995. if ( FAILED(hr) )
  1996. {
  1997. *ppTerminal = NULL;
  1998. return hr;
  1999. }
  2000. //
  2001. // We do nothing special with our video windows. Just make them visible
  2002. // all the time.
  2003. //
  2004. IVideoWindow * pWindow;
  2005. if ( FAILED( (*ppTerminal)->QueryInterface(IID_IVideoWindow,
  2006. (void **) &pWindow) ) )
  2007. {
  2008. (*ppTerminal)->Release();
  2009. *ppTerminal = NULL;
  2010. return hr;
  2011. }
  2012. pWindow->put_AutoShow( VARIANT_TRUE );
  2013. pWindow->Release();
  2014. return S_OK;
  2015. }
  2016. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  2017. //
  2018. // OnCreateTerminal
  2019. //
  2020. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  2021. void CT3testDlg::OnCreateTerminal()
  2022. {
  2023. //
  2024. // Get the selected media type.
  2025. //
  2026. long lMediaType;
  2027. if (!GetMediaType( &lMediaType ))
  2028. {
  2029. return;
  2030. }
  2031. //
  2032. // Get the current address
  2033. //
  2034. ITAddress * pAddress;
  2035. if (!GetAddress( &pAddress ))
  2036. {
  2037. return;
  2038. }
  2039. //
  2040. // Get the selected terminal class.
  2041. //
  2042. BSTR bstrClass;
  2043. if (!GetTerminalClass( &bstrClass ))
  2044. {
  2045. return;
  2046. }
  2047. //
  2048. // get the terminal support interface
  2049. //
  2050. ITTerminalSupport * pTerminalSupport;
  2051. HRESULT hr;
  2052. hr = pAddress->QueryInterface(
  2053. IID_ITTerminalSupport,
  2054. (void **) &pTerminalSupport
  2055. );
  2056. if ( FAILED(hr) )
  2057. {
  2058. SysFreeString( bstrClass );
  2059. return;
  2060. }
  2061. //
  2062. // Convert the terminal class from a BSTR to an IID.
  2063. //
  2064. IID iidTerminalClass;
  2065. IIDFromString(
  2066. bstrClass,
  2067. &iidTerminalClass
  2068. );
  2069. //
  2070. // Create and add the terminal.
  2071. //
  2072. if ( CLSID_VideoWindowTerm == iidTerminalClass )
  2073. {
  2074. HelpCreateTerminal(
  2075. pTerminalSupport,
  2076. bstrClass,
  2077. lMediaType,
  2078. TD_RENDER
  2079. );
  2080. }
  2081. //
  2082. // Release references.
  2083. //
  2084. pTerminalSupport->Release();
  2085. SysFreeString(bstrClass);
  2086. }
  2087. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  2088. //
  2089. // OnReleaseTerminal
  2090. //
  2091. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  2092. void CT3testDlg::OnReleaseterminal()
  2093. {
  2094. ITTerminal * pTerminal;
  2095. //
  2096. // get the terminal
  2097. //
  2098. if (GetCreatedTerminal( &pTerminal ))
  2099. {
  2100. //
  2101. // and release it!
  2102. //
  2103. pTerminal->Release();
  2104. //
  2105. // delete it from the tree
  2106. //
  2107. DeleteSelectedItem(
  2108. ghCreatedWnd
  2109. );
  2110. }
  2111. }
  2112. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  2113. //
  2114. // OnAddCreated
  2115. //
  2116. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  2117. void CT3testDlg::OnAddcreated()
  2118. {
  2119. ITTerminal * pTerminal;
  2120. ITCallInfo * pCall;
  2121. HRESULT hr = S_OK;
  2122. ITBasicCallControl * pBCC;
  2123. //
  2124. // get the current call
  2125. //
  2126. if (!(GetCall( &pCall )))
  2127. {
  2128. return;
  2129. }
  2130. //
  2131. // GetCreatedTerminal
  2132. //
  2133. if (!GetCreatedTerminal( &pTerminal ))
  2134. {
  2135. return;
  2136. }
  2137. //
  2138. // Select the terminal on the call.
  2139. //
  2140. hr = SelectTerminalOnCall(pTerminal, pCall);
  2141. if ( FAILED(hr) )
  2142. {
  2143. ::MessageBox(NULL, L"SelectTerminals failed", NULL, MB_OK);
  2144. return;
  2145. }
  2146. //
  2147. // add to the selected window
  2148. //
  2149. AddSelectedTerminal(
  2150. pTerminal
  2151. );
  2152. //
  2153. // delete from the created window
  2154. //
  2155. DeleteSelectedItem(
  2156. ghCreatedWnd
  2157. );
  2158. //
  2159. // release because there was a reference to
  2160. // this terminal in the created wnd
  2161. //
  2162. pTerminal->Release();
  2163. return;
  2164. }
  2165. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  2166. //
  2167. // OnAddNull
  2168. //
  2169. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  2170. void CT3testDlg::OnAddnull()
  2171. {
  2172. return;
  2173. }
  2174. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  2175. //
  2176. // OnAddToListen
  2177. //
  2178. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  2179. void CT3testDlg::OnAddtolisten()
  2180. {
  2181. long lMediaType;
  2182. //
  2183. // get the current mediatype
  2184. //
  2185. if (!GetMediaType( &lMediaType ))
  2186. {
  2187. return;
  2188. }
  2189. //
  2190. // add it
  2191. //
  2192. AddListen( lMediaType );
  2193. }
  2194. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  2195. //
  2196. // OnListenAll
  2197. //
  2198. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  2199. void CT3testDlg::OnListenall()
  2200. {
  2201. ITAddress * pAddress;
  2202. HRESULT hr = S_OK;
  2203. long ulRegister;
  2204. long lMediaType;
  2205. ITMediaSupport * pMediaSupport;
  2206. //
  2207. // get the currently selected address
  2208. //
  2209. if (!GetAddress( &pAddress ))
  2210. {
  2211. return;
  2212. }
  2213. pAddress->QueryInterface(
  2214. IID_ITMediaSupport,
  2215. (void **)&pMediaSupport
  2216. );
  2217. pMediaSupport->get_MediaTypes( &lMediaType );
  2218. //
  2219. // register
  2220. //
  2221. gpTapi->RegisterCallNotifications(
  2222. pAddress,
  2223. TRUE,
  2224. TRUE,
  2225. lMediaType,
  2226. gulAdvise,
  2227. &ulRegister
  2228. );
  2229. if (S_OK != hr)
  2230. {
  2231. ::MessageBox(NULL, L"RegisterCallTypes failed", NULL, MB_OK);
  2232. }
  2233. }
  2234. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  2235. //
  2236. // OnSelChangedMedia
  2237. //
  2238. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  2239. void CT3testDlg::OnSelchangedMediatypes(NMHDR* pNMHDR, LRESULT* pResult)
  2240. {
  2241. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  2242. long lMediaType;
  2243. ITAddress * pAddress;
  2244. HRESULT hr;
  2245. *pResult = 0;
  2246. if (gbUpdatingStuff)
  2247. return;
  2248. //
  2249. // get the current mediatype
  2250. //
  2251. if (!GetMediaType( &lMediaType ))
  2252. {
  2253. return;
  2254. }
  2255. //
  2256. // get the current address
  2257. //
  2258. if (!GetAddress( &pAddress ))
  2259. {
  2260. return;
  2261. }
  2262. //
  2263. // we only show terminals that relate
  2264. // to the selected mediatype
  2265. // so get rid of the old ones
  2266. //
  2267. ReleaseTerminals();
  2268. ReleaseTerminalClasses();
  2269. UpdateTerminals( pAddress, lMediaType );
  2270. UpdateTerminalClasses( pAddress, lMediaType );
  2271. }
  2272. void CT3testDlg::OnRclickSelectedterminals(NMHDR* pNMHDR, LRESULT* pResult)
  2273. {
  2274. POINT pt;
  2275. HTREEITEM hItem;
  2276. TV_HITTESTINFO hittestinfo;
  2277. RECT rc;
  2278. *pResult = 0;
  2279. //
  2280. // get the location of the cursor
  2281. //
  2282. GetCursorPos( &pt );
  2283. //
  2284. // get the control's window
  2285. //
  2286. ::GetWindowRect(
  2287. ghSelectedWnd,
  2288. &rc
  2289. );
  2290. //
  2291. // adjust the point to
  2292. // the child's coords
  2293. //
  2294. hittestinfo.pt.x = pt.x - rc.left;
  2295. hittestinfo.pt.y = pt.y - rc.top;
  2296. //
  2297. // hittest to get the tree view item
  2298. //
  2299. hItem = TreeView_HitTest(
  2300. ghSelectedWnd,
  2301. &hittestinfo
  2302. );
  2303. //
  2304. // only display a menu if the mouse is actually
  2305. // over the item (TVHT_ONITEM)
  2306. //
  2307. if (hItem == NULL || (!(hittestinfo.flags & TVHT_ONITEM)) )
  2308. {
  2309. return;
  2310. }
  2311. //
  2312. // select that item (right clicking will not select
  2313. // by default
  2314. //
  2315. TreeView_Select(
  2316. ghSelectedWnd,
  2317. hItem,
  2318. TVGN_CARET
  2319. );
  2320. CreateSelectedTerminalMenu(
  2321. pt,
  2322. m_hWnd
  2323. );
  2324. }
  2325. #ifdef ENABLE_DIGIT_DETECTION_STUFF
  2326. void CT3testDlg::OnModesSupported()
  2327. {
  2328. ITTerminal * pTerminal;
  2329. ITDigitGenerationTerminal * pDigitGeneration;
  2330. HRESULT hr = S_OK;
  2331. LONG lDigits;
  2332. if (!GetSelectedTerminal(&pTerminal))
  2333. {
  2334. return;
  2335. }
  2336. hr = pTerminal->QueryInterface(
  2337. IID_ITDigitGenerationTerminal,
  2338. (void **) &pDigitGeneration
  2339. );
  2340. if (!SUCCEEDED(hr))
  2341. {
  2342. return;
  2343. }
  2344. pDigitGeneration->get_ModesSupported( &lDigits );
  2345. pDigitGeneration->Release();
  2346. }
  2347. void CT3testDlg::OnGenerate()
  2348. {
  2349. ITTerminal * pTerminal;
  2350. ITDigitGenerationTerminal * pDigitGeneration;
  2351. HRESULT hr = S_OK;
  2352. if (!GetSelectedTerminal(&pTerminal))
  2353. {
  2354. return;
  2355. }
  2356. hr = pTerminal->QueryInterface(
  2357. IID_ITDigitGenerationTerminal,
  2358. (void **) &pDigitGeneration
  2359. );
  2360. if (!SUCCEEDED(hr))
  2361. {
  2362. return;
  2363. }
  2364. hr = pDigitGeneration->Generate(
  2365. L"12345",
  2366. LINEDIGITMODE_DTMF
  2367. );
  2368. pDigitGeneration->Release();
  2369. }
  2370. void CT3testDlg::OnModesSupported2()
  2371. {
  2372. ITTerminal * pTerminal;
  2373. ITDigitDetectionTerminal * pDigitDetection;
  2374. HRESULT hr = S_OK;
  2375. LONG lDigits;
  2376. if (!GetSelectedTerminal(&pTerminal))
  2377. {
  2378. return;
  2379. }
  2380. hr = pTerminal->QueryInterface(
  2381. IID_ITDigitDetectionTerminal,
  2382. (void **) &pDigitDetection
  2383. );
  2384. if (!SUCCEEDED(hr))
  2385. {
  2386. return;
  2387. }
  2388. pDigitDetection->get_ModesSupported( &lDigits );
  2389. pDigitDetection->Release();
  2390. }
  2391. void CT3testDlg::OnStartDetect()
  2392. {
  2393. ITTerminal * pTerminal;
  2394. ITDigitDetectionTerminal * pDigitDetection;
  2395. HRESULT hr = S_OK;
  2396. LONG lDigits;
  2397. ULONG ulAdvise;
  2398. IConnectionPointContainer * pCPC;
  2399. IConnectionPoint * pCP;
  2400. if (!GetSelectedTerminal(&pTerminal))
  2401. {
  2402. return;
  2403. }
  2404. hr = pTerminal->QueryInterface(
  2405. IID_ITDigitDetectionTerminal,
  2406. (void **) &pDigitDetection
  2407. );
  2408. if (!SUCCEEDED(hr))
  2409. {
  2410. return;
  2411. }
  2412. hr = pTerminal->QueryInterface(
  2413. IID_IConnectionPointContainer,
  2414. (void **)&pCPC
  2415. );
  2416. if (!SUCCEEDED(hr))
  2417. {
  2418. pDigitDetection->Release();
  2419. return;
  2420. }
  2421. gpDigitNotification = new CDigitDetectionNotification;
  2422. hr = pCPC->FindConnectionPoint(
  2423. IID_ITDigitDetectionNotification,
  2424. &pCP
  2425. );
  2426. pCPC->Release();
  2427. IUnknown * pUnk;
  2428. gpDigitNotification->QueryInterface(
  2429. IID_IUnknown,
  2430. (void**)&pUnk
  2431. );
  2432. hr = pCP->Advise(
  2433. pUnk,
  2434. &ulAdvise
  2435. );
  2436. pUnk->Release();
  2437. pCP->Release();
  2438. pDigitDetection->StartDetect(LINEDIGITMODE_DTMF);
  2439. pDigitDetection->Release();
  2440. }
  2441. void CT3testDlg::OnStopDetect()
  2442. {
  2443. ITTerminal * pTerminal;
  2444. ITDigitDetectionTerminal * pDigitDetection;
  2445. HRESULT hr = S_OK;
  2446. LONG lDigits;
  2447. if (!GetSelectedTerminal(&pTerminal))
  2448. {
  2449. return;
  2450. }
  2451. hr = pTerminal->QueryInterface(
  2452. IID_ITDigitDetectionTerminal,
  2453. (void **) &pDigitDetection
  2454. );
  2455. if (!SUCCEEDED(hr))
  2456. {
  2457. return;
  2458. }
  2459. pDigitDetection->StopDetect();
  2460. pDigitDetection->Release();
  2461. }
  2462. #endif // ENABLE_DIGIT_DETECTION_STUFF
  2463. void CT3testDlg::OnRclickCalls(NMHDR* pNMHDR, LRESULT* pResult)
  2464. {
  2465. POINT pt;
  2466. HTREEITEM hItem;
  2467. TV_HITTESTINFO hittestinfo;
  2468. RECT rc;
  2469. *pResult = 0;
  2470. //
  2471. // get the location of the cursor
  2472. //
  2473. GetCursorPos( &pt );
  2474. //
  2475. // get the control's window
  2476. //
  2477. ::GetWindowRect(
  2478. ghCallsWnd,
  2479. &rc
  2480. );
  2481. //
  2482. // adjust the point to
  2483. // the child's coords
  2484. //
  2485. hittestinfo.pt.x = pt.x - rc.left;
  2486. hittestinfo.pt.y = pt.y - rc.top;
  2487. //
  2488. // hittest to get the tree view item
  2489. //
  2490. hItem = TreeView_HitTest(
  2491. ghCallsWnd,
  2492. &hittestinfo
  2493. );
  2494. //
  2495. // only display a menu if the mouse is actually
  2496. // over the item (TVHT_ONITEM)
  2497. //
  2498. if (hItem == NULL || (!(hittestinfo.flags & TVHT_ONITEM)) )
  2499. {
  2500. return;
  2501. }
  2502. //
  2503. // select that item (right clicking will not select
  2504. // by default
  2505. //
  2506. TreeView_Select(
  2507. ghCallsWnd,
  2508. hItem,
  2509. TVGN_CARET
  2510. );
  2511. }
  2512. void CT3testDlg::OnConfigAutoAnswer()
  2513. {
  2514. ITAddress * pAddress;
  2515. autoans dlg;
  2516. DataPtrList::iterator dataiter, dataend;
  2517. if (!GetAddress( &pAddress ) )
  2518. {
  2519. return;
  2520. }
  2521. dataiter = gDataPtrList.begin();
  2522. dataend = gDataPtrList.end();
  2523. for ( ; dataiter != dataend; dataiter++ )
  2524. {
  2525. if ( pAddress == (*dataiter)->pAddress )
  2526. {
  2527. break;
  2528. }
  2529. }
  2530. if ( dataiter == dataend )
  2531. {
  2532. return;
  2533. }
  2534. FreeData( (*dataiter) );
  2535. if (IDOK == dlg.DoModal())
  2536. {
  2537. TerminalPtrList::iterator iter, end;
  2538. DWORD dwCount;
  2539. long lRegister;
  2540. HRESULT hr;
  2541. long lMediaType = 0;
  2542. dwCount = dlg.m_TerminalPtrList.size();
  2543. if ( 0 == dwCount )
  2544. {
  2545. return;
  2546. }
  2547. iter = dlg.m_TerminalPtrList.begin();
  2548. end = dlg.m_TerminalPtrList.end();
  2549. for ( ; iter != end ; iter++ )
  2550. {
  2551. long l;
  2552. (*dataiter)->pTerminalPtrList->push_back( *iter );
  2553. if ( NULL != (*iter) )
  2554. {
  2555. (*iter)->get_MediaType( &l );
  2556. lMediaType |= l;
  2557. }
  2558. else
  2559. {
  2560. lMediaType |= (long)LINEMEDIAMODE_VIDEO;
  2561. }
  2562. }
  2563. //
  2564. // call register call types
  2565. //
  2566. hr = gpTapi->RegisterCallNotifications(
  2567. pAddress,
  2568. VARIANT_FALSE,
  2569. VARIANT_TRUE,
  2570. lMediaType,
  2571. 0,
  2572. &lRegister
  2573. );
  2574. }
  2575. }
  2576. void CT3testDlg::FreeData( AADATA * pData )
  2577. {
  2578. TerminalPtrList::iterator iter, end;
  2579. iter = pData->pTerminalPtrList->begin();
  2580. end = pData->pTerminalPtrList->end();
  2581. for ( ; iter != end; iter++ )
  2582. {
  2583. if ( NULL != (*iter) )
  2584. {
  2585. (*iter)->Release();
  2586. }
  2587. }
  2588. pData->pTerminalPtrList->clear();
  2589. }
  2590. void CT3testDlg::OnClose()
  2591. {
  2592. CDialog::OnClose();
  2593. }
  2594. void CT3testDlg::OnILS()
  2595. {
  2596. CILSDlg dlg;
  2597. if (IDOK == dlg.DoModal())
  2598. {
  2599. }
  2600. }
  2601. void CT3testDlg::OnRate()
  2602. {
  2603. CRateDlg dlg;
  2604. ITCallInfo * pCallInfo;
  2605. if ( !GetCall( &pCallInfo ) )
  2606. {
  2607. return;
  2608. }
  2609. if (IDOK == dlg.DoModal() )
  2610. {
  2611. pCallInfo->put_CallInfoLong(CIL_MINRATE, dlg.m_dwMinRate );
  2612. pCallInfo->put_CallInfoLong(CIL_MAXRATE, dlg.m_dwMaxRate );
  2613. }
  2614. }
  2615. void CT3testDlg::OnPark1()
  2616. {
  2617. ITCallInfo * pCall;
  2618. ITBasicCallControl * pBCC;
  2619. HRESULT hr;
  2620. //
  2621. // get the call in question
  2622. //
  2623. if (!GetCall( &pCall ))
  2624. {
  2625. return;
  2626. }
  2627. pCall->QueryInterface(
  2628. IID_ITBasicCallControl,
  2629. (void**)&pBCC
  2630. );
  2631. hr = pBCC->ParkDirect( L"101");
  2632. pBCC->Release();
  2633. }
  2634. void CT3testDlg::OnPark2()
  2635. {
  2636. ITCallInfo * pCall;
  2637. ITBasicCallControl * pBCC;
  2638. HRESULT hr;
  2639. BSTR pAddress;
  2640. //
  2641. // get the call in question
  2642. //
  2643. if (!GetCall( &pCall ))
  2644. {
  2645. return;
  2646. }
  2647. pCall->QueryInterface(
  2648. IID_ITBasicCallControl,
  2649. (void **)&pBCC
  2650. );
  2651. hr = pBCC->ParkIndirect( &pAddress );
  2652. SysFreeString( pAddress );
  2653. pBCC->Release();
  2654. }
  2655. void CT3testDlg::OnHandoff1()
  2656. {
  2657. ITCallInfo * pCall;
  2658. ITBasicCallControl * pBCC;
  2659. HRESULT hr;
  2660. //
  2661. // get the call in question
  2662. //
  2663. if (!GetCall( &pCall ))
  2664. {
  2665. return;
  2666. }
  2667. pCall->QueryInterface(
  2668. IID_ITBasicCallControl,
  2669. (void **)&pBCC
  2670. );
  2671. pBCC->HandoffDirect( L"tb20.exe" );
  2672. pBCC->Release();
  2673. }
  2674. void CT3testDlg::OnHandoff2()
  2675. {
  2676. ITCallInfo * pCall;
  2677. ITBasicCallControl * pBCC;
  2678. HRESULT hr;
  2679. //
  2680. // get the call in question
  2681. //
  2682. if (!GetCall( &pCall ))
  2683. {
  2684. return;
  2685. }
  2686. pCall->QueryInterface(
  2687. IID_ITBasicCallControl,
  2688. (void **)&pBCC
  2689. );
  2690. pBCC->HandoffIndirect( TAPIMEDIATYPE_AUDIO );
  2691. pBCC->Release();
  2692. }
  2693. void CT3testDlg::OnUnpark()
  2694. {
  2695. ITCallInfo * pCall;
  2696. ITBasicCallControl * pBCC;
  2697. HRESULT hr;
  2698. //
  2699. // get the call in question
  2700. //
  2701. if (!GetCall( &pCall ))
  2702. {
  2703. return;
  2704. }
  2705. pCall->QueryInterface(
  2706. IID_ITBasicCallControl,
  2707. (void **)&pBCC
  2708. );
  2709. pBCC->Unpark();
  2710. pBCC->Release();
  2711. }
  2712. void CT3testDlg::OnPickup1()
  2713. {
  2714. ITCallInfo * pCall;
  2715. ITBasicCallControl * pBCC;
  2716. HRESULT hr;
  2717. //
  2718. // get the call in question
  2719. //
  2720. if (!GetCall( &pCall ))
  2721. {
  2722. return;
  2723. }
  2724. pCall->QueryInterface(
  2725. IID_ITBasicCallControl,
  2726. (void **)&pBCC
  2727. );
  2728. pBCC->Pickup( NULL );
  2729. pBCC->Release();
  2730. }
  2731. void CT3testDlg::OnPickup2()
  2732. {
  2733. ITCallInfo * pCall;
  2734. ITBasicCallControl * pBCC;
  2735. HRESULT hr;
  2736. //
  2737. // get the call in question
  2738. //
  2739. if (!GetCall( &pCall ))
  2740. {
  2741. return;
  2742. }
  2743. pCall->QueryInterface(
  2744. IID_ITBasicCallControl,
  2745. (void **)&pBCC
  2746. );
  2747. }