Re: Trouble subclassing listview to display unicode (chinese)



On Nov 21, 9:53 am, "Thorsten Albers" <alber...@xxxxxxxxxxxxxxxxxxx>
wrote:
AFAIK the control isn't enabled to display Unicode strings, you have to do
that by your own code. For this you have to create the ListView window with
the LVS_OWNERDRAWFIXED style which AFAIK is supported only in report view
of the ListView control.

That's okay, since I only want the report view of the listview control.

After getting a WM_DRAWITEM message you have to draw the text e.g. with the
API function TextOutW() - note the trailing "W" which designates the wide
character (= Unicode) string version of TextOut(); in addition note that
you have to pass a string to a function's "W" version not "ByVal/ByRef As
String" but "ByVal As Long" and Call xyz(StrPtr(MyString)).

This makes sense, and I'll try it out.

I still don't quite understand why (or even if) this method is
different from the one getting getting the WM_SETTEXT; I'm a bit new to
the winapi. I got the idea from microsoft.public.cn.vb (who
incidentally took it from this group) on May 13 2004. I post it here.
What am I not understanding in the difference between this method and
the one suggested by Thorsten?

-----microsoft.public.cn.vb-----
First, sub-class the window as usual, but use the SetWindowLongW
function to allow Unicode support (and prevent Windows from converting
Unicode to ANSI automatically before it gets to your handler).

Second, trap the WM_SETTEXT message in your handler.

Third, extract the Unicode string from your message and pass it through
to the DefWindowProcW function, like so:
DefWindowProcW hWnd, WM_SETTEXT, 0, StrPtr(m_strBuffer)

Fourth, don't forget to "discard" the handled message by returning 0
for
your handler function.

That's all it takes!

As an interesting side note, you can also display valid Unicode text
for
the CommandButton, OptionButton, CheckBox & Frame caption properties if
you pass the control hWnd into that same function, like so:

Private Declare Function DefWindowProc Lib "user32" Alias
"DefWindowProcW" ( _
ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long

Public Sub SetUnicodeWindowText(ByVal hWnd As Long, ByVal NewText As
String)
DefWindowProc hWnd, WM_SETTEXT, &H0&, StrPtr(NewText)
End Sub

In your form, just do something like:

strNewText = "My string with Unicode characters"
Call SetUnicodeWindowText(Me.CommandButton.hWnd, VarPtr(strNewText))

.