.pszText = sNewText & Chr$(0)mais comme les String de VB6 sont unicode, je ne sais pas si c'est bien nécessaire.
With lvi
.mask = ...
...
End With
Private Declare Function SendMessageW Lib "user32" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long--
Private Type LV_ITEM
mask As Long
iItem As Long
iSubItem As Long
State As Long
stateMask As Long
pszText As Long
cchTextMax As Long
iImage As Long
lParam As Long
iIndent As Long
End Type
Public Const LVIF_INDENT As Long = &H10
Public Const LVIF_TEXT As Long = &H1
Public Const LVIF_PARAM = &H4
Public Const LVIF_STATE = &H8
Public Const LVIF_IMAGE = &H2
Public Const LVM_FIRST As Long = &H1000
Public Const LVM_SETITEM = (LVM_FIRST + 6)
Public Const LVM_SETITEMW = (LVM_FIRST + 76)
Public Const LVM_SETITEMTEXT = (LVM_FIRST + 46)
Public Const LVM_SETITEMTEXTW = (LVM_FIRST + 116)
Public Sub SetText(ByVal lhwnd As Long, ByVal lIndex As Long, ByVal sNewText As String)
Dim lvi As LV_ITEM
Dim rep As Long
With lvi
.iItem = lIndex
.mask = LVIF_TEXT
.pszText = StrPtr(sNewText & vbNullChar)
.cchTextMax = LenB(sNewText) + 2
End With
rep = SendMessageW(lhwnd, LVM_SETITEMW, lIndex, lvi)
End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionWith lviPas de .iITem ni de .mask
.pszText = StrPtr(sNewText)
.cchTextMax = Len(sNewText)
End With
rep = SendMessageW(lhwnd, LVM_SETITEMTEXTW, lIndex, lvi)
... LVM_SETITEMTEXTW, ByVal lIndex, lvi)
Private Declare Function SendMessageW _A tester
Lib "user32" (ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Function zConvertStringToUtf8Bytes(ByRef strText As String) As Byte()
Dim objStream As ADODB.Stream
Dim data() As Byte
' init du stream
Set objStream = New ADODB.Stream
objStream.Charset = "utf-8"
objStream.Mode = adModeReadWrite
objStream.Type = adTypeText
objStream.Open
' écrit les bytes originaux dans le stream
objStream.WriteText strText
objStream.Flush
' Repositionne en tête du stream
objStream.Position = 0
objStream.Type = adTypeBinary
' Saute les 3 premiers bytes identifiant l'UTF-8
'##### Voir s'il ne faudrait pas mieux les laisser
objStream.Read 3
data = objStream.Read()
' Ferme le stream et renvoie le résultat
objStream.Close
zConvertStringToUtf8Bytes = data
End Function
TheString = StrConv(data(), vbUnicode)
cchTextMax = UBound(theTableau) + 1Le "+1" pour l'index 0
pszText = theTableau(0)
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const STANDARD_RIGHTS_REQUIRED As Long = &HF0000
Private Const SYNCHRONIZE As Long = &H100000
Private Const PROCESS_ALL_ACCESS As Long = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)
Private Const MEM_COMMIT As Long = &H1000
Private Const PAGE_READWRITE As Long = &H4
Private Const MEM_RELEASE As Long = &H8000
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal Handle As Long) As Long
Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Private Declare Function VirtualAllocEx Lib "kernel32.dll" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
Private Declare Function VirtualFreeEx Lib "kernel32.dll" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwSize As Long, ByVal dwFreeType As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32.dll" (ByVal hProcess As Long, ByVal lpBaseAddress As Long, ByRef lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Function ListView_SetItemText(ByVal hWnd As Long, _
ByVal iItem As Long, _
ByVal iSubItem As Long, _
ByVal ItemText As String) As Boolean
Dim PID As Long
Dim hProcess As Long
Dim nSize As Long
Dim plvItem As Long
Dim p_MyItemText As Long
Dim myItem As LV_ITEM
nSize = LenB(StrConv(ItemText, vbFromUnicode))
GetWindowThreadProcessId hWnd, PID
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, PID)
If hProcess <> 0 Then
plvItem = VirtualAllocEx(hProcess, 0, Len(myItem), MEM_COMMIT, PAGE_READWRITE)
p_MyItemText = VirtualAllocEx(hProcess, 0, nSize, MEM_COMMIT, PAGE_READWRITE)
myItem.iSubItem = iSubItem
myItem.pszText = p_MyItemText
If plvItem And p_MyItemText Then
Call WriteProcessMemory(hProcess, p_MyItemText, ByVal ItemText, nSize, 0)
Call WriteProcessMemory(hProcess, plvItem, myItem, Len(myItem), 0)
Call SendMessage(hWnd, LVM_SETITEMTEXT, iItem, ByVal plvItem)
ListView_SetItemText = True
CloseHandle (hWnd)
CloseHandle (hProcess)
Call VirtualFreeEx(hProcess, plvItem, 0, MEM_RELEASE)
Call VirtualFreeEx(hProcess, p_MyItemText, 0, MEM_RELEASE)
End If
End If
End Function
With ListView1
.Font.Name = "Arial Unicode MS"
.Font.Charset = 134 ' Chinois
.ListItems.Add , , "Coucou Coucou Coucou Coucou Coucou"
.ListItems.Add , , "Coucou Coucou Coucou Coucou Coucou"
.ListItems.Add , , "Coucou Coucou Coucou Coucou Coucou"
.ListItems.Add , , "Coucou Coucou Coucou Coucou Coucou"
.ListItems.Add , , "Coucou Coucou Coucou Coucou Coucou"
End With
Private Sub Command1_Click()
' Voir les exemples de textes sur
' http://www.cyberactivex.com/UnicodeTutorialVb.htm
Dim sTemp As String
Dim aByte() As Byte
Dim theString As String
Dim LCID As Long
Dim r As Long
' LCID : Voir http://msdn.microsoft.com/en-us/goglobal/bb964664.aspx
' Chinois
sTemp = "CHS: " & ChrW$(&H6B22) & ChrW$(&H8FCE)
LCID = 2052
aByte = StrConv(sTemp, vbFromUnicode, LCID)
theString = StrConv(aByte, vbUnicode)
Call ListView_SetItemText(ListView1.hWnd, 2, 0, theString)
Exit Sub
'--- Pour les suivants, il faut modifier le Charset de la fonte
' mais ça modifie aussi les textes déjà existant !
' Koréen
sTemp = "KOR: " & ChrW$(&HC5EC) & ChrW$(&HBCF4) & ChrW$(&HC138) & ChrW$(&HC694)
LCID = 1042
aByte = StrConv(sTemp, vbFromUnicode, LCID)
theString = StrConv(aByte, vbUnicode)
Call ListView_SetItemText(ListView1.hWnd, 1, 0, theString)
' Hindi
sTemp = "HIN: " & ChrW$(&H930) & ChrW$(&H935) & ChrW$(&H93E) & ChrW$(&H917) & ChrW$(&H924)
LCID = 1081
aByte = StrConv(sTemp, vbFromUnicode, LCID)
theString = StrConv(aByte, vbUnicode)
Call ListView_SetItemText(ListView1.hWnd, 3, 0, theString)
' For r = 5 To UBound(aByte)
' Debug.Print r, aByte(r)
' Next r
End Sub
sclass = "SysListView32" hListView = CreateWindowExW(WS_EX_OVERLAPPEDWINDOW, StrPtr(sclass), "", WS_CHILD Or _ WS_VISIBLE Or LVS_REPORT, 10, 10, 500, 200, Form1.hWnd, 0, App.hInstance, ByVal CLng(0))
With objColumnAjouter des items
.mask = LVCF_TEXT Or LVCF_WIDTH
.cchTextMax = Len(myString)
.pszText = StrPtr(myString)
.cx = 100
End With
rep = SendMessageW(hListView, LVM_INSERTCOLUMNW, 0, objColumn)
with lviredimensionner les colonnes
.iItem = 0
.mask = LVIF_IMAGE Or LVIF_TEXT
.cchTextMax = Len(myString1)
.pszText = StrPtr(myString1)
end With
rep = SendMessageW(hListView, LVM_INSERTITEMW, 0, lvi)
rep = SendMessageW(hListView, LVM_SETCOLUMNWIDTH, 0, ByVal CLng(200))
Public Sub SetText(ByVal lhwnd As Long, ByVal lIndex As Long, ByVal sNewText As String)
Dim lvi As LV_ITEM
Dim rep As Long
With lvi
.iItem = lIndex
.mask = LVIF_TEXT
.pszText = StrPtr(sNewText)
.cchTextMax = Len(sNewText)
End With
rep = SendMessageW(lhwnd, LVM_SETITEMTEXTW, lIndex, lvi)
End Sub