#include "SRComboBox.h" #include "SRApp.h" #include using namespace SRFramework; SRComboBox::SRComboBox(void) { m_hInstance = SRFramework::SRApp::GetInstanceHandle(); m_wcsClassName = "combobox"; m_wcsWindowName = ""; } SRComboBox::~SRComboBox(void) { } BOOL SRComboBox::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 SRComboBox::GetText() { TCHAR *strQuery = NULL; WCString wcsQuery; 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 wcsQuery = strQuery; delete [] strQuery; return wcsQuery; } WCString SRComboBox::GetItemAt(INT nItemIndex) { TCHAR *strQuery = NULL; WCString wcsQuery; INT nQueryLen = ::SendMessage(m_hWnd, CB_GETLBTEXTLEN, (WPARAM)nItemIndex, NULL) + 1; strQuery = new TCHAR[nQueryLen]; ::SendMessage(m_hWnd,CB_GETLBTEXT,(WPARAM)nItemIndex,(LPARAM)strQuery); strQuery[nQueryLen - 1] = 0; // in case the buffer was exceeded wcsQuery = strQuery; delete [] strQuery; return wcsQuery; } VOID SRComboBox::Clear() { ::SendMessage (m_hWnd, CB_RESETCONTENT,0,0); } INT SRComboBox::AddItem(const WCString &wcsItem) { return ::SendMessage (m_hWnd, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)wcsItem.w_str()); } INT SRComboBox::InsertItem(INT nItemIndex, const WCString &wcsItem) { return ::SendMessage (m_hWnd, CB_INSERTSTRING, nItemIndex, (LPARAM)(LPCTSTR)wcsItem.w_str()); } INT SRComboBox::DeleteItem(INT nItemIndex) { return ::SendMessage (m_hWnd, CB_DELETESTRING, nItemIndex, NULL); } INT SRComboBox::FindItem(const WCString &wcsItem) { return ::SendMessage (m_hWnd, CB_FINDSTRING, 0, (LPARAM)(LPCTSTR)wcsItem.w_str()); } INT SRComboBox::SelectItem(const WCString &wcsItem) { return ::SendMessage (m_hWnd, CB_SELECTSTRING, 0, (LPARAM)(LPCTSTR)wcsItem.w_str()); } INT SRComboBox::SetCurSel(INT nItemIndex) { return ::SendMessage(m_hWnd, CB_SETCURSEL, (WPARAM)nItemIndex, 0); } INT SRComboBox::GetCurSel() { return ::SendMessage (m_hWnd, CB_GETCURSEL, 0,0); } BOOL SRComboBox::SetText(const WCString &text) { return ::SendMessage(m_hWnd, WM_SETTEXT, NULL, (LPARAM)text.w_str()); } BOOL SRComboBox::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { INT a = 0; switch(nChar) { case VK_UP: break; case VK_DOWN: break; case VK_LEFT: break; case VK_RIGHT: break; default: return FALSE; } return TRUE; }