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.

111 lines
4.1 KiB

  1. // Copyright (C) 1993-1997 Microsoft Corporation. All rights reserved.
  2. #if _MSC_VER > 1000
  3. #pragma once
  4. #endif
  5. #ifndef __CDLGLISTBOX_H__
  6. #define __CDLGLISTBOX_H__
  7. // Header-only classes for coding convenience
  8. class CDlgListBox
  9. {
  10. public:
  11. CDlgListBox() { m_hWnd = NULL; }
  12. CDlgListBox(HWND hwndParent, int id) {
  13. m_hWnd = GetDlgItem(hwndParent, id);
  14. ASSERT_COMMENT(m_hWnd, "Invalid Listbox id");
  15. }
  16. void Initialize(int id) { ASSERT(m_hWnd); m_hWnd = GetDlgItem(GetParent(m_hWnd), id); };
  17. void Initialize(HWND hdlg, int id) { m_hWnd = ::GetDlgItem(hdlg, id); };
  18. INT_PTR SendMessage(UINT msg, WPARAM wParam = 0, LPARAM lParam = 0) const { return ::SendMessage(m_hWnd, msg, wParam, lParam); };
  19. void Enable(BOOL fEnable = TRUE) const { EnableWindow(m_hWnd, fEnable); };
  20. INT_PTR GetText(PSTR psz, int cchMax = MAX_PATH, int index = -1) const { return SendMessage(LB_GETTEXT,
  21. (index == -1) ? GetCurSel() : index, (LPARAM) psz); };
  22. INT_PTR GetTextLength(int index = -1) const { return SendMessage(LB_GETTEXTLEN,
  23. (index == -1) ? GetCurSel() : index); };
  24. INT_PTR GetCount() const { return SendMessage(LB_GETCOUNT); };
  25. void ResetContent() const { SendMessage(LB_RESETCONTENT); };
  26. void Reset() const { SendMessage(LB_RESETCONTENT); };
  27. INT_PTR AddString(PCSTR psz) const { return SendMessage(LB_ADDSTRING, 0, (LPARAM) psz); };
  28. INT_PTR InsertString(int index, PCSTR psz) const { return SendMessage(LB_INSERTSTRING, index, (LPARAM) psz); };
  29. INT_PTR DeleteString(int index) const { return SendMessage(LB_DELETESTRING, index); };
  30. void RemoveListItem(); // removes currently selected item
  31. INT_PTR GetItemRect(RECT* prc, int index = -1) const { return SendMessage(LB_GETITEMRECT,
  32. ((index == -1) ? GetCurSel() : index), (LPARAM) prc); };
  33. INT_PTR GetItemData(int index) const { return SendMessage(LB_GETITEMDATA, index); };
  34. INT_PTR SetItemData(int index, int data) const { return SendMessage(LB_SETITEMDATA, index, data); };
  35. INT_PTR GetCurSel() const {
  36. // works on single selection listbox only
  37. ASSERT(!(GetWindowLong(m_hWnd, GWL_STYLE) & LBS_MULTIPLESEL));
  38. return SendMessage(LB_GETCURSEL); };
  39. INT_PTR SetCurSel(int index = 0) const {
  40. // works on single selection listbox only
  41. ASSERT(!(GetWindowLong(m_hWnd, GWL_STYLE) & LBS_MULTIPLESEL));
  42. return SendMessage(LB_SETCURSEL, index); };
  43. INT_PTR GetTopIndex(void) const { return SendMessage(LB_GETTOPINDEX); };
  44. void SetTopIndex(int index) const { (void) SendMessage(LB_SETTOPINDEX, (WPARAM) index); };
  45. // For multi-select list boxes
  46. INT_PTR GetSel(int index) const {
  47. // works on multiple selection listbox only
  48. ASSERT((GetWindowLong(m_hWnd, GWL_STYLE) & LBS_MULTIPLESEL));
  49. return SendMessage(LB_GETSEL, index); };
  50. void SetSel(int index, BOOL fSelect = TRUE) const {
  51. // works on multiple selection listbox only
  52. ASSERT((GetWindowLong(m_hWnd, GWL_STYLE) & LBS_MULTIPLESEL));
  53. (void) SendMessage(LB_SETSEL, fSelect, MAKELPARAM(index, 0)); };
  54. INT_PTR FindString(PCSTR pszString, int iStart = -1) const { return SendMessage(LB_FINDSTRING, iStart, (LPARAM) pszString); };
  55. INT_PTR SelectString(PCSTR pszString, int iStart = -1) const {
  56. // works on single selection listbox only
  57. ASSERT(!(GetWindowLong(m_hWnd, GWL_STYLE) & LBS_MULTIPLESEL));
  58. return SendMessage(LB_SELECTSTRING, iStart, (LPARAM) pszString); };
  59. void Invalidate(BOOL bErase = TRUE) { InvalidateRect(m_hWnd, NULL, bErase); }
  60. void DisableRedraw(void) { SendMessage(WM_SETREDRAW, FALSE); }
  61. void EnableRedraw(void) { SendMessage(WM_SETREDRAW, TRUE); }
  62. HWND m_hWnd;
  63. operator HWND() const
  64. { return m_hWnd; }
  65. };
  66. class CDlgCheckListBox : public CDlgListBox
  67. {
  68. public:
  69. CDlgCheckListBox();
  70. ~CDlgCheckListBox();
  71. BOOL IsItemChecked(int nIndex) const;
  72. void CheckItem(int nIndex, BOOL fChecked = TRUE);
  73. void ToggleItem(int nIndex);
  74. void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
  75. int GetCheckRect(int nIndex, RECT* prc);
  76. void InvalidateItem(int nIndex, BOOL fRedraw = FALSE);
  77. int ItemHeight(void);
  78. void DrawCheck(HDC hdc, RECT* prc, BOOL fChecked);
  79. void OnSelChange(void);
  80. int m_xMargin;
  81. int m_yMargin;
  82. int m_cxDlgFrame;
  83. int m_cxCheck;
  84. int m_cyCheck;
  85. int m_iLastSel;
  86. HBITMAP m_hbmpCheck;
  87. };
  88. #endif // __CDLGLISTBOX_H__