1 Attachment(s)
[RESOLVED] ListView/Treeview API Classes?
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.
Re: ListView/Treeview API Classes?
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.
Re: ListView/Treeview API Classes?
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
Re: ListView/Treeview API Classes?
Spot on. Krools project in the code bank appears to have what I need. Just need to sift thru it.
Re: [RESOLVED] ListView/Treeview API Classes?
http://btmtz.mvps.org/
LaVolpe: You might also want to take a look at Brad's site. Has both.
2 Attachment(s)
Re: [RESOLVED] ListView/Treeview API Classes?
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
Attachment 123485
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.
Re: [RESOLVED] ListView/Treeview API Classes?
Is the above code (as is) supposed to work on Win 10?
No errors but nothing added to a 1 column Listview (ver 5 common controls) in report mode using your sample unicode string.
Re: [RESOLVED] ListView/Treeview API Classes?
That code sets the text of existing items. You'd have to add the items first or just LVM_INSERTITEMW instead.
Your best bet today if you need Unicode is just using Krool's Common Controls Replacements instead of the original VB6 ocxs.
Re: [RESOLVED] ListView/Treeview API Classes?
Quote:
Originally Posted by
fafalone
That code sets the text of existing items. You'd have to add the items first or just LVM_INSERTITEMW instead.
Your best bet today if you need Unicode is just using
Krool's Common Controls Replacements instead of the original VB6 ocxs.
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
Re: [RESOLVED] ListView/Treeview API Classes?
Dim li As ListItem
Set li = ListView1.ListItems.Add(0, , "Item 1")
Then use the original SETITEMTEXTW call.
LVM_INSERTITEMW requires more changes than just the message and I don't think VB will know about it.
Re: [RESOLVED] ListView/Treeview API Classes?