Hi.
Have a problem with setting a form caption with russian characters.
The sample code for a Form application:
uses Windows;
function MyWndProc(hWnd: HWND; uiMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
Result := CallWindowProc(OldWProc, hWnd, uiMsg, wParam, lParam);
end;
procedure SetMyWndProc(Handle : HWND);
begin
OldWProc := WNDPROC(SetWindowLongPtr(Handle, GWLP_WNDPROC, LONG_PTR(@MyWndProc)));
end;
procedure TForm1.Button1Click(Sender: TObject);
var s:string;
begin
SetMyWndProc(Handle);
s := 'абв';
Form1.Caption := s;
end;
On the button click I set a window procedure to handle some Win32 messages. Then I change the form Caption to a string containing russian characters. But at the end it shows '???' in the title bar of the form.
If I comment the
SetMyWndProc() part the title updates without problems.
I guess it's the same for other multibyte Unicode characters (chinese for example). Other diacritic characters (like áéíó) are showed fine.
If I dump the caption after I change it (using the
"Showing codepoints with UTF8CharacterToUnicode" from the
UTF8 strings and characters page,
http://wiki.freepascal.org/UTF8_strings_and_characters) it gives me Unicode multibyte values for those 3 characters:
1072
1073
1074
If I set that string to a TLabel or TEdit it renders ok.
So could anyone give me an advice on why it could happen? Maybe there's another param for
CallWindowProc() or
SetWindowLongPtr() to set proper encoding. Or I should convert the caption string before assignment.
Thanks.