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.

ListViewControl.cxx 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // ListViewControl.cxx: implementation of the ListViewControl class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include <tchar.h>
  5. #include "ListViewControl.h"
  6. #include "commctrl.h"
  7. //////////////////////////////////////////////////////////////////////
  8. // Construction/Destruction
  9. //////////////////////////////////////////////////////////////////////
  10. using namespace rfb;
  11. using namespace rfb::win32;
  12. ListViewControl::ListViewControl()
  13. {
  14. }
  15. bool ListViewControl::IsSelectedLVItem(DWORD idListView,
  16. HWND hDlg, int numberItem)
  17. {
  18. return (ListView_GetItemState(GetDlgItem(hDlg, idListView),
  19. numberItem, LVIS_SELECTED) == LVIS_SELECTED);
  20. }
  21. void ListViewControl::SelectLVItem(DWORD idListView, HWND hDlg, int numberItem)
  22. {
  23. ListView_SetItemState(GetDlgItem(hDlg, idListView),
  24. numberItem, LVIS_SELECTED, LVIS_SELECTED);
  25. }
  26. BOOL ListViewControl::InitLVColumns(DWORD idListView, HWND hDlg, int width, int columns,
  27. TCHAR *title[], DWORD mask, DWORD LVStyle, DWORD format)
  28. {
  29. (void)ListView_SetExtendedListViewStyle(GetDlgItem(hDlg, idListView), LVStyle);
  30. TCHAR szText[256];
  31. LVCOLUMN lvc;
  32. int iCol;
  33. lvc.mask = mask;
  34. for (iCol = 0; iCol < columns; iCol++) {
  35. lvc.iSubItem = iCol;
  36. lvc.pszText = szText;
  37. lvc.cx = width;
  38. lvc.fmt = format;
  39. _tcscpy(szText, title[iCol]);
  40. if (ListView_InsertColumn(GetDlgItem(hDlg, idListView), iCol, &lvc) == -1)
  41. return FALSE;
  42. }
  43. return TRUE;
  44. }
  45. BOOL ListViewControl::InsertLVItem(DWORD idListView, HWND hDlg, int number, TCHAR * texts[],
  46. int columns)
  47. {
  48. int i;
  49. LVITEM lvI;
  50. lvI.mask = LVIF_TEXT| LVIF_STATE;
  51. lvI.state = 0;
  52. lvI.stateMask = 0;
  53. lvI.iItem = number;
  54. lvI.iSubItem = 0;
  55. lvI.pszText = texts[0];
  56. if(ListView_InsertItem(GetDlgItem(hDlg, idListView), &lvI) == -1)
  57. return FALSE;
  58. for (i =1; i < columns; i++) {
  59. SetLVItemText(
  60. idListView, hDlg,
  61. number, i, texts[i]);
  62. }
  63. return TRUE;
  64. }
  65. void ListViewControl::SetLVItemText(DWORD idListView, HWND hDlg, int numberItem,
  66. int namberColumn, TCHAR * text)
  67. {
  68. ListView_SetItemText(
  69. GetDlgItem(hDlg, idListView),
  70. numberItem, namberColumn, text);
  71. }
  72. void ListViewControl::GetLVItemText(DWORD idListView, HWND hDlg, int numberItem,
  73. int namberColumn, TCHAR * text)
  74. {
  75. ListView_GetItemText(GetDlgItem(hDlg, idListView), numberItem,
  76. namberColumn, text, 256);
  77. }
  78. void ListViewControl::DeleteLVItem(DWORD idListView, HWND hDlg, int number)
  79. {
  80. (void)ListView_DeleteItem(GetDlgItem(hDlg, idListView), number);
  81. }
  82. void ListViewControl::DeleteAllLVItem(DWORD idListView, HWND hDlg)
  83. {
  84. (void)ListView_DeleteAllItems(GetDlgItem(hDlg, idListView));
  85. }
  86. ListViewControl::~ListViewControl()
  87. {
  88. }