Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Add a string or char * to ComboBox win32 c++ (FAQ ?)

258 views
Skip to first unread message

MarinoCpp

unread,
Oct 16, 2008, 12:07:56 PM10/16/08
to
Hi,
I want add a string in a ComboBox, here the code:

char szBuff [100] ;
sprintf_s(szBuff , 100, "This is an Item!");
ComboBox_AddString(hCbox, szBuff);

In this way in the CBox appear a row of *square*.

Thanks.

MarinoCpp

Timo Kunze

unread,
Oct 16, 2008, 12:19:26 PM10/16/08
to
Maybe your combobox is a Unicode window and you're trying to add an ANSI
string? Try this:
TCHAR szBuff [100];
_stprintf_s(szBuff, 100, TEXT("This is an Item!"));
ComboBox_AddString(hCbox, szBuff);

If this doesn't help, make sure your combobox has the CBS_HASSTRINGS
style set.

Timo
--
www.TimoSoft-Software.de - Unicode controls for VB6
"Those who sacrifice freedom for safety deserve neither."
"Demokratie ist per Definition unsicher. Ihr Schutz entsteht aus der
Überzeugung, dass die demokratischen Kräfte überwiegen und sich – auf
demokratischem Wege – durchsetzen."

MarinoCpp

unread,
Oct 16, 2008, 3:18:41 PM10/16/08
to
Timo Kunze ha scritto:

> Maybe your combobox is a Unicode window and you're trying to add an ANSI
> string? Try this:
> TCHAR szBuff [100];
> _stprintf_s(szBuff, 100, TEXT("This is an Item!"));
> ComboBox_AddString(hCbox, szBuff);

Great, this work!
But now I've another problem.
I must insert in the TCHAR string some string codified as char8, like this:

char* author = func(); //where func is not modifiable

_stprintf_s(szBuff, 100, TEXT("Realized by %s"), author);

and this don't work :(
How can I solve this issue?

Another question, if I would make a totally ANSI program how could do I?
(I'm a c++ and win32 newbie!)

Thanks

MarinoCpp


cathy

unread,
Oct 17, 2008, 1:02:53 AM10/17/08
to
> Great, this work!
> But now I've another problem.
> I must insert in the TCHAR string some string codified as char8, like this:
>
> char* author = func(); //where func is not modifiable
>
> _stprintf_s(szBuff, 100, TEXT("Realized by %s"), author);
>
> and this don't work :(
> How can I solve this issue?
>
> Another question, if I would make a totally ANSI program how could do I?
> (I'm a c++ and win32 newbie!)
>
> Thanks
>
> MarinoCpp
>

Hello
- Either your whole project is using char's: in "Project | Properties |
Configuration properties | General" set "Character set" to "Not set" so
that char will work with ComboBox_AddString
- or you only need char for this variable and force the functions used
to be char8 putting an 'A' at the end of the functions (I am not using
ComboBox_AddString, only SendMessage to do the same thing, but I guess
that ComboBox_AddStringA exists and it is the version of
ComboBox_AddString that works with char).
Hope this help
Cathy

MarinoCpp

unread,
Oct 17, 2008, 4:37:54 AM10/17/08
to
cathy ha scritto:

> - or you only need char for this variable and force the functions used
> to be char8 putting an 'A' at the end of the functions (I am not using
> ComboBox_AddString, only SendMessage to do the same thing, but I guess
> that ComboBox_AddStringA exists and it is the version of
> ComboBox_AddString that works with char).

Thanks!! I've solved with SendMessageA

:)

MarinoCpp

0 new messages