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 12 namespace NWindows { 13 namespace NControl { 14 15 class CComboBox: public CWindow 16 { 17 public: ResetContent()18 void ResetContent() { SendMsg(CB_RESETCONTENT, 0, 0); } AddString(LPCTSTR s)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.*/ SetCurSel(int index)25 LRESULT SetCurSel(int index) { return SendMsg(CB_SETCURSEL, MY_int_TO_WPARAM(index), 0); } SetCurSel(unsigned index)26 LRESULT SetCurSel(unsigned index) { return SendMsg(CB_SETCURSEL, index, 0); } 27 28 /* If no item is selected, it returns CB_ERR (-1) */ GetCurSel()29 int GetCurSel() { return (int)SendMsg(CB_GETCURSEL, 0, 0); } 30 31 /* If an error occurs, it is CB_ERR (-1) */ GetCount()32 int GetCount() { return (int)SendMsg(CB_GETCOUNT, 0, 0); } 33 GetLBTextLen(int index)34 LRESULT GetLBTextLen(int index) { return SendMsg(CB_GETLBTEXTLEN, MY_int_TO_WPARAM(index), 0); } GetLBText(int index,LPTSTR s)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 SetItemData(int index,LPARAM lParam)41 LRESULT SetItemData(int index, LPARAM lParam) { return SendMsg(CB_SETITEMDATA, MY_int_TO_WPARAM(index), lParam); } GetItemData(int index)42 LRESULT GetItemData(int index) { return SendMsg(CB_GETITEMDATA, MY_int_TO_WPARAM(index), 0); } GetItemData(unsigned index)43 LRESULT GetItemData(unsigned index) { return SendMsg(CB_GETITEMDATA, index, 0); } 44 GetItemData_of_CurSel()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 52 class CComboBoxEx: public CComboBox 53 { 54 public: SetUnicodeFormat(bool fUnicode)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. */ DeleteItem(int index)60 LRESULT DeleteItem(int index) { return SendMsg(CBEM_DELETEITEM, MY_int_TO_WPARAM(index), 0); } 61 InsertItem(COMBOBOXEXITEM * item)62 LRESULT InsertItem(COMBOBOXEXITEM *item) { return SendMsg(CBEM_INSERTITEM, 0, (LPARAM)item); } 63 #ifndef _UNICODE InsertItem(COMBOBOXEXITEMW * item)64 LRESULT InsertItem(COMBOBOXEXITEMW *item) { return SendMsg(CBEM_INSERTITEMW, 0, (LPARAM)item); } 65 #endif 66 SetItem(COMBOBOXEXITEM * item)67 LRESULT SetItem(COMBOBOXEXITEM *item) { return SendMsg(CBEM_SETITEM, 0, (LPARAM)item); } SetExtendedStyle(DWORD exMask,DWORD exStyle)68 DWORD SetExtendedStyle(DWORD exMask, DWORD exStyle) { return (DWORD)SendMsg(CBEM_SETEXTENDEDSTYLE, exMask, (LPARAM)exStyle); } GetEditControl()69 HWND GetEditControl() { return (HWND)SendMsg(CBEM_GETEDITCONTROL, 0, 0); } SetImageList(HIMAGELIST imageList)70 HIMAGELIST SetImageList(HIMAGELIST imageList) { return (HIMAGELIST)SendMsg(CBEM_SETIMAGELIST, 0, (LPARAM)imageList); } 71 }; 72 73 #endif 74 75 }} 76 77 #endif 78