Source code of Windows XP (NT5)
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.

701 lines
18 KiB

  1. //-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: D L G F I L T. C P P
  7. //
  8. // Contents: Implementation of CFilteringDialog and CAddFilterDialog
  9. //
  10. // Notes: CFilterDialog is the TCP/IP filtering dialog
  11. //
  12. // Author: tongl 6 Sept 1998
  13. //-----------------------------------------------------------------------
  14. #include "pch.h"
  15. #pragma hdrstop
  16. #include "tcpipobj.h"
  17. #include "ncatlui.h"
  18. #include "ncstl.h"
  19. #include "resource.h"
  20. #include "tcphelp.h"
  21. #include "tcpmacro.h"
  22. #include "tcputil.h"
  23. #include "dlgopt.h"
  24. int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
  25. {
  26. unsigned long a = (unsigned long)lParam1;
  27. unsigned long b = (unsigned long)lParam2;
  28. if (a < b)
  29. return -1;
  30. return a != b;
  31. }
  32. //
  33. // CFilterDialog
  34. //
  35. CFilterDialog::CFilterDialog(CTcpOptionsPage * pOptionsPage,
  36. GLOBAL_INFO * pGlbDlg,
  37. ADAPTER_INFO * pAdapterDlg,
  38. const DWORD* adwHelpIDs)
  39. {
  40. Assert(pOptionsPage != NULL);
  41. Assert(pGlbDlg != NULL);
  42. Assert(pAdapterDlg != NULL);
  43. m_pParentDlg = pOptionsPage;
  44. m_pGlobalInfo = pGlbDlg;
  45. m_pAdapterInfo = pAdapterDlg;
  46. m_adwHelpIDs = adwHelpIDs;
  47. m_fModified = FALSE;
  48. }
  49. CFilterDialog::~CFilterDialog()
  50. {
  51. }
  52. LRESULT CFilterDialog::OnInitDialog(UINT uMsg, WPARAM wParam,
  53. LPARAM lParam, BOOL& fHandled)
  54. {
  55. m_hlistTcp = GetDlgItem(IDC_FILTERING_TCP);
  56. m_hlistUdp = GetDlgItem(IDC_FILTERING_UDP);
  57. m_hlistIp = GetDlgItem(IDC_FILTERING_IP);
  58. // Label columns in the listviews
  59. LV_COLUMN lvCol;
  60. RECT rect;
  61. int iNewCol;
  62. lvCol.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
  63. lvCol.fmt = LVCFMT_LEFT;
  64. // TCP ports
  65. ::GetClientRect(m_hlistTcp, &rect);
  66. lvCol.pszText = (PWSTR)SzLoadIds(IDS_FILTERING_TCP_LABEL);
  67. lvCol.cx = rect.right;
  68. iNewCol = ListView_InsertColumn(m_hlistTcp, 0, &lvCol);
  69. Assert(iNewCol == 0);
  70. // UDP ports
  71. ::GetClientRect(m_hlistUdp, &rect);
  72. lvCol.pszText = (PWSTR)SzLoadIds(IDS_FILTERING_UDP_LABEL);
  73. lvCol.cx = rect.right;
  74. iNewCol = ListView_InsertColumn(m_hlistUdp, 0, &lvCol);
  75. Assert(iNewCol == 0);
  76. // IP protocols
  77. ::GetClientRect(m_hlistIp, &rect);
  78. lvCol.pszText = (PWSTR)SzLoadIds(IDS_FILTERING_IP_LABEL);
  79. lvCol.cx = rect.right;
  80. iNewCol = ListView_InsertColumn(m_hlistIp, 0, &lvCol);
  81. Assert(iNewCol == 0);
  82. SetInfo();
  83. SetButtons();
  84. m_fModified = FALSE;
  85. return 0;
  86. }
  87. LRESULT CFilterDialog::OnContextMenu(UINT uMsg, WPARAM wParam,
  88. LPARAM lParam, BOOL& fHandled)
  89. {
  90. ShowContextHelp(m_hWnd, HELP_CONTEXTMENU, m_adwHelpIDs);
  91. return 0;
  92. }
  93. LRESULT CFilterDialog::OnHelp(UINT uMsg, WPARAM wParam,
  94. LPARAM lParam, BOOL& fHandled)
  95. {
  96. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  97. Assert(lphi);
  98. if (HELPINFO_WINDOW == lphi->iContextType)
  99. {
  100. ShowContextHelp(static_cast<HWND>(lphi->hItemHandle), HELP_WM_HELP,
  101. m_adwHelpIDs);
  102. }
  103. return 0;
  104. }
  105. LRESULT CFilterDialog::OnEnableFiltering( WORD wNotifyCode, WORD wID,
  106. HWND hWndCtl, BOOL& fHandled)
  107. {
  108. switch(wNotifyCode)
  109. {
  110. case BN_CLICKED:
  111. case BN_DOUBLECLICKED:
  112. m_fModified = TRUE;
  113. if (m_pGlobalInfo->m_fEnableFiltering) // if Filtering was enabled
  114. {
  115. // disable filtering
  116. NcMsgBox(::GetActiveWindow(),
  117. IDS_MSFT_TCP_TEXT,
  118. IDS_FILTERING_DISABLE,
  119. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  120. m_pGlobalInfo->m_fEnableFiltering = FALSE;
  121. }
  122. else
  123. {
  124. m_pGlobalInfo->m_fEnableFiltering = TRUE;
  125. }
  126. }
  127. return 0;
  128. }
  129. LRESULT CFilterDialog::OnTcpPermit( WORD wNotifyCode, WORD wID,
  130. HWND hWndCtl, BOOL& fHandled)
  131. {
  132. m_fModified = TRUE;
  133. // check "Enable Filtering"
  134. CheckDlgButton(IDC_FILTERING_ENABLE, TRUE);
  135. m_pGlobalInfo->m_fEnableFiltering = TRUE;
  136. EnableGroup(wID, !IsDlgButtonChecked(IDC_FILTERING_FILTER_TCP));
  137. SetButtons();
  138. return 0;
  139. }
  140. LRESULT CFilterDialog::OnUdpPermit(WORD wNotifyCode, WORD wID,
  141. HWND hWndCtl, BOOL& fHandled)
  142. {
  143. m_fModified = TRUE;
  144. // check "Enable Filtering"
  145. CheckDlgButton(IDC_FILTERING_ENABLE, TRUE);
  146. m_pGlobalInfo->m_fEnableFiltering = TRUE;
  147. EnableGroup(wID, !IsDlgButtonChecked(IDC_FILTERING_FILTER_UDP));
  148. SetButtons();
  149. return 0;
  150. }
  151. LRESULT CFilterDialog::OnIpPermit(WORD wNotifyCode, WORD wID,
  152. HWND hWndCtl, BOOL& fHandled)
  153. {
  154. m_fModified = TRUE;
  155. // check "Enable Filtering"
  156. CheckDlgButton(IDC_FILTERING_ENABLE, TRUE);
  157. m_pGlobalInfo->m_fEnableFiltering = TRUE;
  158. EnableGroup(wID, !IsDlgButtonChecked(IDC_FILTERING_FILTER_IP));
  159. SetButtons();
  160. return 0;
  161. }
  162. LRESULT CFilterDialog::OnOk(WORD wNotifyCode, WORD wID,
  163. HWND hWndCtl, BOOL& fHandled)
  164. {
  165. if (m_fModified)
  166. {
  167. m_pParentDlg->m_fPropDlgModified = TRUE;
  168. UpdateInfo();
  169. }
  170. EndDialog(IDOK);
  171. return 0;
  172. }
  173. LRESULT CFilterDialog::OnCancel(WORD wNotifyCode, WORD wID,
  174. HWND hWndCtl, BOOL& fHandled)
  175. {
  176. m_fModified = FALSE;
  177. EndDialog(IDCANCEL);
  178. return 0;
  179. }
  180. LRESULT CFilterDialog::OnAdd(WORD wNotifyCode, WORD wID,
  181. HWND hWndCtl, BOOL& fHandled)
  182. {
  183. CAddFilterDialog * pDlgAddFilter = new CAddFilterDialog(this,
  184. wID,
  185. g_aHelpIDs_IDD_FILTER_ADD);
  186. if (pDlgAddFilter == NULL)
  187. {
  188. return(ERROR_NOT_ENOUGH_MEMORY);
  189. }
  190. if (pDlgAddFilter->DoModal() == IDOK)
  191. m_fModified = TRUE;
  192. SetButtons();
  193. delete pDlgAddFilter;
  194. return 0;
  195. }
  196. LRESULT CFilterDialog::OnRemove(WORD wNotifyCode, WORD wID,
  197. HWND hWndCtl, BOOL& fHandled)
  198. {
  199. HWND hList = NULL;
  200. HWND hAdd = NULL;
  201. switch (wID)
  202. {
  203. case IDC_FILTERING_TCP_REMOVE:
  204. hList = m_hlistTcp;
  205. hAdd = GetDlgItem(IDC_FILTERING_TCP_ADD);
  206. break;
  207. case IDC_FILTERING_UDP_REMOVE:
  208. hList = m_hlistUdp;
  209. hAdd = GetDlgItem(IDC_FILTERING_UDP_ADD);
  210. break;
  211. case IDC_FILTERING_IP_REMOVE:
  212. hList = m_hlistIp;
  213. hAdd = GetDlgItem(IDC_FILTERING_IP_ADD);
  214. break;
  215. default:
  216. Assert(FALSE);
  217. break;
  218. }
  219. Assert(hList);
  220. if (NULL == hList || NULL == hAdd)
  221. {
  222. return TRUE;
  223. }
  224. // see if an item is selected
  225. int i = ::SendMessage(hList, LVM_GETNEXTITEM, -1, MAKELPARAM(LVNI_SELECTED, 0));
  226. if (i == -1)
  227. {
  228. NcMsgBox(::GetActiveWindow(), IDS_MSFT_TCP_TEXT,
  229. IDS_FILTERING_ITEM_NOT_SELECTED,
  230. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  231. return TRUE;
  232. }
  233. // remove the item and make item 0 selected
  234. ListView_DeleteItem(hList, i);
  235. ListView_GetItemCount(hList);
  236. m_fModified = TRUE;
  237. if (i)
  238. {
  239. LV_ITEM lvItem;
  240. lvItem.stateMask = LVIS_SELECTED;
  241. lvItem.state = LVIS_SELECTED;
  242. ::SendMessage(hList, LVM_SETITEMSTATE, 0, (LPARAM)&lvItem);
  243. }
  244. else // Force focus to the Add button
  245. {
  246. IsWindow(::SetFocus(hAdd));
  247. }
  248. SetButtons();
  249. return TRUE;
  250. }
  251. void CFilterDialog::UpdateInfo()
  252. {
  253. m_pGlobalInfo->m_fEnableFiltering = IsDlgButtonChecked(IDC_FILTERING_ENABLE);
  254. FreeCollectionAndItem(m_pAdapterInfo->m_vstrTcpFilterList);
  255. FreeCollectionAndItem(m_pAdapterInfo->m_vstrUdpFilterList);
  256. FreeCollectionAndItem(m_pAdapterInfo->m_vstrIpFilterList);
  257. HWND list[3];
  258. VSTR * pvstr[3];
  259. int nId[3] = {IDC_FILTERING_FILTER_TCP, IDC_FILTERING_FILTER_UDP, IDC_FILTERING_FILTER_IP};
  260. // Initialize values
  261. list[0] = m_hlistTcp;
  262. list[1] = m_hlistUdp;
  263. list[2] = m_hlistIp;
  264. pvstr[0] = &m_pAdapterInfo->m_vstrTcpFilterList;
  265. pvstr[1] = &m_pAdapterInfo->m_vstrUdpFilterList;
  266. pvstr[2] = &m_pAdapterInfo->m_vstrIpFilterList;
  267. for(int iLists = 0; iLists < 3; ++iLists)
  268. {
  269. int nlvCount = ListView_GetItemCount(list[iLists]);
  270. // "" (Empty String) == All ports
  271. // "0" == No ports
  272. // "x y z" == ports x, y, x
  273. // if the All Filter button is checked, use Empty String
  274. if (IsDlgButtonChecked(nId[iLists]))
  275. {
  276. pvstr[iLists]->push_back(new tstring(L"0"));
  277. continue;
  278. }
  279. if (nlvCount == 0)
  280. {
  281. pvstr[iLists]->push_back(new tstring(L""));
  282. continue;
  283. }
  284. LV_ITEM lvItem;
  285. lvItem.mask = LVIF_PARAM;
  286. lvItem.iSubItem = 0;
  287. for (int iItem = 0; iItem < nlvCount; iItem++)
  288. {
  289. WCHAR szBuf[16];
  290. lvItem.iItem = iItem;
  291. ListView_GetItem(list[iLists], &lvItem);
  292. Assert(lvItem.lParam != 0);
  293. _itow((int)lvItem.lParam, szBuf, 10);
  294. Assert(szBuf);
  295. pvstr[iLists]->push_back(new tstring(szBuf));
  296. }
  297. }
  298. }
  299. void CFilterDialog::SetInfo()
  300. {
  301. CheckDlgButton(IDC_FILTERING_ENABLE, m_pGlobalInfo->m_fEnableFiltering);
  302. int anId[3] = {IDC_FILTERING_FILTER_TCP, IDC_FILTERING_FILTER_UDP, IDC_FILTERING_FILTER_IP};
  303. int anIdSel[3] = {IDC_FILTERING_FILTER_TCP_SEL, IDC_FILTERING_FILTER_UDP_SEL, IDC_FILTERING_FILTER_IP_SEL};
  304. HWND aplist[3];
  305. VSTR * apvect[3];
  306. aplist[0] = m_hlistTcp;
  307. aplist[1] = m_hlistUdp;
  308. aplist[2] = m_hlistIp;
  309. ListView_DeleteAllItems(m_hlistTcp);
  310. ListView_DeleteAllItems(m_hlistUdp);
  311. ListView_DeleteAllItems(m_hlistIp);
  312. apvect[0] = &m_pAdapterInfo->m_vstrTcpFilterList;
  313. apvect[1] = &m_pAdapterInfo->m_vstrUdpFilterList;
  314. apvect[2] = &m_pAdapterInfo->m_vstrIpFilterList;
  315. int iItem;
  316. for (int iLists = 0; iLists < 3; ++iLists)
  317. {
  318. iItem = 0;
  319. //if the list is empty, that means no value is accepted
  320. if (apvect[iLists]->empty())
  321. {
  322. EnableGroup(anId[iLists], TRUE);
  323. CheckRadioButton(anId[iLists], anIdSel[iLists], anIdSel[iLists]);
  324. continue;
  325. }
  326. for(VSTR_ITER iter = apvect[iLists]->begin() ; iter != apvect[iLists]->end() ; ++iter)
  327. {
  328. if (**iter == L"0")
  329. {
  330. EnableGroup(anId[iLists], FALSE);
  331. CheckRadioButton(anId[iLists], anIdSel[iLists], anId[iLists]);
  332. break;
  333. }
  334. EnableGroup(anId[iLists], TRUE);
  335. CheckRadioButton(anId[iLists], anIdSel[iLists], anIdSel[iLists]);
  336. if (**iter == L"")
  337. break;
  338. unsigned long nNum = wcstoul((*iter)->c_str(), NULL, 10);
  339. LV_ITEM lvItem;
  340. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  341. lvItem.lParam = nNum;
  342. lvItem.iItem = iItem;
  343. lvItem.iSubItem = 0;
  344. lvItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
  345. lvItem.state =0;
  346. lvItem.pszText = (PWSTR)(*iter)->c_str();
  347. ::SendMessage(aplist[iLists], LVM_INSERTITEM, 0, (LPARAM)&lvItem);
  348. lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  349. lvItem.state = LVIS_SELECTED | LVIS_FOCUSED;
  350. :: SendMessage(aplist[iLists], LVM_SETITEMSTATE, iItem, (LPARAM)&lvItem);
  351. ++iItem;
  352. }
  353. ListView_SortItems(aplist[iLists], CompareFunc, 0);
  354. }
  355. // Update the RemoveButtons
  356. SetButtons();
  357. }
  358. void CFilterDialog::EnableGroup(int nId, BOOL fEnable)
  359. {
  360. int nIdAdd = 0;
  361. int nIdRemove = 0;
  362. int nIdList = 0;
  363. switch (nId)
  364. {
  365. case IDC_FILTERING_FILTER_TCP:
  366. case IDC_FILTERING_FILTER_TCP_SEL:
  367. nIdAdd = IDC_FILTERING_TCP_ADD;
  368. nIdRemove = IDC_FILTERING_TCP_REMOVE;
  369. nIdList = IDC_FILTERING_TCP;
  370. break;
  371. case IDC_FILTERING_FILTER_UDP:
  372. case IDC_FILTERING_FILTER_UDP_SEL:
  373. nIdAdd = IDC_FILTERING_UDP_ADD;
  374. nIdRemove = IDC_FILTERING_UDP_REMOVE;
  375. nIdList = IDC_FILTERING_UDP;
  376. break;
  377. case IDC_FILTERING_FILTER_IP:
  378. case IDC_FILTERING_FILTER_IP_SEL:
  379. nIdAdd = IDC_FILTERING_IP_ADD;
  380. nIdRemove = IDC_FILTERING_IP_REMOVE;
  381. nIdList = IDC_FILTERING_IP;
  382. break;
  383. default:
  384. Assert(FALSE);
  385. break;
  386. }
  387. if (0 != nIdAdd && 0 != nIdRemove && 0 != nIdList)
  388. {
  389. ::EnableWindow(GetDlgItem(nIdAdd), fEnable);
  390. ::EnableWindow(GetDlgItem(nIdRemove), fEnable);
  391. ::EnableWindow(GetDlgItem(nIdList), fEnable);
  392. }
  393. }
  394. void CFilterDialog::SetButtons()
  395. {
  396. if (ListView_GetItemCount(m_hlistTcp)>0)
  397. {
  398. ::EnableWindow(GetDlgItem(IDC_FILTERING_TCP_REMOVE),
  399. !IsDlgButtonChecked(IDC_FILTERING_FILTER_TCP));
  400. }
  401. if (ListView_GetItemCount(m_hlistUdp)>0)
  402. {
  403. ::EnableWindow(GetDlgItem(IDC_FILTERING_UDP_REMOVE),
  404. !IsDlgButtonChecked(IDC_FILTERING_FILTER_UDP));
  405. }
  406. if (ListView_GetItemCount(m_hlistIp)>0)
  407. {
  408. ::EnableWindow(GetDlgItem(IDC_FILTERING_IP_REMOVE),
  409. !IsDlgButtonChecked(IDC_FILTERING_FILTER_IP));
  410. }
  411. }
  412. //
  413. // CAddFilterDialog
  414. //
  415. CAddFilterDialog::CAddFilterDialog(CFilterDialog* pParentDlg, int ID, const DWORD* adwHelpIDs)
  416. {
  417. Assert(pParentDlg != NULL);
  418. Assert(ID != 0);
  419. m_pParentDlg = pParentDlg;
  420. m_nId = ID;
  421. m_hList = NULL;
  422. m_adwHelpIDs = adwHelpIDs;
  423. }
  424. CAddFilterDialog::~CAddFilterDialog()
  425. {
  426. }
  427. LRESULT CAddFilterDialog::OnInitDialog(UINT uMsg, WPARAM wParam,
  428. LPARAM lParam, BOOL& fHandled)
  429. {
  430. int nTextId = 0;
  431. Assert(m_pParentDlg != NULL);
  432. // Position the dialog
  433. RECT rect;
  434. switch (m_nId)
  435. {
  436. case IDC_FILTERING_TCP_ADD:
  437. m_hList = m_pParentDlg->m_hlistTcp;
  438. nTextId = IDS_FILTERING_TCP_TEXT;
  439. break;
  440. case IDC_FILTERING_UDP_ADD:
  441. m_hList = m_pParentDlg->m_hlistUdp;
  442. nTextId = IDS_FILTERING_UDP_TEXT;
  443. break;
  444. case IDC_FILTERING_IP_ADD:
  445. m_hList = m_pParentDlg->m_hlistIp;
  446. nTextId = IDS_FILTERING_IP_TEXT;
  447. break;
  448. default:
  449. Assert(FALSE);
  450. break;
  451. }
  452. Assert(IsWindow(m_hList));
  453. if (IsWindow(m_hList))
  454. {
  455. ::GetWindowRect(m_hList, &rect);
  456. SetWindowPos(NULL, rect.left, rect.top-8, 0,0,
  457. SWP_NOZORDER|SWP_NOSIZE|SWP_NOACTIVATE);
  458. }
  459. // Set the static text and limit the edit control to 5 characters
  460. SetDlgItemText(IDC_FILTERING_TEXT, SzLoadIds(nTextId));
  461. SendDlgItemMessage(IDC_FILTERING_ADD_EDIT, EM_SETLIMITTEXT, FILTER_ADD_LIMIT, 0);
  462. ::EnableWindow(GetDlgItem(IDOK), FALSE);
  463. return TRUE;
  464. }
  465. LRESULT CAddFilterDialog::OnContextMenu(UINT uMsg, WPARAM wParam,
  466. LPARAM lParam, BOOL& fHandled)
  467. {
  468. ShowContextHelp(m_hWnd, HELP_CONTEXTMENU, m_adwHelpIDs);
  469. return 0;
  470. }
  471. LRESULT CAddFilterDialog::OnHelp(UINT uMsg, WPARAM wParam,
  472. LPARAM lParam, BOOL& fHandled)
  473. {
  474. LPHELPINFO lphi = reinterpret_cast<LPHELPINFO>(lParam);
  475. Assert(lphi);
  476. if (HELPINFO_WINDOW == lphi->iContextType)
  477. {
  478. ShowContextHelp(static_cast<HWND>(lphi->hItemHandle), HELP_WM_HELP,
  479. m_adwHelpIDs);
  480. }
  481. return 0;
  482. }
  483. LRESULT CAddFilterDialog::OnFilterAddEdit(WORD wNotifyCode, WORD wID,
  484. HWND hWndCtl, BOOL& fHandled)
  485. {
  486. switch (wNotifyCode)
  487. {
  488. case EN_CHANGE:
  489. ::EnableWindow(GetDlgItem(IDOK),
  490. Tcp_Edit_LineLength(GetDlgItem(wID), -1));
  491. break;
  492. default:
  493. break;
  494. }
  495. return 0;
  496. }
  497. LRESULT CAddFilterDialog::OnOk(WORD wNotifyCode, WORD wID,
  498. HWND hWndCtl, BOOL& fHandled)
  499. {
  500. WCHAR szData[FILTER_ADD_LIMIT+1];
  501. szData[0] = 0;
  502. ::GetWindowText(GetDlgItem(IDC_FILTERING_ADD_EDIT), szData, FILTER_ADD_LIMIT+1);
  503. Assert(IsWindow(m_hList));
  504. // check the range of the number
  505. PWSTR pStr;
  506. unsigned long num = wcstoul(szData, &pStr, 10);
  507. unsigned long maxNum = 65535;
  508. int nId = IDS_FILTERING_RANGE_WORD;
  509. if (m_hList == m_pParentDlg->m_hlistIp)
  510. {
  511. maxNum = 255;
  512. nId = IDS_FILTERING_RANGE_BYTE;
  513. }
  514. if (num < 1 || num > maxNum)
  515. {
  516. NcMsgBox(::GetActiveWindow(),
  517. IDS_MSFT_TCP_TEXT,
  518. nId,
  519. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  520. return 0;
  521. }
  522. // See if the item is in the list
  523. LV_FINDINFO info;
  524. info.flags = LVFI_PARAM;
  525. info.lParam = num;
  526. int i = ListView_FindItem(m_hList, -1, &info);
  527. if (i != -1)
  528. {
  529. NcMsgBox(::GetActiveWindow(),
  530. IDS_MSFT_TCP_TEXT,
  531. IDS_FILTERING_ITEM_IN_LIST,
  532. MB_APPLMODAL | MB_ICONEXCLAMATION | MB_OK);
  533. return 0;
  534. }
  535. int index = ListView_GetItemCount(m_hList);
  536. LV_ITEM lvItem;
  537. lvItem.mask = LVIF_TEXT | LVIF_PARAM;
  538. lvItem.lParam = num;
  539. lvItem.iItem = index;
  540. lvItem.iSubItem = 0;
  541. lvItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
  542. lvItem.state =0;
  543. lvItem.pszText = (PWSTR)szData;
  544. ::SendMessage(m_hList, LVM_INSERTITEM, 0, (LPARAM)&lvItem);
  545. ListView_SortItems(m_hList, CompareFunc, 0);
  546. lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
  547. lvItem.state = LVIS_SELECTED | LVIS_FOCUSED;
  548. ::SendMessage(m_hList, LVM_SETITEMSTATE, (WPARAM)i, (LPARAM)&lvItem);
  549. EndDialog(IDOK);
  550. return 0;
  551. }
  552. LRESULT CAddFilterDialog::OnCancel(WORD wNotifyCode, WORD wID,
  553. HWND hWndCtl, BOOL& fHandled)
  554. {
  555. EndDialog(IDOK);
  556. return 0;
  557. }