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.

2667 lines
60 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 ghSelectedWnd;
  28. HWND ghCreatedWnd;
  29. HWND ghClassesWnd;
  30. HWND ghListenWnd;
  31. HTREEITEM ghAddressesRoot;
  32. HTREEITEM ghTerminalsRoot;
  33. HTREEITEM ghMediaTypesRoot;
  34. HTREEITEM ghCallsRoot;
  35. HTREEITEM ghSelectedRoot;
  36. HTREEITEM ghCreatedRoot;
  37. HTREEITEM ghClassesRoot;
  38. HTREEITEM ghListenRoot;
  39. #ifdef ENABLE_DIGIT_DETECTION_STUFF
  40. CDigitDetectionNotification * gpDigitNotification;
  41. #endif // ENABLE_DIGIT_DETECTION_STUFF
  42. long gulAdvise;
  43. BOOL gbUpdatingStuff = FALSE;
  44. BOOL gfShuttingDown = FALSE;
  45. DataPtrList gDataPtrList;
  46. extern CT3testApp theApp;
  47. const BSTR TAPIMEDIATYPE_String_Audio = L"{028ED8C2-DC7A-11D0-8ED3-00C04FB6809F}";
  48. const BSTR TAPIMEDIATYPE_String_Video = L"{028ED8C4-DC7A-11D0-8ED3-00C04FB6809F}";
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CAboutDlg dialog used for App About
  51. class CAboutDlg : public CDialog
  52. {
  53. public:
  54. CAboutDlg();
  55. // Dialog Data
  56. //{{AFX_DATA(CAboutDlg)
  57. enum { IDD = IDD_ABOUTBOX };
  58. //}}AFX_DATA
  59. // ClassWizard generated virtual function overrides
  60. //{{AFX_VIRTUAL(CAboutDlg)
  61. protected:
  62. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  63. //}}AFX_VIRTUAL
  64. // Implementation
  65. protected:
  66. //{{AFX_MSG(CAboutDlg)
  67. //}}AFX_MSG
  68. DECLARE_MESSAGE_MAP()
  69. };
  70. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  71. {
  72. //{{AFX_DATA_INIT(CAboutDlg)
  73. //}}AFX_DATA_INIT
  74. }
  75. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  76. {
  77. CDialog::DoDataExchange(pDX);
  78. //{{AFX_DATA_MAP(CAboutDlg)
  79. //}}AFX_DATA_MAP
  80. }
  81. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  82. //{{AFX_MSG_MAP(CAboutDlg)
  83. // No message handlers
  84. //}}AFX_MSG_MAP
  85. END_MESSAGE_MAP()
  86. /////////////////////////////////////////////////////////////////////////////
  87. // CT3testDlg dialog
  88. CT3testDlg::CT3testDlg(CWnd* pParent /*=NULL*/)
  89. : CDialog(CT3testDlg::IDD, pParent)
  90. {
  91. //{{AFX_DATA_INIT(CT3testDlg)
  92. // NOTE: the ClassWizard will add member initialization here
  93. //}}AFX_DATA_INIT
  94. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  95. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  96. }
  97. void CT3testDlg::DoDataExchange(CDataExchange* pDX)
  98. {
  99. CDialog::DoDataExchange(pDX);
  100. //{{AFX_DATA_MAP(CT3testDlg)
  101. // NOTE: the ClassWizard will add DDX and DDV calls here
  102. //}}AFX_DATA_MAP
  103. }
  104. BEGIN_MESSAGE_MAP(CT3testDlg, CDialog)
  105. //{{AFX_MSG_MAP(CT3testDlg)
  106. ON_WM_SYSCOMMAND()
  107. ON_WM_PAINT()
  108. ON_WM_QUERYDRAGICON()
  109. ON_WM_DESTROY()
  110. ON_NOTIFY(TVN_SELCHANGED, IDC_ADDRESSES, OnSelchangedAddresses)
  111. ON_BN_CLICKED(IDC_ADDTERMINAL, OnAddterminal)
  112. ON_BN_CLICKED(IDC_REMOVETERMINAL, OnRemoveterminal)
  113. ON_BN_CLICKED(IDC_CREATECALL, OnCreatecall)
  114. ON_BN_CLICKED(IDC_CONNECT, OnConnect)
  115. ON_BN_CLICKED(IDC_DROP, OnDrop)
  116. ON_BN_CLICKED(IDC_ANSWER, OnAnswer)
  117. ON_BN_CLICKED(IDC_LISTEN, OnListen)
  118. ON_NOTIFY(TVN_SELCHANGED, IDC_CALLS, OnSelchangedCalls)
  119. ON_BN_CLICKED(IDC_RELEASE, OnRelease)
  120. ON_BN_CLICKED(IDC_CREATE, OnCreateTerminal)
  121. ON_BN_CLICKED(IDC_RELEASETERMINAL, OnReleaseterminal)
  122. ON_BN_CLICKED(IDC_ADDCREATED, OnAddcreated)
  123. ON_BN_CLICKED(IDC_ADDNULL, OnAddnull)
  124. ON_BN_CLICKED(IDC_ADDTOLISTEN, OnAddtolisten)
  125. ON_BN_CLICKED(IDC_LISTENALL, OnListenall)
  126. ON_BN_CLICKED(IDC_CONFIGAUTOANSWER, OnConfigAutoAnswer)
  127. ON_BN_CLICKED(IDC_ILS, OnILS)
  128. ON_BN_CLICKED(IDC_RATE, OnRate)
  129. ON_NOTIFY(TVN_SELCHANGED, IDC_MEDIATYPES, OnSelchangedMediatypes)
  130. ON_NOTIFY(NM_RCLICK, IDC_SELECTEDTERMINALS, OnRclickSelectedterminals)
  131. #ifdef ENABLE_DIGIT_DETECTION_STUFF
  132. ON_COMMAND(ID_GENERATE, OnGenerate)
  133. ON_COMMAND(ID_MODESUPPORTED, OnModesSupported)
  134. ON_COMMAND(ID_MODESUPPORTED2, OnModesSupported2)
  135. ON_COMMAND(ID_STARTDETECT, OnStartDetect)
  136. ON_COMMAND(ID_STOPDETECT, OnStopDetect)
  137. #endif // ENABLE_DIGIT_DETECTION_STUFF
  138. ON_COMMAND(ID_PARK1, OnPark1)
  139. ON_COMMAND(ID_PARK2, OnPark2)
  140. ON_COMMAND(ID_HANDOFF1, OnHandoff1)
  141. ON_COMMAND(ID_HANDOFF2, OnHandoff2)
  142. ON_COMMAND(ID_UNPARK, OnUnpark)
  143. ON_COMMAND(ID_PICKUP1, OnPickup1)
  144. ON_COMMAND(ID_PICKUP2, OnPickup2)
  145. ON_WM_CLOSE()
  146. ON_MESSAGE(WM_USER+101, OnTapiEvent)
  147. ON_NOTIFY(NM_RCLICK, IDC_CALLS, OnRclickCalls)
  148. //}}AFX_MSG_MAP
  149. END_MESSAGE_MAP()
  150. /////////////////////////////////////////////////////////////////////////////
  151. // CT3testDlg message handlers
  152. BOOL CT3testDlg::OnInitDialog()
  153. {
  154. CDialog::OnInitDialog();
  155. // IDM_ABOUTBOX must be in the system command range.
  156. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  157. ASSERT(IDM_ABOUTBOX < 0xF000);
  158. CMenu* pSysMenu = GetSystemMenu(FALSE);
  159. if (pSysMenu != NULL)
  160. {
  161. CString strAboutMenu;
  162. strAboutMenu.LoadString(IDS_ABOUTBOX);
  163. if (!strAboutMenu.IsEmpty())
  164. {
  165. pSysMenu->AppendMenu(MF_SEPARATOR);
  166. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  167. }
  168. }
  169. // Set the icon for this dialog. The framework does this automatically
  170. // when the application's main window is not a dialog
  171. SetIcon(m_hIcon, TRUE); // Set big icon
  172. SetIcon(m_hIcon, FALSE); // Set small icon
  173. HRESULT hr;
  174. //
  175. // coinit
  176. //
  177. hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  178. //hr = CoInitialize(NULL);
  179. if (hr != S_OK)
  180. {
  181. MessageBox(L"CoInitialize failed", MB_OK);
  182. return FALSE;
  183. }
  184. //
  185. // create the tapi object
  186. //
  187. hr = CoCreateInstance(
  188. CLSID_TAPI,
  189. NULL,
  190. CLSCTX_INPROC_SERVER,
  191. IID_ITTAPI,
  192. (LPVOID *)&gpTapi
  193. );
  194. if (hr != S_OK)
  195. {
  196. ::MessageBox(NULL, L"CoCreateInstance on TAPI failed", NULL, MB_OK);
  197. return TRUE;
  198. }
  199. //
  200. // initialize tapi
  201. //
  202. hr = gpTapi->Initialize();
  203. if (hr != S_OK)
  204. {
  205. ::MessageBox(NULL, L"TAPI initialize failed", NULL, MB_OK);
  206. gpTapi->Release();
  207. return TRUE;
  208. }
  209. // Set the Event filter to only give us only the events we process
  210. gpTapi->put_EventFilter(TE_CALLNOTIFICATION | \
  211. TE_CALLSTATE | \
  212. TE_CALLHUB | \
  213. TE_CALLMEDIA | \
  214. TE_TAPIOBJECT | \
  215. TE_ADDRESS);
  216. //
  217. // intialize the tree controls
  218. //
  219. InitializeTrees();
  220. //
  221. // intialize the address tree control
  222. //
  223. InitializeAddressTree();
  224. //
  225. // register the main event interface
  226. //
  227. RegisterEventInterface();
  228. //
  229. // register for call notification for
  230. // all addresses for outgoing calls
  231. //
  232. RegisterForCallNotifications();
  233. return TRUE; // return TRUE unless you set the focus to a control
  234. }
  235. void CT3testDlg::OnSysCommand(UINT nID, LPARAM lParam)
  236. {
  237. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  238. {
  239. CAboutDlg dlgAbout;
  240. dlgAbout.DoModal();
  241. }
  242. else
  243. {
  244. CDialog::OnSysCommand(nID, lParam);
  245. }
  246. }
  247. // If you add a minimize button to your dialog, you will need the code below
  248. // to draw the icon. For MFC applications using the document/view model,
  249. // this is automatically done for you by the framework.
  250. void CT3testDlg::OnPaint()
  251. {
  252. if (IsIconic())
  253. {
  254. CPaintDC dc(this); // device context for painting
  255. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  256. // Center icon in client rectangle
  257. int cxIcon = GetSystemMetrics(SM_CXICON);
  258. int cyIcon = GetSystemMetrics(SM_CYICON);
  259. CRect rect;
  260. GetClientRect(&rect);
  261. int x = (rect.Width() - cxIcon + 1) / 2;
  262. int y = (rect.Height() - cyIcon + 1) / 2;
  263. // Draw the icon
  264. dc.DrawIcon(x, y, m_hIcon);
  265. }
  266. else
  267. {
  268. CDialog::OnPaint();
  269. }
  270. }
  271. // The system calls this to obtain the cursor to display while the user drags
  272. // the minimized window.
  273. HCURSOR CT3testDlg::OnQueryDragIcon()
  274. {
  275. return (HCURSOR) m_hIcon;
  276. }
  277. void CT3testDlg::OnFinalRelease()
  278. {
  279. // TODO: Add your specialized code here and/or call the base class
  280. CDialog::OnFinalRelease();
  281. }
  282. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  283. //
  284. // SelectFirstItem
  285. //
  286. // selects the first item under the hroot node in hwnd.
  287. // this is used to make sure that something is selected
  288. // in the window at all times.
  289. //
  290. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  291. void CT3testDlg::SelectFirstItem(
  292. HWND hWnd,
  293. HTREEITEM hRoot
  294. )
  295. {
  296. HTREEITEM hChild;
  297. //
  298. // get the first item
  299. //
  300. hChild = TreeView_GetChild(
  301. hWnd,
  302. hRoot
  303. );
  304. //
  305. // select it
  306. //
  307. TreeView_SelectItem(
  308. hWnd,
  309. hChild
  310. );
  311. }
  312. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  313. //
  314. // DeleteSelectedItem
  315. //
  316. //
  317. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  318. void CT3testDlg::DeleteSelectedItem(
  319. HWND hWnd
  320. )
  321. {
  322. HTREEITEM hItem;
  323. //
  324. // get current selections
  325. //
  326. hItem = TreeView_GetSelection( hWnd );
  327. //
  328. // delete it
  329. //
  330. TreeView_DeleteItem(
  331. hWnd,
  332. hItem
  333. );
  334. }
  335. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  336. //
  337. // InitializeAddressTree
  338. // initialize the address tree control with
  339. // the address objects
  340. //
  341. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  342. void CT3testDlg::InitializeAddressTree()
  343. {
  344. IEnumAddress * pEnumAddress;
  345. ITAddress * pAddress;
  346. HTREEITEM hChild;
  347. HRESULT hr;
  348. long l;
  349. DWORD dwCount = 0;
  350. //
  351. // get the address enumerator
  352. //
  353. hr = gpTapi->EnumerateAddresses( &pEnumAddress );
  354. if (S_OK != hr)
  355. {
  356. gpTapi->Release();
  357. gpTapi = NULL;
  358. return;
  359. }
  360. //
  361. // go through all the address objects
  362. // and add them to the address treecontrol
  363. //
  364. while (TRUE)
  365. {
  366. AADATA * pData;
  367. hr = pEnumAddress->Next( 1, &pAddress, NULL );
  368. if (S_OK != hr)
  369. {
  370. break;
  371. }
  372. AddAddressToTree( pAddress );
  373. pAddress->Release();
  374. pData = (AADATA *)CoTaskMemAlloc( sizeof ( AADATA ) );
  375. pData->pAddress = pAddress;
  376. pData->pTerminalPtrList = new TerminalPtrList;
  377. gDataPtrList.push_back( pData );
  378. dwCount++;
  379. }
  380. //
  381. // release the enumerator
  382. //
  383. pEnumAddress->Release();
  384. //
  385. // select the first item
  386. //
  387. if (dwCount > 0)
  388. {
  389. SelectFirstItem(
  390. ghAddressesWnd,
  391. ghAddressesRoot
  392. );
  393. }
  394. }
  395. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  396. //
  397. // RegisterEventInterface
  398. //
  399. // registers the ITTAPIEventNotification interface
  400. //
  401. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  402. void CT3testDlg::RegisterEventInterface()
  403. {
  404. CTAPIEventNotification * pTAPIEventNotification;
  405. IConnectionPointContainer * pCPC;
  406. IConnectionPoint * pCP;
  407. IUnknown * pUnk;
  408. //
  409. // create the object
  410. //
  411. pTAPIEventNotification = new CTAPIEventNotification;
  412. //
  413. // get the connectionpointcontainer interface
  414. // from the tapi object
  415. //
  416. gpTapi->QueryInterface(
  417. IID_IConnectionPointContainer,
  418. (void **) &pCPC
  419. );
  420. //
  421. // get the connectionpoint we are
  422. // looking for
  423. //
  424. pCPC->FindConnectionPoint(
  425. IID_ITTAPIEventNotification,
  426. &gpCP
  427. );
  428. pCPC->Release();
  429. pTAPIEventNotification->QueryInterface(
  430. IID_IUnknown,
  431. (void **)&pUnk
  432. );
  433. //
  434. // call the advise method to tell tapi
  435. // about the interface
  436. //
  437. gpCP->Advise(
  438. pUnk,
  439. (ULONG *)&gulAdvise
  440. );
  441. //
  442. // release our reference to
  443. // it
  444. //
  445. pUnk->Release();
  446. }
  447. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  448. //
  449. // RegisterForCallNotifications
  450. //
  451. // registers for call state notifications for all
  452. // addresses for outgoing calls
  453. //
  454. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  455. void CT3testDlg::RegisterForCallNotifications()
  456. {
  457. VARIANT var;
  458. var.vt = VT_ARRAY;
  459. var.parray = NULL;
  460. gpTapi->SetCallHubTracking(var, VARIANT_TRUE);
  461. }
  462. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  463. //
  464. // InitializeTrees
  465. //
  466. // Create and labels the tree controls
  467. //
  468. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  469. void CT3testDlg::InitializeTrees()
  470. {
  471. TV_INSERTSTRUCT tvi;
  472. tvi.hParent = TVI_ROOT;
  473. tvi.hInsertAfter = TVI_FIRST;
  474. tvi.item.mask = TVIF_TEXT;
  475. //
  476. // address tree
  477. //
  478. tvi.item.pszText = L"Addresses";
  479. ghAddressesWnd = GetDlgItem( IDC_ADDRESSES )->m_hWnd;
  480. ghAddressesRoot = TreeView_InsertItem(
  481. ghAddressesWnd,
  482. &tvi
  483. );
  484. //
  485. // mediatypes tree
  486. //
  487. tvi.item.pszText = L"MediaTypes";
  488. ghMediaTypesWnd = GetDlgItem( IDC_MEDIATYPES )->m_hWnd;
  489. ghMediaTypesRoot = TreeView_InsertItem(
  490. ghMediaTypesWnd,
  491. &tvi
  492. );
  493. //
  494. // terminals tree
  495. //
  496. tvi.item.pszText = L"Terminals";
  497. ghTerminalsWnd = GetDlgItem( IDC_TERMINALS )->m_hWnd;
  498. ghTerminalsRoot = TreeView_InsertItem(
  499. ghTerminalsWnd,
  500. &tvi
  501. );
  502. //
  503. // calls tree
  504. //
  505. tvi.item.pszText = L"Calls";
  506. ghCallsWnd = GetDlgItem( IDC_CALLS )->m_hWnd;
  507. ghCallsRoot = TreeView_InsertItem(
  508. ghCallsWnd,
  509. &tvi
  510. );
  511. //
  512. // selected media terminals tree
  513. //
  514. tvi.item.pszText = L"Selected Media Terminals";
  515. ghSelectedWnd = GetDlgItem( IDC_SELECTEDTERMINALS )->m_hWnd;
  516. ghSelectedRoot = TreeView_InsertItem(
  517. ghSelectedWnd,
  518. &tvi
  519. );
  520. //
  521. // dynamic terminal classes tree
  522. //
  523. tvi.item.pszText = L"Dynamic Terminal Classes";
  524. ghClassesWnd = GetDlgItem( IDC_DYNAMICCLASSES )->m_hWnd;
  525. ghClassesRoot = TreeView_InsertItem(
  526. ghClassesWnd,
  527. &tvi
  528. );
  529. //
  530. // created terminals tree
  531. //
  532. tvi.item.pszText = L"Created Terminals";
  533. ghCreatedWnd = GetDlgItem( IDC_CREATEDTERMINALS )->m_hWnd;
  534. ghCreatedRoot = TreeView_InsertItem(
  535. ghCreatedWnd,
  536. &tvi
  537. );
  538. //
  539. // listen mediatypes tree
  540. //
  541. tvi.item.pszText = L"Listen MediaTypes";
  542. ghListenWnd = GetDlgItem( IDC_LISTENMEDIAMODES )->m_hWnd;
  543. ghListenRoot = TreeView_InsertItem(
  544. ghListenWnd,
  545. &tvi
  546. );
  547. }
  548. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  549. //
  550. // OnDestroy
  551. //
  552. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  553. void CT3testDlg::OnDestroy()
  554. {
  555. CDialog::OnDestroy();
  556. gfShuttingDown = TRUE;
  557. //
  558. // Release everything
  559. //
  560. ReleaseMediaTypes();
  561. ReleaseTerminals();
  562. ReleaseCalls();
  563. ReleaseSelectedTerminals();
  564. ReleaseCreatedTerminals();
  565. ReleaseTerminalClasses();
  566. ReleaseListen();
  567. ReleaseAddresses();
  568. DataPtrList::iterator iter, end;
  569. iter = gDataPtrList.begin();
  570. end = gDataPtrList.end();
  571. for( ; iter != end; iter++ )
  572. {
  573. FreeData( *iter );
  574. delete (*iter)->pTerminalPtrList;
  575. CoTaskMemFree( *iter );
  576. }
  577. gDataPtrList.clear();
  578. if (NULL != gpCP)
  579. {
  580. gpCP->Unadvise(gulAdvise);
  581. gpCP->Release();
  582. }
  583. //
  584. // shutdown TAPI
  585. //
  586. if (NULL != gpTapi)
  587. {
  588. gpTapi->Shutdown();
  589. gpTapi->Release();
  590. }
  591. }
  592. void
  593. DoAddressCapStuff(ITTAPI * pTapi);
  594. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  595. //
  596. // OnSelChangedAddresses
  597. //
  598. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  599. void CT3testDlg::OnSelchangedAddresses(NMHDR* pNMHDR, LRESULT* pResult)
  600. {
  601. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  602. ITAddress * pAddress;
  603. *pResult = 0;
  604. //
  605. // free all the stuff related to
  606. // the address selected. this stuff
  607. // will all be refilled in
  608. //
  609. ReleaseMediaTypes();
  610. ReleaseListen();
  611. ReleaseCalls();
  612. ReleaseSelectedTerminals();
  613. ReleaseCreatedTerminals();
  614. //
  615. // get the currently selected address
  616. //
  617. if (!GetAddress( &pAddress ))
  618. {
  619. return;
  620. }
  621. //
  622. // update these trees
  623. //
  624. if ( !gfShuttingDown )
  625. {
  626. UpdateMediaTypes( pAddress );
  627. UpdateCalls( pAddress );
  628. }
  629. }
  630. /////////////////////////////////////////////////////////////////
  631. // IsVideoCaptureStream
  632. //
  633. // Returns true if the stream is for video capture
  634. /////////////////////////////////////////////////////////////////
  635. BOOL
  636. CT3testDlg::IsVideoCaptureStream(
  637. ITStream * pStream
  638. )
  639. {
  640. TERMINAL_DIRECTION tdStreamDirection;
  641. long lStreamMediaType;
  642. if ( FAILED( pStream ->get_Direction(&tdStreamDirection) ) ) { return FALSE; }
  643. if ( FAILED( pStream ->get_MediaType(&lStreamMediaType) ) ) { return FALSE; }
  644. return (tdStreamDirection == TD_CAPTURE) &&
  645. (lStreamMediaType == TAPIMEDIATYPE_VIDEO);
  646. }
  647. /////////////////////////////////////////////////////////////////
  648. // EnablePreview
  649. //
  650. // Selects a video render terminal on a video capture stream,
  651. // thereby enabling video preview.
  652. /////////////////////////////////////////////////////////////////
  653. HRESULT
  654. CT3testDlg::EnablePreview(
  655. ITStream * pStream
  656. )
  657. {
  658. ITTerminal * pTerminal;
  659. HRESULT hr = GetVideoRenderTerminal(&pTerminal);
  660. if ( SUCCEEDED(hr) )
  661. {
  662. hr = pStream->SelectTerminal(pTerminal);
  663. pTerminal->Release();
  664. }
  665. return hr;
  666. }
  667. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  668. //
  669. // SelectTerminalOnCall
  670. //
  671. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  672. HRESULT
  673. CT3testDlg::SelectTerminalOnCall(
  674. ITTerminal * pTerminal,
  675. ITCallInfo * pCall
  676. )
  677. {
  678. ITStreamControl * pStreamControl;
  679. TERMINAL_DIRECTION termtd;
  680. long lTermMediaType;
  681. HRESULT hr;
  682. pTerminal->get_Direction( &termtd );
  683. pTerminal->get_MediaType( &lTermMediaType );
  684. hr = pCall->QueryInterface(
  685. IID_ITStreamControl,
  686. (void**) &pStreamControl
  687. );
  688. if ( SUCCEEDED(hr) )
  689. {
  690. IEnumStream * pEnumStreams;
  691. hr = pStreamControl->EnumerateStreams( &pEnumStreams );
  692. if ( SUCCEEDED(hr) )
  693. {
  694. while (TRUE)
  695. {
  696. ITStream * pStream;
  697. long lMediaType;
  698. TERMINAL_DIRECTION td;
  699. hr = pEnumStreams->Next( 1, &pStream, NULL );
  700. if ( S_OK != hr )
  701. {
  702. hr = E_FAIL; // didn't select it anywhere
  703. break;
  704. }
  705. pStream->get_MediaType( &lMediaType );
  706. pStream->get_Direction( &td );
  707. if ( ( lMediaType == lTermMediaType ) &&
  708. ( td == termtd) )
  709. {
  710. hr = pStream->SelectTerminal( pTerminal );
  711. if ( FAILED(hr) )
  712. {
  713. ::MessageBox(NULL, L"SelectTerminals failed", NULL, MB_OK);
  714. }
  715. else
  716. {
  717. //
  718. // Also enable preview on the video capture stream.
  719. //
  720. if ( IsVideoCaptureStream( pStream ) )
  721. {
  722. EnablePreview( pStream );
  723. }
  724. pStream->Release();
  725. break;
  726. }
  727. }
  728. pStream->Release();
  729. }
  730. pEnumStreams->Release();
  731. }
  732. pStreamControl->Release();
  733. }
  734. return hr;
  735. }
  736. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  737. //
  738. // OnAddTerminal
  739. //
  740. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  741. void CT3testDlg::OnAddterminal()
  742. {
  743. ITCallInfo * pCall;
  744. ITTerminal * pTerminal;
  745. HRESULT hr = S_OK;
  746. //
  747. // get the selected call
  748. //
  749. if (!(GetCall( &pCall )))
  750. {
  751. return;
  752. }
  753. //
  754. // get the selected terminal
  755. //
  756. if (!(GetTerminal( &pTerminal )))
  757. {
  758. return;
  759. }
  760. if (S_OK != hr)
  761. {
  762. ::MessageBox(NULL, L"SelectTerminals failed", NULL, MB_OK);
  763. return;
  764. }
  765. hr = SelectTerminalOnCall(pTerminal, pCall);
  766. if ( FAILED(hr) )
  767. {
  768. return;
  769. }
  770. //
  771. // put the terminal in the
  772. // tree
  773. //
  774. AddSelectedTerminal(
  775. pTerminal
  776. );
  777. }
  778. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  779. //
  780. // RemovePreview
  781. //
  782. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  783. void CT3testDlg::RemovePreview( ITStream * pStream )
  784. {
  785. //
  786. // This is a video capture stream and we've unselected the
  787. // video capture terminal. If there is a video render
  788. // terminal on the stream, then unselect it now.
  789. //
  790. IEnumTerminal * pEnum;
  791. if ( FAILED( pStream->EnumerateTerminals( &pEnum ) ) )
  792. {
  793. return;
  794. }
  795. ITTerminal * pTerminal;
  796. if ( S_OK == pEnum->Next(1, &pTerminal, NULL) )
  797. {
  798. pStream->UnselectTerminal( pTerminal );
  799. pTerminal->Release();
  800. }
  801. pEnum->Release();
  802. }
  803. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  804. //
  805. // OnRemoveTerminal
  806. //
  807. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  808. void CT3testDlg::OnRemoveterminal()
  809. {
  810. ITTerminal * pTerminal;
  811. ITCallInfo * pCall;
  812. HTREEITEM hItem;
  813. HRESULT hr;
  814. ITBasicCallControl * pBCC;
  815. //
  816. // get current call
  817. //
  818. if (!GetCall( &pCall ))
  819. {
  820. return;
  821. }
  822. //
  823. // get current terminal
  824. //
  825. if (!GetSelectedTerminal(&pTerminal))
  826. {
  827. return;
  828. }
  829. TERMINAL_DIRECTION termtd;
  830. long lTermMediaType;
  831. pTerminal->get_Direction( &termtd );
  832. pTerminal->get_MediaType( &lTermMediaType );
  833. ITStreamControl * pStreamControl;
  834. hr = pCall->QueryInterface(
  835. IID_ITStreamControl,
  836. (void**) &pStreamControl
  837. );
  838. BOOL bFound = FALSE;
  839. if ( SUCCEEDED(hr) )
  840. {
  841. IEnumStream * pEnumStreams;
  842. hr = pStreamControl->EnumerateStreams( &pEnumStreams );
  843. if ( SUCCEEDED(hr) )
  844. {
  845. while ( ! bFound )
  846. {
  847. ITStream * pStream;
  848. long lMediaType;
  849. TERMINAL_DIRECTION td;
  850. hr = pEnumStreams->Next( 1, &pStream, NULL );
  851. if ( S_OK != hr )
  852. {
  853. break;
  854. }
  855. pStream->get_MediaType( &lMediaType );
  856. pStream->get_Direction( &td );
  857. if ( ( lMediaType == lTermMediaType ) &&
  858. ( td == termtd) )
  859. {
  860. hr = pStream->UnselectTerminal( pTerminal );
  861. if ( !SUCCEEDED(hr) )
  862. {
  863. ::MessageBox(NULL, L"UnselectTerminals failed", NULL, MB_OK);
  864. }
  865. else
  866. {
  867. if ( IsVideoCaptureStream( pStream ) )
  868. {
  869. RemovePreview( pStream );
  870. }
  871. bFound = TRUE;
  872. }
  873. }
  874. pStream->Release();
  875. }
  876. pEnumStreams->Release();
  877. }
  878. pStreamControl->Release();
  879. }
  880. if ( !bFound )
  881. {
  882. return;
  883. }
  884. //
  885. // remove it from tree
  886. //
  887. hItem = TreeView_GetSelection( ghSelectedWnd );
  888. TreeView_DeleteItem(
  889. ghSelectedWnd,
  890. hItem
  891. );
  892. //
  893. // release tree's reference to
  894. // the terminal
  895. //
  896. pTerminal->Release();
  897. }
  898. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  899. //
  900. // OnCreateCall
  901. //
  902. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  903. void CT3testDlg::OnCreatecall()
  904. {
  905. ITAddress * pAddress;
  906. HRESULT hr;
  907. ITBasicCallControl * pCall;
  908. ITCallInfo * pCallInfo;
  909. BOOL bConference = FALSE;
  910. BOOL lAddressType = LINEADDRESSTYPE_PHONENUMBER;
  911. BSTR bstrDestAddress;
  912. ITAddressCapabilities * pAddressCaps;
  913. long lType = 0;
  914. ITMediaSupport * pMediaSupport;
  915. long lSupportedMediaTypes, lMediaTypes = 0;
  916. //
  917. // get the current address
  918. //
  919. if (!GetAddress( &pAddress ))
  920. {
  921. return;
  922. }
  923. hr = pAddress->QueryInterface(IID_ITAddressCapabilities, (void**)&pAddressCaps);
  924. hr = pAddressCaps->get_AddressCapability( AC_ADDRESSTYPES, &lType );
  925. if ( SUCCEEDED(hr) && (LINEADDRESSTYPE_SDP & lType) )
  926. {
  927. bConference = TRUE;
  928. lAddressType = LINEADDRESSTYPE_SDP;
  929. }
  930. if ( SUCCEEDED(hr) && (LINEADDRESSTYPE_DOMAINNAME & lType) )
  931. {
  932. lAddressType = LINEADDRESSTYPE_DOMAINNAME;
  933. }
  934. pAddressCaps->Release();
  935. if ( !bConference )
  936. {
  937. //
  938. // create the dialog to get the
  939. // dial string
  940. //
  941. CCreateCallDlg Dlg( this );
  942. if (IDOK == Dlg.DoModal())
  943. {
  944. //
  945. // create a call with the
  946. // string input in the dialog
  947. //
  948. bstrDestAddress = SysAllocString( Dlg.m_pszDestAddress );
  949. }
  950. else
  951. {
  952. return;
  953. }
  954. }
  955. else
  956. {
  957. CConfDlg Dlg;
  958. if ( IDOK == Dlg.DoModal() )
  959. {
  960. bstrDestAddress = Dlg.m_bstrDestAddress;
  961. }
  962. else
  963. {
  964. return;
  965. }
  966. }
  967. //
  968. // Find out if the address supports audio, video, or both.
  969. //
  970. pAddress->QueryInterface(
  971. IID_ITMediaSupport,
  972. (void**)&pMediaSupport
  973. );
  974. pMediaSupport->get_MediaTypes( &lSupportedMediaTypes );
  975. pMediaSupport->Release();
  976. if ( lSupportedMediaTypes & TAPIMEDIATYPE_AUDIO )
  977. {
  978. lMediaTypes |= TAPIMEDIATYPE_AUDIO;
  979. }
  980. if ( lSupportedMediaTypes & TAPIMEDIATYPE_VIDEO )
  981. {
  982. lMediaTypes |= TAPIMEDIATYPE_VIDEO;
  983. }
  984. if ( lMediaTypes == 0 )
  985. {
  986. if ( lSupportedMediaTypes & TAPIMEDIATYPE_DATAMODEM )
  987. {
  988. lMediaTypes |= TAPIMEDIATYPE_DATAMODEM;
  989. }
  990. }
  991. //
  992. // Create the call.
  993. //
  994. hr = pAddress->CreateCall(
  995. bstrDestAddress,
  996. lAddressType,
  997. lMediaTypes,
  998. &pCall
  999. );
  1000. SysFreeString( bstrDestAddress );
  1001. if (S_OK != hr)
  1002. {
  1003. ::MessageBox(NULL, L"CreateCall failed", NULL, MB_OK);
  1004. return;
  1005. }
  1006. //
  1007. // get the callinfo interface
  1008. //
  1009. pCall->QueryInterface( IID_ITCallInfo, (void **)&pCallInfo );
  1010. //
  1011. // add the call to the tree
  1012. //
  1013. AddCall(pCallInfo);
  1014. //
  1015. // update the callinfo
  1016. //
  1017. UpdateCall( pCallInfo );
  1018. //
  1019. // release this inteface
  1020. //
  1021. pCallInfo->Release();
  1022. //
  1023. // note that we keep a global reference to the call
  1024. // (CreateCall returns with a reference count of 1)
  1025. // so the call does not get destroyed. When we want
  1026. // the call to actually be destroyed, then we
  1027. // release twice.
  1028. //
  1029. }
  1030. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1031. //
  1032. // OnConnect
  1033. //
  1034. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1035. void CT3testDlg::OnConnect()
  1036. {
  1037. ITBasicCallControl * pCall;
  1038. ITCallInfo * pCallInfo;
  1039. HRESULT hr = S_OK;
  1040. //
  1041. // get the current call
  1042. //
  1043. if (!GetCall( &pCallInfo))
  1044. {
  1045. return;
  1046. }
  1047. //
  1048. // get the call control interface
  1049. //
  1050. hr = pCallInfo->QueryInterface(IID_ITBasicCallControl, (void **)&pCall);
  1051. if (S_OK != hr)
  1052. {
  1053. ::MessageBox(NULL, L"Connect failed", NULL, MB_OK);
  1054. return;
  1055. }
  1056. //
  1057. // call connect
  1058. //
  1059. hr = pCall->Connect( FALSE );
  1060. //
  1061. // release this interface
  1062. //
  1063. pCall->Release();
  1064. if (S_OK != hr)
  1065. {
  1066. ::MessageBox(NULL, L"Connect failed", NULL, MB_OK);
  1067. return;
  1068. }
  1069. }
  1070. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1071. //
  1072. // OnDrop
  1073. //
  1074. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1075. void CT3testDlg::OnDrop()
  1076. {
  1077. ITBasicCallControl * pCall;
  1078. ITCallInfo * pCallInfo;
  1079. HRESULT hr = S_OK;
  1080. //
  1081. // get the current call
  1082. //
  1083. if (!GetCall( &pCallInfo ))
  1084. {
  1085. return;
  1086. }
  1087. //
  1088. // get the bcc interface
  1089. //
  1090. hr = pCallInfo->QueryInterface(
  1091. IID_ITBasicCallControl,
  1092. (void **)&pCall
  1093. );
  1094. if (S_OK != hr)
  1095. {
  1096. ::MessageBox(NULL, L"Disconnect failed", NULL, MB_OK);
  1097. return;
  1098. }
  1099. //
  1100. // call disconnect
  1101. //
  1102. hr = pCall->Disconnect( DC_NORMAL );
  1103. //
  1104. // release this reference
  1105. //
  1106. pCall->Release();
  1107. if (S_OK != hr)
  1108. {
  1109. ::MessageBox(NULL, L"Disconnect failed", NULL, MB_OK);
  1110. }
  1111. }
  1112. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1113. //
  1114. // OnDrop
  1115. //
  1116. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1117. void CT3testDlg::OnAnswer()
  1118. {
  1119. ITCallInfo * pCallInfo;
  1120. ITBasicCallControl * pCall;
  1121. HRESULT hr = S_OK;
  1122. //
  1123. // get the current call
  1124. //
  1125. if (!GetCall( &pCallInfo))
  1126. {
  1127. return;
  1128. }
  1129. //
  1130. // get the bcc interface
  1131. //
  1132. hr = pCallInfo->QueryInterface(IID_ITBasicCallControl, (void **)&pCall);
  1133. if (S_OK != hr)
  1134. {
  1135. ::MessageBox(NULL, L"Answer failed", NULL, MB_OK);
  1136. return;
  1137. }
  1138. //
  1139. // answer it
  1140. //
  1141. hr = pCall->Answer( );
  1142. //
  1143. // release this interface
  1144. //
  1145. pCall->Release();
  1146. if (S_OK != hr)
  1147. {
  1148. ::MessageBox(NULL, L"Answer failed", NULL, MB_OK);
  1149. }
  1150. }
  1151. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1152. //
  1153. // OnListen
  1154. //
  1155. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1156. void CT3testDlg::OnListen()
  1157. {
  1158. ITAddress * pAddress;
  1159. HRESULT hr = S_OK;
  1160. DWORD dwCookie;
  1161. HTREEITEM hItem;
  1162. long ulRegister;
  1163. DWORD dwMediaMode = 0;
  1164. //
  1165. // get the current address
  1166. //
  1167. if (!GetAddress( &pAddress ))
  1168. {
  1169. return;
  1170. }
  1171. hItem = TreeView_GetChild(
  1172. ghListenWnd,
  1173. ghListenRoot
  1174. );
  1175. while (NULL != hItem)
  1176. {
  1177. TV_ITEM item;
  1178. item.mask = TVIF_HANDLE | TVIF_PARAM;
  1179. item.hItem = hItem;
  1180. //
  1181. // get it
  1182. //
  1183. TreeView_GetItem(
  1184. ghListenWnd,
  1185. &item
  1186. );
  1187. dwMediaMode |= (DWORD)(item.lParam);
  1188. hItem = TreeView_GetNextSibling(
  1189. ghAddressesWnd,
  1190. hItem
  1191. );
  1192. }
  1193. hr = gpTapi->RegisterCallNotifications(
  1194. pAddress,
  1195. VARIANT_TRUE,
  1196. VARIANT_TRUE,
  1197. (long)dwMediaMode,
  1198. gulAdvise,
  1199. &ulRegister
  1200. );
  1201. if (S_OK != hr)
  1202. {
  1203. ::MessageBox(NULL, L"RegisterCallNotifications failed", NULL, MB_OK);
  1204. }
  1205. //
  1206. // release all the mediatypes
  1207. // in the listen tree
  1208. //
  1209. ReleaseListen();
  1210. }
  1211. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1212. //
  1213. // OnSelChangedCalls
  1214. //
  1215. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1216. void CT3testDlg::OnSelchangedCalls(NMHDR* pNMHDR, LRESULT* pResult)
  1217. {
  1218. }
  1219. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1220. //
  1221. // OnRelease()
  1222. //
  1223. // this is called to release all references to a call
  1224. //
  1225. // if a call is selected it has two references - once for
  1226. // the tree control, and once for our global reference.
  1227. // release both here.
  1228. //
  1229. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1230. void CT3testDlg::OnRelease()
  1231. {
  1232. ITCallInfo * pCallInfo;
  1233. //
  1234. // get the call
  1235. //
  1236. if (!GetCall( &pCallInfo ))
  1237. {
  1238. return;
  1239. }
  1240. //
  1241. // these depend on the call,
  1242. // so release them
  1243. //
  1244. ReleaseSelectedTerminals();
  1245. ReleaseCreatedTerminals();
  1246. //
  1247. // delete it from the tree
  1248. //
  1249. DeleteSelectedItem(
  1250. ghCallsWnd
  1251. );
  1252. //
  1253. // release once for the tree view
  1254. //
  1255. pCallInfo->Release();
  1256. //
  1257. // release a second time for our global reference
  1258. //
  1259. pCallInfo->Release();
  1260. }
  1261. void
  1262. CT3testDlg::HelpCreateTerminal(
  1263. ITTerminalSupport * pTerminalSupport,
  1264. BSTR bstrClass,
  1265. long lMediaType,
  1266. TERMINAL_DIRECTION dir
  1267. )
  1268. {
  1269. ITTerminal * pTerminal;
  1270. HRESULT hr;
  1271. //
  1272. // create it
  1273. //
  1274. hr = pTerminalSupport->CreateTerminal(
  1275. bstrClass,
  1276. lMediaType,
  1277. dir,
  1278. &pTerminal
  1279. );
  1280. if (S_OK != hr)
  1281. {
  1282. return;
  1283. }
  1284. //
  1285. // ZoltanS:
  1286. // We do nothing special with our video windows. Just make them visible
  1287. // all the time. If this isn't a video window we just skip this step.
  1288. //
  1289. IVideoWindow * pWindow;
  1290. if ( SUCCEEDED( pTerminal->QueryInterface(IID_IVideoWindow,
  1291. (void **) &pWindow) ) )
  1292. {
  1293. pWindow->put_AutoShow( VARIANT_TRUE );
  1294. pWindow->Release();
  1295. }
  1296. //
  1297. // add the terminal
  1298. //
  1299. AddCreatedTerminal(
  1300. pTerminal
  1301. );
  1302. //
  1303. // release our reference
  1304. //
  1305. pTerminal->Release();
  1306. }
  1307. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1308. //
  1309. // GetVideoRenderTerminal
  1310. //
  1311. // this is used to create a video render terminal for preview
  1312. //
  1313. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1314. HRESULT CT3testDlg::GetVideoRenderTerminal(ITTerminal ** ppTerminal)
  1315. {
  1316. //
  1317. // Get the current address
  1318. //
  1319. ITAddress * pAddress;
  1320. if (!GetAddress( &pAddress ))
  1321. {
  1322. return E_FAIL;
  1323. }
  1324. //
  1325. // get the terminal support interface
  1326. //
  1327. ITTerminalSupport * pTerminalSupport;
  1328. HRESULT hr;
  1329. hr = pAddress->QueryInterface(
  1330. IID_ITTerminalSupport,
  1331. (void **) &pTerminalSupport
  1332. );
  1333. if ( FAILED(hr) )
  1334. {
  1335. return hr;
  1336. }
  1337. //
  1338. // Construct a BSTR for the correct IID.
  1339. //
  1340. LPOLESTR lpTerminalClass;
  1341. hr = StringFromIID(CLSID_VideoWindowTerm,
  1342. &lpTerminalClass);
  1343. BSTR bstrTerminalClass;
  1344. if ( FAILED(hr) )
  1345. {
  1346. pTerminalSupport->Release();
  1347. return hr;
  1348. }
  1349. bstrTerminalClass = SysAllocString ( lpTerminalClass );
  1350. CoTaskMemFree( lpTerminalClass );
  1351. if ( bstrTerminalClass == NULL )
  1352. {
  1353. pTerminalSupport->Release();
  1354. return E_OUTOFMEMORY;
  1355. }
  1356. //
  1357. // create it
  1358. //
  1359. hr = pTerminalSupport->CreateTerminal(
  1360. bstrTerminalClass,
  1361. TAPIMEDIATYPE_VIDEO,
  1362. TD_RENDER,
  1363. ppTerminal
  1364. );
  1365. pTerminalSupport->Release();
  1366. if ( FAILED(hr) )
  1367. {
  1368. *ppTerminal = NULL;
  1369. return hr;
  1370. }
  1371. //
  1372. // We do nothing special with our video windows. Just make them visible
  1373. // all the time.
  1374. //
  1375. IVideoWindow * pWindow;
  1376. if ( FAILED( (*ppTerminal)->QueryInterface(IID_IVideoWindow,
  1377. (void **) &pWindow) ) )
  1378. {
  1379. (*ppTerminal)->Release();
  1380. *ppTerminal = NULL;
  1381. return hr;
  1382. }
  1383. pWindow->put_AutoShow( VARIANT_TRUE );
  1384. pWindow->Release();
  1385. return S_OK;
  1386. }
  1387. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1388. //
  1389. // OnCreateTerminal
  1390. //
  1391. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1392. void CT3testDlg::OnCreateTerminal()
  1393. {
  1394. //
  1395. // Get the selected media type.
  1396. //
  1397. long lMediaType;
  1398. if (!GetMediaType( &lMediaType ))
  1399. {
  1400. return;
  1401. }
  1402. //
  1403. // Get the current address
  1404. //
  1405. ITAddress * pAddress;
  1406. if (!GetAddress( &pAddress ))
  1407. {
  1408. return;
  1409. }
  1410. //
  1411. // Get the selected terminal class.
  1412. //
  1413. BSTR bstrClass;
  1414. if (!GetTerminalClass( &bstrClass ))
  1415. {
  1416. return;
  1417. }
  1418. //
  1419. // get the terminal support interface
  1420. //
  1421. ITTerminalSupport * pTerminalSupport;
  1422. HRESULT hr;
  1423. hr = pAddress->QueryInterface(
  1424. IID_ITTerminalSupport,
  1425. (void **) &pTerminalSupport
  1426. );
  1427. if ( FAILED(hr) )
  1428. {
  1429. SysFreeString( bstrClass );
  1430. return;
  1431. }
  1432. //
  1433. // Convert the terminal class from a BSTR to an IID.
  1434. //
  1435. IID iidTerminalClass;
  1436. IIDFromString(
  1437. bstrClass,
  1438. &iidTerminalClass
  1439. );
  1440. //
  1441. // Create and add the terminal.
  1442. //
  1443. if ( CLSID_VideoWindowTerm == iidTerminalClass )
  1444. {
  1445. HelpCreateTerminal(
  1446. pTerminalSupport,
  1447. bstrClass,
  1448. lMediaType,
  1449. TD_RENDER
  1450. );
  1451. }
  1452. //
  1453. // Release references.
  1454. //
  1455. pTerminalSupport->Release();
  1456. SysFreeString(bstrClass);
  1457. }
  1458. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1459. //
  1460. // OnReleaseTerminal
  1461. //
  1462. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1463. void CT3testDlg::OnReleaseterminal()
  1464. {
  1465. ITTerminal * pTerminal;
  1466. //
  1467. // get the terminal
  1468. //
  1469. if (GetCreatedTerminal( &pTerminal ))
  1470. {
  1471. //
  1472. // and release it!
  1473. //
  1474. pTerminal->Release();
  1475. //
  1476. // delete it from the tree
  1477. //
  1478. DeleteSelectedItem(
  1479. ghCreatedWnd
  1480. );
  1481. }
  1482. }
  1483. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1484. //
  1485. // OnAddCreated
  1486. //
  1487. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1488. void CT3testDlg::OnAddcreated()
  1489. {
  1490. ITTerminal * pTerminal;
  1491. ITCallInfo * pCall;
  1492. HRESULT hr = S_OK;
  1493. ITBasicCallControl * pBCC;
  1494. //
  1495. // get the current call
  1496. //
  1497. if (!(GetCall( &pCall )))
  1498. {
  1499. return;
  1500. }
  1501. //
  1502. // GetCreatedTerminal
  1503. //
  1504. if (!GetCreatedTerminal( &pTerminal ))
  1505. {
  1506. return;
  1507. }
  1508. //
  1509. // Select the terminal on the call.
  1510. //
  1511. hr = SelectTerminalOnCall(pTerminal, pCall);
  1512. if ( FAILED(hr) )
  1513. {
  1514. ::MessageBox(NULL, L"SelectTerminals failed", NULL, MB_OK);
  1515. return;
  1516. }
  1517. //
  1518. // add to the selected window
  1519. //
  1520. AddSelectedTerminal(
  1521. pTerminal
  1522. );
  1523. //
  1524. // delete from the created window
  1525. //
  1526. DeleteSelectedItem(
  1527. ghCreatedWnd
  1528. );
  1529. //
  1530. // release because there was a reference to
  1531. // this terminal in the created wnd
  1532. //
  1533. pTerminal->Release();
  1534. return;
  1535. }
  1536. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1537. //
  1538. // OnAddNull
  1539. //
  1540. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1541. void CT3testDlg::OnAddnull()
  1542. {
  1543. return;
  1544. }
  1545. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1546. //
  1547. // OnAddToListen
  1548. //
  1549. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1550. void CT3testDlg::OnAddtolisten()
  1551. {
  1552. long lMediaType;
  1553. //
  1554. // get the current mediatype
  1555. //
  1556. if (!GetMediaType( &lMediaType ))
  1557. {
  1558. return;
  1559. }
  1560. //
  1561. // add it
  1562. //
  1563. AddListen( lMediaType );
  1564. }
  1565. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1566. //
  1567. // OnListenAll
  1568. //
  1569. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1570. void CT3testDlg::OnListenall()
  1571. {
  1572. ITAddress * pAddress;
  1573. HRESULT hr = S_OK;
  1574. long ulRegister;
  1575. long lMediaType;
  1576. ITMediaSupport * pMediaSupport;
  1577. //
  1578. // get the currently selected address
  1579. //
  1580. if (!GetAddress( &pAddress ))
  1581. {
  1582. return;
  1583. }
  1584. pAddress->QueryInterface(
  1585. IID_ITMediaSupport,
  1586. (void **)&pMediaSupport
  1587. );
  1588. pMediaSupport->get_MediaTypes( &lMediaType );
  1589. //
  1590. // register
  1591. //
  1592. gpTapi->RegisterCallNotifications(
  1593. pAddress,
  1594. TRUE,
  1595. TRUE,
  1596. lMediaType,
  1597. gulAdvise,
  1598. &ulRegister
  1599. );
  1600. if (S_OK != hr)
  1601. {
  1602. ::MessageBox(NULL, L"RegisterCallTypes failed", NULL, MB_OK);
  1603. }
  1604. }
  1605. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1606. //
  1607. // OnSelChangedMedia
  1608. //
  1609. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=
  1610. void CT3testDlg::OnSelchangedMediatypes(NMHDR* pNMHDR, LRESULT* pResult)
  1611. {
  1612. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  1613. long lMediaType;
  1614. ITAddress * pAddress;
  1615. HRESULT hr;
  1616. *pResult = 0;
  1617. if (gbUpdatingStuff)
  1618. return;
  1619. //
  1620. // get the current mediatype
  1621. //
  1622. if (!GetMediaType( &lMediaType ))
  1623. {
  1624. return;
  1625. }
  1626. //
  1627. // get the current address
  1628. //
  1629. if (!GetAddress( &pAddress ))
  1630. {
  1631. return;
  1632. }
  1633. //
  1634. // we only show terminals that relate
  1635. // to the selected mediatype
  1636. // so get rid of the old ones
  1637. //
  1638. ReleaseTerminals();
  1639. ReleaseTerminalClasses();
  1640. UpdateTerminals( pAddress, lMediaType );
  1641. UpdateTerminalClasses( pAddress, lMediaType );
  1642. }
  1643. void CT3testDlg::OnRclickSelectedterminals(NMHDR* pNMHDR, LRESULT* pResult)
  1644. {
  1645. POINT pt;
  1646. HTREEITEM hItem;
  1647. TV_HITTESTINFO hittestinfo;
  1648. RECT rc;
  1649. *pResult = 0;
  1650. //
  1651. // get the location of the cursor
  1652. //
  1653. GetCursorPos( &pt );
  1654. //
  1655. // get the control's window
  1656. //
  1657. ::GetWindowRect(
  1658. ghSelectedWnd,
  1659. &rc
  1660. );
  1661. //
  1662. // adjust the point to
  1663. // the child's coords
  1664. //
  1665. hittestinfo.pt.x = pt.x - rc.left;
  1666. hittestinfo.pt.y = pt.y - rc.top;
  1667. //
  1668. // hittest to get the tree view item
  1669. //
  1670. hItem = TreeView_HitTest(
  1671. ghSelectedWnd,
  1672. &hittestinfo
  1673. );
  1674. //
  1675. // only display a menu if the mouse is actually
  1676. // over the item (TVHT_ONITEM)
  1677. //
  1678. if (hItem == NULL || (!(hittestinfo.flags & TVHT_ONITEM)) )
  1679. {
  1680. return;
  1681. }
  1682. //
  1683. // select that item (right clicking will not select
  1684. // by default
  1685. //
  1686. TreeView_Select(
  1687. ghSelectedWnd,
  1688. hItem,
  1689. TVGN_CARET
  1690. );
  1691. CreateSelectedTerminalMenu(
  1692. pt,
  1693. m_hWnd
  1694. );
  1695. }
  1696. #ifdef ENABLE_DIGIT_DETECTION_STUFF
  1697. void CT3testDlg::OnModesSupported()
  1698. {
  1699. ITTerminal * pTerminal;
  1700. ITDigitGenerationTerminal * pDigitGeneration;
  1701. HRESULT hr = S_OK;
  1702. LONG lDigits;
  1703. if (!GetSelectedTerminal(&pTerminal))
  1704. {
  1705. return;
  1706. }
  1707. hr = pTerminal->QueryInterface(
  1708. IID_ITDigitGenerationTerminal,
  1709. (void **) &pDigitGeneration
  1710. );
  1711. if (!SUCCEEDED(hr))
  1712. {
  1713. return;
  1714. }
  1715. pDigitGeneration->get_ModesSupported( &lDigits );
  1716. pDigitGeneration->Release();
  1717. }
  1718. void CT3testDlg::OnGenerate()
  1719. {
  1720. ITTerminal * pTerminal;
  1721. ITDigitGenerationTerminal * pDigitGeneration;
  1722. HRESULT hr = S_OK;
  1723. if (!GetSelectedTerminal(&pTerminal))
  1724. {
  1725. return;
  1726. }
  1727. hr = pTerminal->QueryInterface(
  1728. IID_ITDigitGenerationTerminal,
  1729. (void **) &pDigitGeneration
  1730. );
  1731. if (!SUCCEEDED(hr))
  1732. {
  1733. return;
  1734. }
  1735. hr = pDigitGeneration->Generate(
  1736. L"12345",
  1737. LINEDIGITMODE_DTMF
  1738. );
  1739. pDigitGeneration->Release();
  1740. }
  1741. void CT3testDlg::OnModesSupported2()
  1742. {
  1743. ITTerminal * pTerminal;
  1744. ITDigitDetectionTerminal * pDigitDetection;
  1745. HRESULT hr = S_OK;
  1746. LONG lDigits;
  1747. if (!GetSelectedTerminal(&pTerminal))
  1748. {
  1749. return;
  1750. }
  1751. hr = pTerminal->QueryInterface(
  1752. IID_ITDigitDetectionTerminal,
  1753. (void **) &pDigitDetection
  1754. );
  1755. if (!SUCCEEDED(hr))
  1756. {
  1757. return;
  1758. }
  1759. pDigitDetection->get_ModesSupported( &lDigits );
  1760. pDigitDetection->Release();
  1761. }
  1762. void CT3testDlg::OnStartDetect()
  1763. {
  1764. ITTerminal * pTerminal;
  1765. ITDigitDetectionTerminal * pDigitDetection;
  1766. HRESULT hr = S_OK;
  1767. LONG lDigits;
  1768. ULONG ulAdvise;
  1769. IConnectionPointContainer * pCPC;
  1770. IConnectionPoint * pCP;
  1771. if (!GetSelectedTerminal(&pTerminal))
  1772. {
  1773. return;
  1774. }
  1775. hr = pTerminal->QueryInterface(
  1776. IID_ITDigitDetectionTerminal,
  1777. (void **) &pDigitDetection
  1778. );
  1779. if (!SUCCEEDED(hr))
  1780. {
  1781. return;
  1782. }
  1783. hr = pTerminal->QueryInterface(
  1784. IID_IConnectionPointContainer,
  1785. (void **)&pCPC
  1786. );
  1787. if (!SUCCEEDED(hr))
  1788. {
  1789. pDigitDetection->Release();
  1790. return;
  1791. }
  1792. gpDigitNotification = new CDigitDetectionNotification;
  1793. hr = pCPC->FindConnectionPoint(
  1794. IID_ITDigitDetectionNotification,
  1795. &pCP
  1796. );
  1797. pCPC->Release();
  1798. IUnknown * pUnk;
  1799. gpDigitNotification->QueryInterface(
  1800. IID_IUnknown,
  1801. (void**)&pUnk
  1802. );
  1803. hr = pCP->Advise(
  1804. pUnk,
  1805. &ulAdvise
  1806. );
  1807. pUnk->Release();
  1808. pCP->Release();
  1809. pDigitDetection->StartDetect(LINEDIGITMODE_DTMF);
  1810. pDigitDetection->Release();
  1811. }
  1812. void CT3testDlg::OnStopDetect()
  1813. {
  1814. ITTerminal * pTerminal;
  1815. ITDigitDetectionTerminal * pDigitDetection;
  1816. HRESULT hr = S_OK;
  1817. LONG lDigits;
  1818. if (!GetSelectedTerminal(&pTerminal))
  1819. {
  1820. return;
  1821. }
  1822. hr = pTerminal->QueryInterface(
  1823. IID_ITDigitDetectionTerminal,
  1824. (void **) &pDigitDetection
  1825. );
  1826. if (!SUCCEEDED(hr))
  1827. {
  1828. return;
  1829. }
  1830. pDigitDetection->StopDetect();
  1831. pDigitDetection->Release();
  1832. }
  1833. #endif // ENABLE_DIGIT_DETECTION_STUFF
  1834. void CT3testDlg::OnRclickCalls(NMHDR* pNMHDR, LRESULT* pResult)
  1835. {
  1836. POINT pt;
  1837. HTREEITEM hItem;
  1838. TV_HITTESTINFO hittestinfo;
  1839. RECT rc;
  1840. *pResult = 0;
  1841. //
  1842. // get the location of the cursor
  1843. //
  1844. GetCursorPos( &pt );
  1845. //
  1846. // get the control's window
  1847. //
  1848. ::GetWindowRect(
  1849. ghCallsWnd,
  1850. &rc
  1851. );
  1852. //
  1853. // adjust the point to
  1854. // the child's coords
  1855. //
  1856. hittestinfo.pt.x = pt.x - rc.left;
  1857. hittestinfo.pt.y = pt.y - rc.top;
  1858. //
  1859. // hittest to get the tree view item
  1860. //
  1861. hItem = TreeView_HitTest(
  1862. ghCallsWnd,
  1863. &hittestinfo
  1864. );
  1865. //
  1866. // only display a menu if the mouse is actually
  1867. // over the item (TVHT_ONITEM)
  1868. //
  1869. if (hItem == NULL || (!(hittestinfo.flags & TVHT_ONITEM)) )
  1870. {
  1871. return;
  1872. }
  1873. //
  1874. // select that item (right clicking will not select
  1875. // by default
  1876. //
  1877. TreeView_Select(
  1878. ghCallsWnd,
  1879. hItem,
  1880. TVGN_CARET
  1881. );
  1882. }
  1883. void CT3testDlg::OnConfigAutoAnswer()
  1884. {
  1885. ITAddress * pAddress;
  1886. autoans dlg;
  1887. DataPtrList::iterator dataiter, dataend;
  1888. if (!GetAddress( &pAddress ) )
  1889. {
  1890. return;
  1891. }
  1892. dataiter = gDataPtrList.begin();
  1893. dataend = gDataPtrList.end();
  1894. for ( ; dataiter != dataend; dataiter++ )
  1895. {
  1896. if ( pAddress == (*dataiter)->pAddress )
  1897. {
  1898. break;
  1899. }
  1900. }
  1901. if ( dataiter == dataend )
  1902. {
  1903. return;
  1904. }
  1905. FreeData( (*dataiter) );
  1906. if (IDOK == dlg.DoModal())
  1907. {
  1908. TerminalPtrList::iterator iter, end;
  1909. DWORD dwCount;
  1910. long lRegister;
  1911. HRESULT hr;
  1912. long lMediaType = 0;
  1913. dwCount = dlg.m_TerminalPtrList.size();
  1914. if ( 0 == dwCount )
  1915. {
  1916. return;
  1917. }
  1918. iter = dlg.m_TerminalPtrList.begin();
  1919. end = dlg.m_TerminalPtrList.end();
  1920. for ( ; iter != end ; iter++ )
  1921. {
  1922. long l;
  1923. (*dataiter)->pTerminalPtrList->push_back( *iter );
  1924. if ( NULL != (*iter) )
  1925. {
  1926. (*iter)->get_MediaType( &l );
  1927. lMediaType |= l;
  1928. }
  1929. else
  1930. {
  1931. lMediaType |= (long)LINEMEDIAMODE_VIDEO;
  1932. }
  1933. }
  1934. //
  1935. // call register call types
  1936. //
  1937. hr = gpTapi->RegisterCallNotifications(
  1938. pAddress,
  1939. VARIANT_FALSE,
  1940. VARIANT_TRUE,
  1941. lMediaType,
  1942. 0,
  1943. &lRegister
  1944. );
  1945. }
  1946. }
  1947. void CT3testDlg::FreeData( AADATA * pData )
  1948. {
  1949. TerminalPtrList::iterator iter, end;
  1950. iter = pData->pTerminalPtrList->begin();
  1951. end = pData->pTerminalPtrList->end();
  1952. for ( ; iter != end; iter++ )
  1953. {
  1954. if ( NULL != (*iter) )
  1955. {
  1956. (*iter)->Release();
  1957. }
  1958. }
  1959. pData->pTerminalPtrList->clear();
  1960. }
  1961. void CT3testDlg::OnClose()
  1962. {
  1963. CDialog::OnClose();
  1964. }
  1965. void CT3testDlg::OnILS()
  1966. {
  1967. CILSDlg dlg;
  1968. if (IDOK == dlg.DoModal())
  1969. {
  1970. }
  1971. }
  1972. void CT3testDlg::OnRate()
  1973. {
  1974. CRateDlg dlg;
  1975. ITCallInfo * pCallInfo;
  1976. if ( !GetCall( &pCallInfo ) )
  1977. {
  1978. return;
  1979. }
  1980. if (IDOK == dlg.DoModal() )
  1981. {
  1982. pCallInfo->put_CallInfoLong(CIL_MINRATE, dlg.m_dwMinRate );
  1983. pCallInfo->put_CallInfoLong(CIL_MAXRATE, dlg.m_dwMaxRate );
  1984. }
  1985. }
  1986. void CT3testDlg::OnPark1()
  1987. {
  1988. ITCallInfo * pCall;
  1989. ITBasicCallControl * pBCC;
  1990. HRESULT hr;
  1991. //
  1992. // get the call in question
  1993. //
  1994. if (!GetCall( &pCall ))
  1995. {
  1996. return;
  1997. }
  1998. pCall->QueryInterface(
  1999. IID_ITBasicCallControl,
  2000. (void**)&pBCC
  2001. );
  2002. hr = pBCC->ParkDirect( L"101");
  2003. pBCC->Release();
  2004. }
  2005. void CT3testDlg::OnPark2()
  2006. {
  2007. ITCallInfo * pCall;
  2008. ITBasicCallControl * pBCC;
  2009. HRESULT hr;
  2010. BSTR pAddress;
  2011. //
  2012. // get the call in question
  2013. //
  2014. if (!GetCall( &pCall ))
  2015. {
  2016. return;
  2017. }
  2018. pCall->QueryInterface(
  2019. IID_ITBasicCallControl,
  2020. (void **)&pBCC
  2021. );
  2022. hr = pBCC->ParkIndirect( &pAddress );
  2023. SysFreeString( pAddress );
  2024. pBCC->Release();
  2025. }
  2026. void CT3testDlg::OnHandoff1()
  2027. {
  2028. ITCallInfo * pCall;
  2029. ITBasicCallControl * pBCC;
  2030. HRESULT hr;
  2031. //
  2032. // get the call in question
  2033. //
  2034. if (!GetCall( &pCall ))
  2035. {
  2036. return;
  2037. }
  2038. pCall->QueryInterface(
  2039. IID_ITBasicCallControl,
  2040. (void **)&pBCC
  2041. );
  2042. pBCC->HandoffDirect( L"tb20.exe" );
  2043. pBCC->Release();
  2044. }
  2045. void CT3testDlg::OnHandoff2()
  2046. {
  2047. ITCallInfo * pCall;
  2048. ITBasicCallControl * pBCC;
  2049. HRESULT hr;
  2050. //
  2051. // get the call in question
  2052. //
  2053. if (!GetCall( &pCall ))
  2054. {
  2055. return;
  2056. }
  2057. pCall->QueryInterface(
  2058. IID_ITBasicCallControl,
  2059. (void **)&pBCC
  2060. );
  2061. pBCC->HandoffIndirect( TAPIMEDIATYPE_AUDIO );
  2062. pBCC->Release();
  2063. }
  2064. void CT3testDlg::OnUnpark()
  2065. {
  2066. ITCallInfo * pCall;
  2067. ITBasicCallControl * pBCC;
  2068. HRESULT hr;
  2069. //
  2070. // get the call in question
  2071. //
  2072. if (!GetCall( &pCall ))
  2073. {
  2074. return;
  2075. }
  2076. pCall->QueryInterface(
  2077. IID_ITBasicCallControl,
  2078. (void **)&pBCC
  2079. );
  2080. pBCC->Unpark();
  2081. pBCC->Release();
  2082. }
  2083. void CT3testDlg::OnPickup1()
  2084. {
  2085. ITCallInfo * pCall;
  2086. ITBasicCallControl * pBCC;
  2087. HRESULT hr;
  2088. //
  2089. // get the call in question
  2090. //
  2091. if (!GetCall( &pCall ))
  2092. {
  2093. return;
  2094. }
  2095. pCall->QueryInterface(
  2096. IID_ITBasicCallControl,
  2097. (void **)&pBCC
  2098. );
  2099. pBCC->Pickup( NULL );
  2100. pBCC->Release();
  2101. }
  2102. void CT3testDlg::OnPickup2()
  2103. {
  2104. ITCallInfo * pCall;
  2105. ITBasicCallControl * pBCC;
  2106. HRESULT hr;
  2107. //
  2108. // get the call in question
  2109. //
  2110. if (!GetCall( &pCall ))
  2111. {
  2112. return;
  2113. }
  2114. pCall->QueryInterface(
  2115. IID_ITBasicCallControl,
  2116. (void **)&pBCC
  2117. );
  2118. }