1// Windows/Control/ComboBox.h
2
3#ifndef ZIP7_INC_WINDOWS_CONTROL_COMBOBOX_H
4#define ZIP7_INC_WINDOWS_CONTROL_COMBOBOX_H
5
6#include "../../Common/MyWindows.h"
7
8#include <CommCtrl.h>
9
10#include "../Window.h"
11
12namespace NWindows {
13namespace NControl {
14
15class CComboBox: public CWindow
16{
17public:
18  void ResetContent() { SendMsg(CB_RESETCONTENT, 0, 0); }
19  LRESULT AddString(LPCTSTR s) { return SendMsg(CB_ADDSTRING, 0, (LPARAM)s); }
20  #ifndef _UNICODE
21  LRESULT AddString(LPCWSTR s);
22  #endif
23
24  /* If this parameter is -1, any current selection in the list is removed and the edit control is cleared.*/
25  LRESULT SetCurSel(int index) { return SendMsg(CB_SETCURSEL, MY_int_TO_WPARAM(index), 0); }
26  LRESULT SetCurSel(unsigned index) { return SendMsg(CB_SETCURSEL, index, 0); }
27
28  /* If no item is selected, it returns CB_ERR (-1) */
29  int GetCurSel() { return (int)SendMsg(CB_GETCURSEL, 0, 0); }
30
31  /*  If an error occurs, it is CB_ERR (-1) */
32  int GetCount() { return (int)SendMsg(CB_GETCOUNT, 0, 0); }
33
34  LRESULT GetLBTextLen(int index) { return SendMsg(CB_GETLBTEXTLEN, MY_int_TO_WPARAM(index), 0); }
35  LRESULT GetLBText(int index, LPTSTR s) { return SendMsg(CB_GETLBTEXT, MY_int_TO_WPARAM(index), (LPARAM)s); }
36  LRESULT GetLBText(int index, CSysString &s);
37  #ifndef _UNICODE
38  LRESULT GetLBText(int index, UString &s);
39  #endif
40
41  LRESULT SetItemData(int index, LPARAM lParam) { return SendMsg(CB_SETITEMDATA, MY_int_TO_WPARAM(index), lParam); }
42  LRESULT GetItemData(int index) { return SendMsg(CB_GETITEMDATA, MY_int_TO_WPARAM(index), 0); }
43  LRESULT GetItemData(unsigned index) { return SendMsg(CB_GETITEMDATA, index, 0); }
44
45  LRESULT GetItemData_of_CurSel() { return GetItemData(GetCurSel()); }
46
47  void ShowDropDown(bool show = true) { SendMsg(CB_SHOWDROPDOWN, show ? TRUE : FALSE, 0);  }
48};
49
50#ifndef UNDER_CE
51
52class CComboBoxEx: public CComboBox
53{
54public:
55  bool SetUnicodeFormat(bool fUnicode) { return LRESULTToBool(SendMsg(CBEM_SETUNICODEFORMAT, BOOLToBool(fUnicode), 0)); }
56
57  /* Returns:
58      an INT value that represents the number of items remaining in the control.
59      If (index) is invalid, the message returns CB_ERR. */
60  LRESULT DeleteItem(int index) { return SendMsg(CBEM_DELETEITEM, MY_int_TO_WPARAM(index), 0); }
61
62  LRESULT InsertItem(COMBOBOXEXITEM *item) { return SendMsg(CBEM_INSERTITEM, 0, (LPARAM)item); }
63  #ifndef _UNICODE
64  LRESULT InsertItem(COMBOBOXEXITEMW *item) { return SendMsg(CBEM_INSERTITEMW, 0, (LPARAM)item); }
65  #endif
66
67  LRESULT SetItem(COMBOBOXEXITEM *item) { return SendMsg(CBEM_SETITEM, 0, (LPARAM)item); }
68  DWORD SetExtendedStyle(DWORD exMask, DWORD exStyle) { return (DWORD)SendMsg(CBEM_SETEXTENDEDSTYLE, exMask, (LPARAM)exStyle); }
69  HWND GetEditControl() { return (HWND)SendMsg(CBEM_GETEDITCONTROL, 0, 0); }
70  HIMAGELIST SetImageList(HIMAGELIST imageList) { return (HIMAGELIST)SendMsg(CBEM_SETIMAGELIST, 0, (LPARAM)imageList); }
71};
72
73#endif
74
75}}
76
77#endif
78