#include "SRListBox.h" #include "SRApp.h" #include using namespace SRFramework; SRListBox::SRListBox(void) { INITCOMMONCONTROLSEX InitCtrlEx; InitCtrlEx.dwSize = sizeof(INITCOMMONCONTROLSEX); InitCtrlEx.dwICC = ICC_TAB_CLASSES; InitCommonControlsEx(&InitCtrlEx); m_hInstance = SRFramework::SRApp::GetInstanceHandle(); m_wcsClassName = "listbox"; m_wcsWindowName = ""; } SRListBox::~SRListBox(void) { } BOOL SRListBox::Create(SRWnd *pParentWnd, RECT bounds, INT nChildID, DWORD dwStyle) { if(!Register()) return FALSE; if(!SRWnd::Create(m_wcsClassName,m_wcsWindowName, dwStyle, bounds, pParentWnd, (HMENU)nChildID, m_hInstance)) return FALSE; return TRUE; } WCString SRListBox::GetText() { TCHAR *strQuery = NULL; INT nQueryLen = ::SendMessage(m_hWnd, WM_GETTEXTLENGTH, NULL, NULL) + 1; strQuery = new TCHAR[nQueryLen]; ::SendMessage(m_hWnd,WM_GETTEXT,(WPARAM)nQueryLen,(LPARAM)strQuery); strQuery[nQueryLen - 1] = 0; // in case the buffer was exceeded return strQuery; } VOID SRListBox::Clear() { ::SendMessage (m_hWnd, LB_RESETCONTENT,0,0); } INT SRListBox::AddItem(const WCString &wcsItem) { return ::SendMessage (m_hWnd, LB_ADDSTRING, 0, (LPARAM)(LPCTSTR)wcsItem.w_str()); } INT SRListBox::InsertItem(INT nItemIndex, const WCString &wcsItem) { return ::SendMessage (m_hWnd, LB_INSERTSTRING, nItemIndex, (LPARAM)(LPCTSTR)wcsItem.w_str()); } INT SRListBox::DeleteItem(INT nItemIndex) { return ::SendMessage (m_hWnd, LB_DELETESTRING, nItemIndex, NULL); } INT SRListBox::FindItem(const WCString &wcsItem) { return ::SendMessage (m_hWnd, LB_FINDSTRING, 0, (LPARAM)(LPCTSTR)wcsItem.w_str()); } INT SRListBox::SelectItem(const WCString &wcsItem) { return ::SendMessage (m_hWnd, LB_FINDSTRING, 0, (LPARAM)(LPCTSTR)wcsItem.w_str()); } INT SRListBox::GetCurSel() { return ::SendMessage (m_hWnd, LB_GETCURSEL, 0,0); }