c++ - wsprintfW printing only tens? -


i have trackbar , @ point it's value supposed change text:

case wm_hscroll:     {         lresult pos = sendmessage(trackbar, tbm_getpos, 0, 0);         wchar buf[3];         wsprintfw(buf, l"%ld", pos);          setwindowtext(trackbarvalue, (lpcstr)buf);     }     break; 

the trackbar's range goes 15 35. reason, tens gets printed text (as trackbar's value between 15 , 19, text 1, when trackbar's value between 20 , 29, text 2, , becomes 3 trackbar's value between 30 , 35.

of course, want text show absolute value of trackbar, not tens!

what should do?

edit: after running debugger, know buf become trackbar's value. problem seems setwindowtext line.

edit: 1 solution to change setwindowtext setwindowtextw , remove (lpcstr) cast. people.

you casting wide char string simple string, wrong. have use widechartomultibyte, this:

size_t size = widechartomultibyte(cp_acp, 0, buf, -1, null, 0, null, null);  char *szto = new char[size]; widechartomultibyte(cp_acp, 0, buf, -1, szto, size, null, null);  // don't forget delete[] szto 

alternatively, define application unicode-compliant, setwindowtext macro resolve setwindowtextw:

#define unicode #define _unicode #include <windows.h> 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -