Before I spend hours on the web searching for these, wonder if any of you may already have links you'd be willing to provide?
What I'm looking for is something to update one of my projects with unicode support. Specifically, the listview & treeview controls. I know that we can coerce these to use a font and code page to enable unicode support for a specific locale, but I'm wanting to use these controls to potentially display multiple locales.
I am not opposed to and am very willing to use APIs to set/retrieve text strings for these controls, but am opposed to using some 3rd party replica. I'm sure there have been a few projects out there that created the API version of these controls & have classes that access them with/without events. CreateWindowEx will be used to create these controls.
Currently, my project does support unicode but only displays unicode on demand as seen in the simple workup I posted below. I'd prefer to display all fields with actual unicode characters vs a "{Unicode}" placeholder that displays the actual characters when activated/double clicked. Haven't really messed with these controls in this respect, otherwise I'd be on the giving end vs. receiving end in this case. Ideas welcomed.
Insomnia is just a byproduct of, "It can't be done"
I tend to begin with stuff like peoples' Common Controls "replacement" projects (I think one here offers the source), vbAccelerator controls, etc. These often aren't well polished but can serve as the starting point to meet a specific need.
Thanks D, I'll browse vbAccelerator. I don't need a full blown suite, just setting/retrieving the list/tree view items basically. Already have the code I need to mess with styles/formatting. And kinda set on using v5 of the controls vs v6 due to themes
Insomnia is just a byproduct of, "It can't be done"
FYI. This was sooooo easy, it's almost a shame that seems none of us were aware of it.
The common controls (at least some of them) appear to be completely Unicode available as of v5.8+. No manifest needed, no subclassing, no API window creation required. More testing needed, but here is a simple example that works on my Vista box:
Code:
' declarations section
Private Type LVITEM
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
Private Const LVM_FIRST As Long = &H1000&
Private Const LVM_SETITEMTEXTW As Long = (LVM_FIRST + 116)
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
' sample call
Dim sText As String
Dim LVI As LVITEM
sText = ChrW$(12434) & ChrW$(21628) & ChrW$(12403) & ChrW$(20986) & ChrW$(12377) & ChrW$(12383) & ChrW$(12417)
With LVI
.pszText = StrPtr(sText)
.cchTextMax = Len(sText) + 1
.iSubItem = 1 ' subitem 1
End With
SendMessage ListView1.hWnd, LVM_SETITEMTEXTW, 0, ByVal VarPtr(LVI)
' the 0 in above line indicates 1st listview item, which are 0-bound when called by API
The 1st example below is result of: ListView1.ListItems(1).SubItems(1) = sText
The 2nd example is use of SendMessage call
Edited: If anyone is trying this at home, ensure the listview's font is true-type
Tested this on WinXP also, themed or unthemed and it works. For far-eastern unicode characters, you must ensure you installed the far-eastern fonts.
Last edited by LaVolpe; Feb 4th, 2015 at 04:08 PM.
Insomnia is just a byproduct of, "It can't be done"
I'm trying to avoid replacing a mature project's controls with 3'rd party versions.
So I made the change to use LVM_INSERTITEMW and still the same no errors and no results.
Code:
Option Explicit
Private Type LVITEM
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
Private Const LVM_FIRST As Long = &H1000&
Private Const LVM_SETITEMTEXTW As Long = (LVM_FIRST + 116)
Private Const LVM_INSERTITEMW As Long = &H104D
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
Private Sub Form_Load()
Dim sText As String
Dim LVI As LVITEM
sText = ChrW$(12434) & ChrW$(21628) & ChrW$(12403) & ChrW$(20986) & ChrW$(12377) & ChrW$(12383) & ChrW$(12417)
With LVI
.pszText = StrPtr(sText)
.cchTextMax = Len(sText) + 1
.iSubItem = 0
End With
SendMessage ListView1.hWnd, LVM_INSERTITEMW, 0, ByVal VarPtr(LVI)
End Sub