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.

305 lines
9.6 KiB

  1. // ArchiveAccessDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ConfigTest.h"
  5. #include "ArchiveAccessDlg.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 "ArchiveMsgDlg.h"
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CArchiveAccessDlg dialog
  17. CArchiveAccessDlg::CArchiveAccessDlg(HANDLE hFax, CWnd* pParent /*=NULL*/)
  18. : CDialog(CArchiveAccessDlg::IDD, pParent),
  19. m_hFax (hFax)
  20. {
  21. //{{AFX_DATA_INIT(CArchiveAccessDlg)
  22. m_cstrNumMsgs = _T("0");
  23. m_iFolder = 0;
  24. m_dwMsgsPerCall = 5;
  25. //}}AFX_DATA_INIT
  26. }
  27. void CArchiveAccessDlg::DoDataExchange(CDataExchange* pDX)
  28. {
  29. CDialog::DoDataExchange(pDX);
  30. //{{AFX_DATA_MAP(CArchiveAccessDlg)
  31. DDX_Control(pDX, IDC_SPIN, m_spin);
  32. DDX_Control(pDX, IDC_LIST, m_lstArchive);
  33. DDX_Text(pDX, IDC_NUMSGS, m_cstrNumMsgs);
  34. DDX_Radio(pDX, IDC_INBOX, m_iFolder);
  35. DDX_Text(pDX, IDC_MSGSPERCALL, m_dwMsgsPerCall);
  36. DDV_MinMaxUInt(pDX, m_dwMsgsPerCall, 1, 9999);
  37. //}}AFX_DATA_MAP
  38. }
  39. BEGIN_MESSAGE_MAP(CArchiveAccessDlg, CDialog)
  40. //{{AFX_MSG_MAP(CArchiveAccessDlg)
  41. ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
  42. ON_NOTIFY(NM_DBLCLK, IDC_LIST, OnDblclkList)
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CArchiveAccessDlg message handlers
  47. BOOL CArchiveAccessDlg::OnInitDialog()
  48. {
  49. CDialog::OnInitDialog();
  50. m_spin.SetRange (1, 9999);
  51. m_lstArchive.InsertColumn ( 0, "Message id");
  52. m_lstArchive.InsertColumn ( 1, "Type");
  53. m_lstArchive.InsertColumn ( 2, "Size");
  54. m_lstArchive.InsertColumn ( 3, "Pages");
  55. m_lstArchive.InsertColumn ( 4, "Recipient number");
  56. m_lstArchive.InsertColumn ( 5, "Recipient name");
  57. m_lstArchive.InsertColumn ( 6, "Sender number");
  58. m_lstArchive.InsertColumn ( 7, "Sender name");
  59. m_lstArchive.InsertColumn ( 8, "Tsid");
  60. m_lstArchive.InsertColumn ( 9, "Csid");
  61. m_lstArchive.InsertColumn (10, "Sender user");
  62. m_lstArchive.InsertColumn (11, "Billing code");
  63. m_lstArchive.InsertColumn (12, "Original time");
  64. m_lstArchive.InsertColumn (13, "Submit time");
  65. m_lstArchive.InsertColumn (14, "Start time");
  66. m_lstArchive.InsertColumn (15, "End time");
  67. m_lstArchive.InsertColumn (16, "Device name");
  68. m_lstArchive.InsertColumn (17, "Priority");
  69. m_lstArchive.InsertColumn (18, "Retries");
  70. m_lstArchive.InsertColumn (19, "Document");
  71. m_lstArchive.InsertColumn (20, "Subject");
  72. m_lstArchive.InsertColumn (21, "Caller id");
  73. m_lstArchive.InsertColumn (22, "Routing");
  74. CHeaderCtrl* pHeader = (CHeaderCtrl*)m_lstArchive.GetDlgItem(0);
  75. DWORD dwCount = pHeader->GetItemCount();
  76. for (DWORD col = 0; col <= dwCount; col++)
  77. {
  78. m_lstArchive.SetColumnWidth(col, LVSCW_AUTOSIZE);
  79. int wc1 = m_lstArchive.GetColumnWidth(col);
  80. m_lstArchive.SetColumnWidth(col,LVSCW_AUTOSIZE_USEHEADER);
  81. int wc2 = m_lstArchive.GetColumnWidth(col);
  82. int wc = max(20,max(wc1,wc2));
  83. m_lstArchive.SetColumnWidth(col,wc);
  84. }
  85. return TRUE; // return TRUE unless you set the focus to a control
  86. // EXCEPTION: OCX Property Pages should return FALSE
  87. }
  88. void
  89. CArchiveAccessDlg::SetNumber (
  90. int iIndex,
  91. DWORD dwColumn,
  92. DWORD dwValue,
  93. BOOL bAvail)
  94. {
  95. CString cs;
  96. if (!bAvail)
  97. {
  98. cs = "N/A";
  99. }
  100. else
  101. {
  102. cs.Format ("%ld", dwValue);
  103. }
  104. m_lstArchive.SetItemText (iIndex, dwColumn, cs);
  105. }
  106. void
  107. CArchiveAccessDlg::SetTime (
  108. int iIndex,
  109. DWORD dwColumn,
  110. SYSTEMTIME dwTime,
  111. BOOL bAvail)
  112. {
  113. CString cs;
  114. if (!bAvail)
  115. {
  116. cs = "N/A";
  117. }
  118. else
  119. {
  120. cs.Format ("%02d:%02d:%02d", dwTime.wHour, dwTime.wMinute, dwTime.wSecond);
  121. }
  122. m_lstArchive.SetItemText (iIndex, dwColumn, cs);
  123. }
  124. void CArchiveAccessDlg::OnRefresh()
  125. {
  126. HANDLE h;
  127. if (!UpdateData ())
  128. {
  129. return;
  130. }
  131. m_lstArchive.DeleteAllItems ();
  132. if (!FaxStartMessagesEnum (m_hFax,
  133. m_iFolder ? FAX_MESSAGE_FOLDER_SENTITEMS : FAX_MESSAGE_FOLDER_INBOX,
  134. &h))
  135. {
  136. CString cs;
  137. cs.Format ("Failed while calling FaxStartMessagesEnum (%ld)",
  138. GetLastError ());
  139. AfxMessageBox (cs, MB_OK | MB_ICONHAND);
  140. return;
  141. }
  142. DWORD dwRes = ERROR_SUCCESS;
  143. DWORD dwNumMsgs = 0;
  144. while (ERROR_SUCCESS == dwRes)
  145. {
  146. PFAX_MESSAGE pMsgs;
  147. DWORD dwReturnedMsgs;
  148. if (!FaxEnumMessages (h, m_dwMsgsPerCall, &pMsgs, &dwReturnedMsgs))
  149. {
  150. CString cs;
  151. dwRes = GetLastError ();
  152. if (ERROR_NO_MORE_ITEMS != dwRes)
  153. {
  154. //
  155. // Real error
  156. //
  157. cs.Format ("Failed while calling FaxEnumMessages (%ld)",
  158. dwRes);
  159. AfxMessageBox (cs, MB_OK | MB_ICONHAND);
  160. }
  161. }
  162. else
  163. {
  164. //
  165. // Success in enumeration
  166. //
  167. dwNumMsgs += dwReturnedMsgs;
  168. for (DWORD dw = 0; dw < dwReturnedMsgs; dw++)
  169. {
  170. CString cs;
  171. cs.Format ("0x%016I64x", pMsgs[dw].dwlMessageId);
  172. int iIndex = m_lstArchive.InsertItem (0, cs);
  173. DWORDLONG *pdwl = new DWORDLONG;
  174. *pdwl = pMsgs[dw].dwlMessageId;
  175. m_lstArchive.SetItemData (iIndex, (DWORD)pdwl);
  176. if (!(pMsgs[dw].dwValidityMask & FAX_JOB_FIELD_TYPE))
  177. {
  178. m_lstArchive.SetItemText (iIndex, 1, "N/A");
  179. }
  180. else
  181. {
  182. if (JT_SEND == pMsgs[dw].dwJobType)
  183. {
  184. m_lstArchive.SetItemText (iIndex, 1, "Send");
  185. }
  186. else if (JT_RECEIVE == pMsgs[dw].dwJobType)
  187. {
  188. m_lstArchive.SetItemText (iIndex, 1, "Receive");
  189. }
  190. else
  191. {
  192. cs.Format ("Bad (%ld)", pMsgs[dw].dwJobType);
  193. m_lstArchive.SetItemText (iIndex, 1, cs);
  194. }
  195. }
  196. SetNumber (iIndex, 2, pMsgs[dw].dwSize, pMsgs[dw].dwValidityMask & FAX_JOB_FIELD_SIZE);
  197. SetNumber (iIndex, 3, pMsgs[dw].dwPageCount, pMsgs[dw].dwValidityMask & FAX_JOB_FIELD_PAGE_COUNT);
  198. m_lstArchive.SetItemText (iIndex, 4, pMsgs[dw].lpctstrRecipientNumber);
  199. m_lstArchive.SetItemText (iIndex, 5, pMsgs[dw].lpctstrRecipientName);
  200. m_lstArchive.SetItemText (iIndex, 6, pMsgs[dw].lpctstrSenderNumber);
  201. m_lstArchive.SetItemText (iIndex, 7, pMsgs[dw].lpctstrSenderName);
  202. m_lstArchive.SetItemText (iIndex, 8, pMsgs[dw].lpctstrTsid);
  203. m_lstArchive.SetItemText (iIndex, 9, pMsgs[dw].lpctstrCsid);
  204. m_lstArchive.SetItemText (iIndex,10, pMsgs[dw].lpctstrSenderUserName);
  205. m_lstArchive.SetItemText (iIndex,11, pMsgs[dw].lpctstrBillingCode);
  206. SetTime (iIndex, 12, pMsgs[dw].tmOriginalScheduleTime, pMsgs[dw].dwValidityMask & FAX_JOB_FIELD_ORIGINAL_SCHEDULE_TIME);
  207. SetTime (iIndex, 13, pMsgs[dw].tmSubmissionTime, pMsgs[dw].dwValidityMask & FAX_JOB_FIELD_SUBMISSION_TIME);
  208. SetTime (iIndex, 14, pMsgs[dw].tmTransmissionStartTime, pMsgs[dw].dwValidityMask & FAX_JOB_FIELD_TRANSMISSION_START_TIME);
  209. SetTime (iIndex, 15, pMsgs[dw].tmTransmissionEndTime, pMsgs[dw].dwValidityMask & FAX_JOB_FIELD_TRANSMISSION_END_TIME);
  210. m_lstArchive.SetItemText (iIndex,16, pMsgs[dw].lpctstrDeviceName);
  211. if (!(pMsgs[dw].dwValidityMask & FAX_JOB_FIELD_PRIORITY))
  212. {
  213. m_lstArchive.SetItemText (iIndex, 17, "N/A");
  214. }
  215. else
  216. {
  217. if (FAX_PRIORITY_TYPE_LOW == pMsgs[dw].Priority)
  218. {
  219. m_lstArchive.SetItemText (iIndex, 17, "Low");
  220. }
  221. else if (FAX_PRIORITY_TYPE_NORMAL == pMsgs[dw].Priority)
  222. {
  223. m_lstArchive.SetItemText (iIndex, 17, "Normal");
  224. }
  225. else if (FAX_PRIORITY_TYPE_HIGH == pMsgs[dw].Priority)
  226. {
  227. m_lstArchive.SetItemText (iIndex, 17, "High");
  228. }
  229. else
  230. {
  231. cs.Format ("Bad (%ld)", pMsgs[dw].Priority);
  232. m_lstArchive.SetItemText (iIndex, 17, cs);
  233. }
  234. }
  235. SetNumber (iIndex, 18, pMsgs[dw].dwRetries, pMsgs[dw].dwValidityMask & FAX_JOB_FIELD_RETRIES);
  236. m_lstArchive.SetItemText (iIndex,19, pMsgs[dw].lpctstrDocumentName);
  237. m_lstArchive.SetItemText (iIndex,20, pMsgs[dw].lpctstrSubject);
  238. m_lstArchive.SetItemText (iIndex,21, pMsgs[dw].lpctstrCallerID);
  239. m_lstArchive.SetItemText (iIndex,22, pMsgs[dw].lpctstrRoutingInfo);
  240. }
  241. FaxFreeBuffer ((LPVOID)pMsgs);
  242. }
  243. }
  244. m_cstrNumMsgs.Format ("%ld", dwNumMsgs);
  245. UpdateData (FALSE);
  246. if (!FaxEndMessagesEnum (h))
  247. {
  248. CString cs;
  249. cs.Format ("Failed while calling FaxEndMessagesEnum (%ld)",
  250. GetLastError ());
  251. AfxMessageBox (cs, MB_OK | MB_ICONHAND);
  252. return;
  253. }
  254. }
  255. void CArchiveAccessDlg::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)
  256. {
  257. *pResult = 0;
  258. NM_LISTVIEW *pnmListView = (NM_LISTVIEW *)pNMHDR;
  259. if (pnmListView->iItem < 0)
  260. {
  261. return;
  262. }
  263. DWORDLONG dwlMsgID = *((DWORDLONG *)(m_lstArchive.GetItemData (pnmListView->iItem)));
  264. if (!dwlMsgID)
  265. {
  266. return;
  267. }
  268. CArchiveMsgDlg dlg(m_hFax,
  269. m_iFolder ? FAX_MESSAGE_FOLDER_SENTITEMS : FAX_MESSAGE_FOLDER_INBOX,
  270. dwlMsgID);
  271. if (99 == dlg.DoModal ())
  272. {
  273. //
  274. // Msg was erased - refresh list
  275. //
  276. OnRefresh ();
  277. }
  278. }