ComboBox.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #ifndef NULLSOFT_UTILITY_COMBOBOX_H
  2. #define NULLSOFT_UTILITY_COMBOBOX_H
  3. #include <windows.h>
  4. class ComboBox
  5. {
  6. public:
  7. ComboBox(HWND hwndDlg, int id)
  8. {
  9. cbHwnd = GetDlgItem(hwndDlg, id);
  10. }
  11. ComboBox(HWND control)
  12. {
  13. cbHwnd = control;
  14. }
  15. operator HWND()
  16. {
  17. return cbHwnd;
  18. }
  19. LRESULT AddString(const wchar_t *string)
  20. {
  21. return SendMessageW(cbHwnd, CB_ADDSTRING, 0, (LPARAM)string);
  22. }
  23. LRESULT AddString(const wchar_t *string, LPARAM data)
  24. {
  25. LRESULT index = SendMessageW(cbHwnd, CB_ADDSTRING, 0, (LPARAM)string);
  26. SendMessage(cbHwnd, CB_SETITEMDATA, index, data);
  27. return index;
  28. }
  29. LRESULT AddString(const char *string)
  30. {
  31. return SendMessageA(cbHwnd, CB_ADDSTRING, 0, (LPARAM)string);
  32. }
  33. void SetItemData(LPARAM index, LPARAM data)
  34. {
  35. SendMessage(cbHwnd, CB_SETITEMDATA, index, data);
  36. }
  37. int GetCount()
  38. {
  39. return (int)SendMessage(cbHwnd, CB_GETCOUNT, 0, 0);
  40. }
  41. LRESULT GetItemData(LPARAM index)
  42. {
  43. return SendMessage(cbHwnd, CB_GETITEMDATA, index, 0);
  44. }
  45. void Clear()
  46. {
  47. SendMessage(cbHwnd, CB_RESETCONTENT, 0, 0);
  48. }
  49. void SelectItem(LPARAM index)
  50. {
  51. SendMessage(cbHwnd, CB_SETCURSEL, index, 0);
  52. }
  53. LPARAM GetSelection()
  54. {
  55. return SendMessage(cbHwnd, CB_GETCURSEL, 0, 0);
  56. }
  57. LRESULT SelectString(const wchar_t *str)
  58. {
  59. return SendMessageW(cbHwnd, CB_SELECTSTRING, (WPARAM)-1, (LPARAM)str);
  60. }
  61. LRESULT GetTextLen(int index)
  62. {
  63. return SendMessageW(cbHwnd, CB_GETLBTEXTLEN, (WPARAM)index, 0);
  64. }
  65. void GetText(int index, wchar_t *str)
  66. {
  67. SendMessageW(cbHwnd, CB_GETLBTEXT, (WPARAM)index, (LPARAM)str);
  68. }
  69. #if (_WIN32_WINNT >= 0x0501)
  70. void SetCueBanner(const wchar_t *str)
  71. {
  72. SendMessageW(cbHwnd, CB_SETCUEBANNER, 0, (LPARAM)str);
  73. //CB_SETCUEBANNER;
  74. }
  75. #endif
  76. void SetEditText(const wchar_t *str)
  77. {
  78. SendMessageW(cbHwnd, WM_SETTEXT, 0, (LPARAM)str);
  79. }
  80. unsigned int GetEditText(wchar_t *str, unsigned int cch)
  81. {
  82. return (unsigned int)SendMessageW(cbHwnd, WM_GETTEXT, (WPARAM)cch, (LPARAM)str);
  83. }
  84. HWND cbHwnd;
  85. };
  86. #endif