Forum > General

Form Caption encoding for russian characters with CallWindowProc

(1/2) > >>

mortalis:
Hi.
Have a problem with setting a form caption with russian characters.
The sample code for a Form application:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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.

Thaddy:
CallWindowProcW. I have to check but I think CallWindowProc is still aliased to CallWindowProcA.
Maybe {$mode delphiunicode} will help?

And, yes, I checked, the W goes through all unicode functions EVEN IF there is no obvious string involved here.

mortalis:
Using CallWindowProcW() gives me an asian character and a '?' (IMG1).

And the {$mode delphiunicode} directive gives me IMG2 (label and edit showed the string well before and the title seems to be converted to some other encoding). The default directive created by Lazarus is {$mode objfpc}{$H+}.

Anyway it's a little better than plain ?'s.
Maybe it lacks some encoding convertion, from/to Unicode/UTF8/CP1251/...

balazsszekely:
You should also change SetWindowLongPtr to SetWindowLongPtrW.

mortalis:
That's right.
So CallWindowProcW and SetWindowLongPtrW.
The problem solved.
Thanks a lot.

Navigation

[0] Message Index

[#] Next page

Go to full version