aboutsummaryrefslogtreecommitdiff
path: root/CPP/Windows/Control/ComboBox.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/Windows/Control/ComboBox.cpp')
-rw-r--r--CPP/Windows/Control/ComboBox.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/CPP/Windows/Control/ComboBox.cpp b/CPP/Windows/Control/ComboBox.cpp
new file mode 100644
index 0000000..f6ed8d3
--- /dev/null
+++ b/CPP/Windows/Control/ComboBox.cpp
@@ -0,0 +1,66 @@
1// Windows/Control/ComboBox.cpp
2
3#include "StdAfx.h"
4
5#ifndef _UNICODE
6#include "../../Common/StringConvert.h"
7#endif
8
9#include "ComboBox.h"
10
11#ifndef _UNICODE
12extern bool g_IsNT;
13#endif
14
15namespace NWindows {
16namespace NControl {
17
18LRESULT CComboBox::GetLBText(int index, CSysString &s)
19{
20 s.Empty();
21 LRESULT len = GetLBTextLen(index); // length, excluding the terminating null character
22 if (len == CB_ERR)
23 return len;
24 LRESULT len2 = GetLBText(index, s.GetBuf((unsigned)len));
25 if (len2 == CB_ERR)
26 return len;
27 if (len > len2)
28 len = len2;
29 s.ReleaseBuf_CalcLen((unsigned)len);
30 return len;
31}
32
33#ifndef _UNICODE
34LRESULT CComboBox::AddString(LPCWSTR s)
35{
36 if (g_IsNT)
37 return SendMsgW(CB_ADDSTRING, 0, (LPARAM)s);
38 return AddString(GetSystemString(s));
39}
40
41LRESULT CComboBox::GetLBText(int index, UString &s)
42{
43 s.Empty();
44 if (g_IsNT)
45 {
46 LRESULT len = SendMsgW(CB_GETLBTEXTLEN, MY__int_TO_WPARAM(index), 0);
47 if (len == CB_ERR)
48 return len;
49 LRESULT len2 = SendMsgW(CB_GETLBTEXT, MY__int_TO_WPARAM(index), (LPARAM)s.GetBuf((unsigned)len));
50 if (len2 == CB_ERR)
51 return len;
52 if (len > len2)
53 len = len2;
54 s.ReleaseBuf_CalcLen((unsigned)len);
55 return len;
56 }
57 AString sa;
58 LRESULT len = GetLBText(index, sa);
59 if (len == CB_ERR)
60 return len;
61 s = GetUnicodeString(sa);
62 return s.Len();
63}
64#endif
65
66}}