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.

168 lines
4.8 KiB

  1. // DlgDevices.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ConfigTest.h"
  5. #include "DlgDevices.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. typedef unsigned long ULONG_PTR, *PULONG_PTR;
  12. typedef ULONG_PTR DWORD_PTR, *PDWORD_PTR;
  13. #include "..\..\..\inc\fxsapip.h"
  14. #include "DlgDevice.h"
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CDlgDevices dialog
  17. CDlgDevices::CDlgDevices(HANDLE hFax, CWnd* pParent /*=NULL*/)
  18. : CDialog(CDlgDevices::IDD, pParent), m_hFax (hFax)
  19. {
  20. //{{AFX_DATA_INIT(CDlgDevices)
  21. m_cstrNumDevices = _T("0");
  22. //}}AFX_DATA_INIT
  23. }
  24. void CDlgDevices::DoDataExchange(CDataExchange* pDX)
  25. {
  26. CDialog::DoDataExchange(pDX);
  27. //{{AFX_DATA_MAP(CDlgDevices)
  28. DDX_Control(pDX, IDC_DEVS, m_lstDevices);
  29. DDX_Text(pDX, IDC_NUMDEVS, m_cstrNumDevices);
  30. //}}AFX_DATA_MAP
  31. }
  32. BEGIN_MESSAGE_MAP(CDlgDevices, CDialog)
  33. //{{AFX_MSG_MAP(CDlgDevices)
  34. ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
  35. ON_NOTIFY(NM_DBLCLK, IDC_DEVS, OnDblclkDevs)
  36. //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CDlgDevices message handlers
  40. BOOL CDlgDevices::OnInitDialog()
  41. {
  42. CDialog::OnInitDialog();
  43. m_lstDevices.InsertColumn (0, "Device id");
  44. m_lstDevices.InsertColumn (1, "Device name");
  45. m_lstDevices.InsertColumn (2, "Description");
  46. m_lstDevices.InsertColumn (3, "Provider name");
  47. m_lstDevices.InsertColumn (4, "Provider GUID");
  48. m_lstDevices.InsertColumn (5, "Send");
  49. m_lstDevices.InsertColumn (6, "Receive");
  50. m_lstDevices.InsertColumn (7, "Rings");
  51. m_lstDevices.InsertColumn (8, "Csid");
  52. m_lstDevices.InsertColumn (9, "Tsid");
  53. CHeaderCtrl* pHeader = (CHeaderCtrl*)m_lstDevices.GetDlgItem(0);
  54. DWORD dwCount = pHeader->GetItemCount();
  55. for (DWORD col = 0; col <= dwCount; col++)
  56. {
  57. m_lstDevices.SetColumnWidth(col, LVSCW_AUTOSIZE);
  58. int wc1 = m_lstDevices.GetColumnWidth(col);
  59. m_lstDevices.SetColumnWidth(col,LVSCW_AUTOSIZE_USEHEADER);
  60. int wc2 = m_lstDevices.GetColumnWidth(col);
  61. int wc = max(20,max(wc1,wc2));
  62. m_lstDevices.SetColumnWidth(col,wc);
  63. }
  64. OnRefresh();
  65. return TRUE; // return TRUE unless you set the focus to a control
  66. // EXCEPTION: OCX Property Pages should return FALSE
  67. }
  68. void CDlgDevices::OnRefresh()
  69. {
  70. PFAX_PORT_INFO_EX pDevices;
  71. DWORD dwNumDevices;
  72. CString cs;
  73. m_lstDevices.DeleteAllItems();
  74. if (!FaxEnumPortsEx (m_hFax, &pDevices, &dwNumDevices))
  75. {
  76. CString cs;
  77. cs.Format ("Failed while calling FaxEnumPortsEx (%ld)", GetLastError());
  78. AfxMessageBox (cs, MB_OK | MB_ICONHAND);
  79. return;
  80. }
  81. for (DWORD dw = 0; dw < dwNumDevices; dw++)
  82. {
  83. //
  84. // Insert device id
  85. //
  86. cs.Format ("%08x", pDevices[dw].dwDeviceID);
  87. int iIndex = m_lstDevices.InsertItem (0, cs);
  88. m_lstDevices.SetItemData (iIndex, pDevices[dw].dwDeviceID);
  89. //
  90. // Insert device name
  91. //
  92. m_lstDevices.SetItemText (iIndex, 1, pDevices[dw].lpctstrDeviceName);
  93. //
  94. // Insert device description
  95. //
  96. m_lstDevices.SetItemText (iIndex, 2, pDevices[dw].lptstrDescription);
  97. //
  98. // Insert provider name
  99. //
  100. m_lstDevices.SetItemText (iIndex, 3, pDevices[dw].lpctstrProviderName);
  101. //
  102. // Insert provider GUID
  103. //
  104. m_lstDevices.SetItemText (iIndex, 4, pDevices[dw].lpctstrProviderGUID);
  105. //
  106. // Insert send flag
  107. //
  108. cs.Format ("%s", pDevices[dw].bSend ? "Yes" : "No");
  109. m_lstDevices.SetItemText (iIndex, 5, cs);
  110. //
  111. // Insert receive flag
  112. //
  113. cs.Format ("%s", pDevices[dw].ReceiveMode != FAX_DEVICE_RECEIVE_MODE_OFF ? "Yes" : "No");
  114. m_lstDevices.SetItemText (iIndex, 6, cs);
  115. //
  116. // Insert rings count
  117. //
  118. cs.Format ("%ld", pDevices[dw].dwRings);
  119. m_lstDevices.SetItemText (iIndex, 7, cs);
  120. //
  121. // Insert Csid
  122. //
  123. m_lstDevices.SetItemText (iIndex, 8, pDevices[dw].lptstrCsid);
  124. //
  125. // Insert Tsid
  126. //
  127. m_lstDevices.SetItemText (iIndex, 9, pDevices[dw].lptstrTsid);
  128. }
  129. m_cstrNumDevices.Format ("%ld", dwNumDevices);
  130. UpdateData (FALSE);
  131. FaxFreeBuffer (LPVOID(pDevices));
  132. }
  133. void CDlgDevices::OnDblclkDevs(NMHDR* pNMHDR, LRESULT* pResult)
  134. {
  135. *pResult = 0;
  136. NM_LISTVIEW *pnmListView = (NM_LISTVIEW *)pNMHDR;
  137. if (pnmListView->iItem < 0)
  138. {
  139. return;
  140. }
  141. DWORD dwDeviceID = m_lstDevices.GetItemData (pnmListView->iItem);
  142. if (!dwDeviceID)
  143. {
  144. return;
  145. }
  146. CDlgDevice dlg(m_hFax, dwDeviceID);
  147. dlg.DoModal ();
  148. }