#31 problem with unicode win32 ListView Control

open
nobody
None
5
2014-08-26
2008-11-10
lys
No

I am using ctype to insert both ascii and unicode data to win32 ListView Control , using the following structure

class LV_ITEM(Structure):
_fields_ = [('mask', c_uint),
('iItem', c_int),
('iSubItem', c_int),
('state', c_uint),
('stateMask', c_uint),
# ('pszText', c_char_p), # for ascii data
('pszText', c_wchar_p), # for unicode data
('cchTextMax', c_int),
('iImage', c_int),
('lParam', c_long),
# ('iIndent', c_int),
# ('iGroupId', c_int),
# ('cColumns', c_uint),
# ('puColumns', c_uint)
]

It is successful for ascii data , but unsuccessful for unicode data .

The code lines I used to set LisView Control data are

def lvc_insert(list,i,s) :
lv_item=LV_ITEM()
lv_item.mask=commctrl.LVIF_TEXT
lv_item.iItem=i
lv_item.iSubItem=0
lv_item.state=0
lv_item.stateMask=0
#lv_item.pszText=s[0]
lv_item.pszText=u"abc123"
lv_item.cchTextMax=len(s[0])+2
#lv_item.cchTextMax=(len(s[0])+2)*2+100
lv_item.iImage=0
lv_item.lParam=i

windll.user32.SendMessageW(list,commctrl.LVM_INSERTITEM,0,byref(lv_item))

lv_item.mask=commctrl.LVIF_TEXT
lv_item.iSubItem=1
#lv_item.pszText=s[1]
lv_item.pszText=u"abc123"
lv_item.cchTextMax=len(s[1])+2
#lv_item.cchTextMax=(len(s[1])+2)*2+100

windll.user32.SendMessageW(list,commctrl.LVM_SETITEM,0,byref(lv_item))

I have checked that the ListView Control is in unicode mode , because the following code line print 1 .

print windll.user32.SendMessageW(hList,commctrl.LVM_GETUNICODEFORMAT,0,0)

I have try the code line [set_conversion_mode("utf-16","strict")] , but , it has no help to the problem .

It seems that , only the first character of the data (u"abc123") is set in the ListView Control , the remaining characters of the data are lost .
(I think , the truncation is caused by the zero in the unicode of the first character 'a ' for the data u"abc123" !)

I have written the same unicode program (python) , but using ListBox Control , and , it works fine !

I have a C version unicode ListView Control program (with the same functionality as the python version) , it also works fine !

Finally , I conclude that , there is something wrong between ctype and ListView Control , when transferring unicode data !

The cytpe and python versions I used are 1.0.2 and 2.4.3 !
The operating system I used is WinXP !

Discussion