1370b324cSopenharmony_ci// Windows/Control/ComboBox.cpp 2370b324cSopenharmony_ci 3370b324cSopenharmony_ci#include "StdAfx.h" 4370b324cSopenharmony_ci 5370b324cSopenharmony_ci#ifndef _UNICODE 6370b324cSopenharmony_ci#include "../../Common/StringConvert.h" 7370b324cSopenharmony_ci#endif 8370b324cSopenharmony_ci 9370b324cSopenharmony_ci#include "ComboBox.h" 10370b324cSopenharmony_ci 11370b324cSopenharmony_ci#ifndef _UNICODE 12370b324cSopenharmony_ciextern bool g_IsNT; 13370b324cSopenharmony_ci#endif 14370b324cSopenharmony_ci 15370b324cSopenharmony_cinamespace NWindows { 16370b324cSopenharmony_cinamespace NControl { 17370b324cSopenharmony_ci 18370b324cSopenharmony_ciLRESULT CComboBox::GetLBText(int index, CSysString &s) 19370b324cSopenharmony_ci{ 20370b324cSopenharmony_ci s.Empty(); 21370b324cSopenharmony_ci LRESULT len = GetLBTextLen(index); // length, excluding the terminating null character 22370b324cSopenharmony_ci if (len == CB_ERR) 23370b324cSopenharmony_ci return len; 24370b324cSopenharmony_ci LRESULT len2 = GetLBText(index, s.GetBuf((unsigned)len)); 25370b324cSopenharmony_ci if (len2 == CB_ERR) 26370b324cSopenharmony_ci return len; 27370b324cSopenharmony_ci if (len > len2) 28370b324cSopenharmony_ci len = len2; 29370b324cSopenharmony_ci s.ReleaseBuf_CalcLen((unsigned)len); 30370b324cSopenharmony_ci return len; 31370b324cSopenharmony_ci} 32370b324cSopenharmony_ci 33370b324cSopenharmony_ci#ifndef _UNICODE 34370b324cSopenharmony_ciLRESULT CComboBox::AddString(LPCWSTR s) 35370b324cSopenharmony_ci{ 36370b324cSopenharmony_ci if (g_IsNT) 37370b324cSopenharmony_ci return SendMsgW(CB_ADDSTRING, 0, (LPARAM)s); 38370b324cSopenharmony_ci return AddString(GetSystemString(s)); 39370b324cSopenharmony_ci} 40370b324cSopenharmony_ci 41370b324cSopenharmony_ciLRESULT CComboBox::GetLBText(int index, UString &s) 42370b324cSopenharmony_ci{ 43370b324cSopenharmony_ci s.Empty(); 44370b324cSopenharmony_ci if (g_IsNT) 45370b324cSopenharmony_ci { 46370b324cSopenharmony_ci LRESULT len = SendMsgW(CB_GETLBTEXTLEN, MY_int_TO_WPARAM(index), 0); 47370b324cSopenharmony_ci if (len == CB_ERR) 48370b324cSopenharmony_ci return len; 49370b324cSopenharmony_ci LRESULT len2 = SendMsgW(CB_GETLBTEXT, MY_int_TO_WPARAM(index), (LPARAM)s.GetBuf((unsigned)len)); 50370b324cSopenharmony_ci if (len2 == CB_ERR) 51370b324cSopenharmony_ci return len; 52370b324cSopenharmony_ci if (len > len2) 53370b324cSopenharmony_ci len = len2; 54370b324cSopenharmony_ci s.ReleaseBuf_CalcLen((unsigned)len); 55370b324cSopenharmony_ci return len; 56370b324cSopenharmony_ci } 57370b324cSopenharmony_ci AString sa; 58370b324cSopenharmony_ci const LRESULT len = GetLBText(index, sa); 59370b324cSopenharmony_ci if (len == CB_ERR) 60370b324cSopenharmony_ci return len; 61370b324cSopenharmony_ci s = GetUnicodeString(sa); 62370b324cSopenharmony_ci return (LRESULT)s.Len(); 63370b324cSopenharmony_ci} 64370b324cSopenharmony_ci#endif 65370b324cSopenharmony_ci 66370b324cSopenharmony_ci}} 67