Link to home
Start Free TrialLog in
Avatar of rosethorn111199
rosethorn111199

asked on

Cyrillic in Menus

I am writing a program that must operate in multiple languages.  To do this I use a file which contains all the programming text, displays etc.  This works very nicely until I hit a Cyrillic application.

I can create the text file so that it will display cyrillic in input dialog boxes, the results area, and a display map.  However I can't get the cyrillic to show in the menu items and message boxes.

I have look through the properties of the things that don't work and none of them have the Font - Charset property.  In the other pieces I set this to Russian_Charset and things work properly.

How can I set the Charset for the Menu and Message boxes?

Cheers
Avatar of Igor UL7AAjr
Igor UL7AAjr
Flag of Kazakhstan image

What you see in menu? Something like this: "ýòî òåõò íà ðóññêì ÿçûêå"?
Is it?
Avatar of rosethorn111199
rosethorn111199

ASKER

Yes that is exactly what I am seeing now.

Cheers
Paul
Well, tell me more about your windows version, is it NT?
Hi rosethorn,
To handle this problem you need to use ownderdraw (draw the menu yourself). Example unit:

 
unit Odmenu1;
 
interface
 
uses
  SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,   Forms, Dialogs, Menus, StdCtrls;
 
type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    Test1: TMenuItem;
    Font1: TMenuItem;
    FontDialog1: TFontDialog;
    DisableFont1: TMenuItem;
    EnableFont1: TMenuItem;
    N1: TMenuItem;
    Exit1: TMenuItem;
    procedure FormCreate(Sender: TObject);
    procedure Font1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure EnableFont1Click(Sender: TObject);
    procedure Exit1Click(Sender: TObject);
    procedure DisableFont1Click(Sender: TObject);
  private
    { Private declarations }
    BM: TBitmap;
    MenuCap: array [0..255] of char;
    procedure WMMeasureItem(var MInfo: TMessage); message wm_MeasureItem;     procedure WMDrawItem(var DInfo: TMessage); message wm_DrawItem;   public
    { Public declarations }
  end;
 
var
  Form1: TForm1;
 
implementation
 
{$R *.DFM}
 
procedure TForm1.FormCreate(Sender: TObject);
begin
  {Create a work area}
  BM := TBitmap.Create;
  {Initialize current font to standard menu text color}
  FontDialog1.Font.Color := GetSysColor(color_MenuText);
  {Tell Windows this menu item is Owner-Draw}
  ModifyMenu(MainMenu1.Handle, Font1.Command,
    mf_ByCommand or mf_OwnerDraw, Font1.Command, nil);
  {Make a copy of menu caption now to save time}
  StrPCopy(MenuCap, Font1.Caption);
  {Does menu item have a shortcut assigned?}
  if Font1.ShortCut <> 0 then
    StrPCopy(StrEnd(MenuCap), #9 + ShortCutToText(Font1.ShortCut)); end;
 
procedure TForm1.FormDestroy(Sender: TObject);
begin
  {Dispose work area}
  BM.Free;
end;
 
procedure TForm1.WMMeasureItem(var MInfo: TMessage);
var
  MIS: TMeasureItemStruct;
const
  zero: integer = 0;
begin
  {Address the Windows supplied info}
  with PMeasureItemStruct(MInfo.lParam)^ do begin
    {Is message for a menu item}
    if CtlType = odt_Menu then begin
      {Is message for Font menu item}
      if ItemID = Font1.Command then begin
        {Assign currently selected font to work space}
        BM.Canvas.Font := FontDialog1.Font;
        {Calculate needed height for current font}
        ItemHeight := BM.Canvas.TextHeight(Font1.Caption);
        {Calculate needed width for caption in current font}
        ItemWidth := LoWord(GetTabbedTextExtent(BM.Canvas.Handle, MenuCap,           StrLen(MenuCap), zero, zero));
        {Tell Windows it's handled}
        MInfo.Result := 1;
      end;
    end;
  end;
end;
 
procedure TForm1.WMDrawItem(var DInfo: TMessage);
var
  oldFont: hFont;
begin
  {Address Windows supplied info}
  with PDrawItemStruct(DInfo.lParam)^ do begin
    {Is message for a menu item?}
    if CtlType = odt_Menu then begin
      {Is message for Font menu item?}
      if ItemID = Font1.Command then begin
        {Select current font into menu's device context}
        oldFont := SelectObject(hDC, FontDialog1.Font.Handle);
        {Set correct background color}
        if (ItemState and ods_Selected) <> 0 then
          BM.Canvas.Brush.Color := clHighlight
        else
          BM.Canvas.Brush.Color := clMenu;
        {Paint the background}
        FillRect(hDC, rcItem, BM.Canvas.Brush.Handle);
        {Adjust left bound of caption}
        Inc(rcItem.Left, LoWord(GetMenuCheckMarkDimensions));
        {Set text color according to state}
        if (ItemState and ods_disabled <> 0)
        or (ItemState and ods_Grayed <> 0) then
          {Use system's 'grayed' color}
          SetTextColor(hDC, GetSysColor(color_GrayText))
        else if (ItemState and ods_Selected <>0) then
          {Use reverse of current font color}
          SetTextColor(hDC, not FontDialog1.Font.Color)
        else
          {Use selected font color}
          SetTextColor(hDC, FontDialog1.Font.Color);
        {Allow background color to surround characters}
        SetBkMode(hDC, Transparent);
        {Draw the menu's caption}
        DrawText(hDC, MenuCap, StrLen(MenuCap), rcItem,
          dt_Top or dt_SingleLine or dt_ExpandTabs);
        {Release current font handle}
        SelectObject(hDC, oldFont);
        {Tell Windows it's handled}
        DInfo.Result := 1;
      end;
    end;
  end;
end;
 
procedure TForm1.EnableFont1Click(Sender: TObject);
begin
  {Tell Windows this menu item is selectable again}
  ModifyMenu(MainMenu1.Handle, Font1.Command,
    mf_ByCommand or mf_Enabled or mf_OwnerDraw, Font1.Command, nil); end;
 
procedure TForm1.DisableFont1Click(Sender: TObject);
begin
  {Tell Windows this menu item not selectable}
  ModifyMenu(MainMenu1.Handle, Font1.Command,
    mf_ByCommand or mf_Grayed or mf_OwnerDraw, Font1.Command, nil); end;
 
procedure TForm1.Font1Click(Sender: TObject);
begin
  if FontDialog1.Execute then
  {Fool Windows into sending another wm_MeasureItem message
  so menu item can be sized for newly selected font.}
    ModifyMenu(MainMenu1.Handle, Font1.Command,
      mf_ByCommand or mf_OwnerDraw, Font1.Command, nil);
end;
 
procedure TForm1.Exit1Click(Sender: TObject);
begin
  Close;
end;
 
end.
Ow! It's a comment!

I make some experiments and have some recomendations. If you don't need to see russian text in menu at your computer, but only need to be sure that in russian version of windows it will look like "russian", you may keep it as is. I just write and compile small application on computer without russian, then start it on computer with russian version of windows. It look like russian. But if you need to see russian in your computer, just change system settings of windows to russian (keep Windows CD ready;).

Best regards

Tugay.
To: ITugay

That might work if the OS is russian or in my case Bulgarian.  However the client is running Win 95 in English with Bulgarian Keyboard support.  Therefore this is not truly Russian.

To: Gurkan

That is one helluva comment!

If I must draw my own menu, then I will use that code as a sample.

Is there no way to activity the Charset for a menu?

Cheers
Paul
Use multilanguage component, for example: http://members.tripod.com/~sushko/,
look into download ->TLanguage
I use these component and it's ok.
Adjusted points to 300
Sorry Dmitry but the TLanguage Component doesn't solve the problem.

I downloaded, installed and ran the demo.  While it provides nice translations, when you select Russian the Cyrillic text is NOT displayed, but you get the same type of characters that ITugay mentioned in his first comment.

Cheers
Paul
Listening
Try to test the TLanguage component on operating system with cyrillic support.
I'm using this component for switch between hebrew and english languages and it's working properly.
ASKER CERTIFIED SOLUTION
Avatar of sassas081597
sassas081597

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can send me  compilled part of application via e-mail, and I tell you how it look.

Best regards,
igor@novell.kz
To: Dmitry

1) Unfortunately my client is restricted to Win95, and they are using Bulgarian support under English OS.
2) I finally got an answer out of MS.  True multilanguage OS is only available with W2K.

Unfortunately this puts a real crimp in your solution.

To: SASSAS

I am not sure what your suggestion is.  I am unfamiliar with soft menus.  Is this the same idea as Gurkan's comment earlier?

To:

I appreciate your offer, but am not sure what to send, or how meaningful the test would be.  If you are running a different OS, than Win95, the test may not have much meaning.

Cheers
Paul
Hi, rosethorn
May be you will try modify in registry key: HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Nls\Codepage
Parameter: 1252 = cp_1252.nls on 1252 = cp_1251.nls

It's common problem with the cyrilic fonts on non russian Windows.
That looks promising.

Much as I hate to work in the Registry, I will give it a cautious try.

Thanks.
Paul
To: DValery

I made the change as suggested.  Rebooted and tested the program.

There was no change.

Was that the only change required?

Cheers
About testing your application. I have a lot : WIN95, WIN98, NT4, NT2000. All of this is russian version. You need only to create new application, put TMenu here and place MenuItems like this:
&Ôàéë
&Îòêðûòü
&Ñîõðàíèòü
Ñîõðàíèòü ê&àê
&Âûéòè
You may copy it then paste to menu caption. Then you compile it and send .EXE to me. I will try it on different OS. I'm sure, it will look like russian.

Best regards
Adjusted points to 500
To: Itugay

I would like to award some points to you, but I can't do it without closing the question.

The answer you provide is that the correct OS must be used, and that answer will solve my problems.  Unfortunately acquiring and installing the necessary OS is not yet an option.

For all others listening in on this question, let me add the following condition.

The solution must be applicable within the Win 95 OS, English version, but running with Bulgarian language support.

I have increase the point value.

Cheers
Paul

P.S. If this question is ever resolved ITugay deserves partial credit!
Hi Paul,

As your client uses Win95 English version, ask him to buy for you 'FlexType' from Datecs - Bulgarian fonts and keyboard support program under W95. After installing it you will have MS SansSerif and other fonts in Bulgarian. And no problems with Bulgarian in Delphi!

Regards, Geo
I have just been through a horrible situation with the Datecs program.  The fonts it installs were not compatible with any of the fonts and the whole installation conflicted badly with the Pan-European Language Support under Win95.

The Datecs program replaced the keyboard driver in the system.ini file and this caused Win95 to loose the ability to change keyboards.

In Excel, under Datecs, the cyrillic fonts were visible in the cell, but displayed as square boxes (unprintable characters) in the cell edit line.  This suggests an incompatibility between Win95 and Datecs.

The version I was using may have been somewhat dated.  Do you have any updated information on the compatibility between Datecs and MS at the keyboard and language support level.

I am also concerned for the future applications and changes to Win98 and W2K.  According to MS, programs such as Datecs are made unnecessary by the advances in Unicode and W2K.

If this is the case, then the solution is short term at best.

Much thanks for your comments, I am slowly beginning to get an idea of where the root of the problem is, and what possible solutions can do.

Cheers
Paul

Hi Paul,
  It sounds like FT is not setup properly.
  I'm using FlexType 3.0 under w95.
  In my version in FT properties I have three pages: General,Keyboard and Fonts.
  Under General there are three filters and all have to be 'Eastern Europe/Cyrillic'.
  Under Keyboard you can add different keyboard layouts and even edit them. As your keyboard has no BDS (i suppose) use 'Bulgarian Phonetic'.
  Under Fonts set System fonts and Window to 'Eastern Europe/Cyrillic' and Full screen to 'US,Western Europe'.
  I hope this will help you.

Regards, Geo
I would seriously consider getting FT for W95, but I would like to have more information and experience in using FT and W95 Pan-European Language Support.  MS are notorious for doing things the awkward way and making everyone else's products obsolete or incompatible.

I will keep this under serious advisement.  I have one or two tricks that might yet work.

Much thanks for your comments.

Cheers
Paul
Hi Paul,

It's interesting for me, is FT solve your problem?

Cheers,
Igor.
To: Igor

I have not tried FT for Win 95.  As per earlier comments I have had some bad experiences with the product.

During this project I had to make a decision regarding the language support for the manuals and at that time FT and MS were incompatible and I was looking at real problems in moving the manuals to a non-FT machine.  This forced the MS choice, unpleasant as it was.

Since I am now stuck (!) in the MS world I am very reluctant to retry FT.  There is a very real possibility of creating complete incompatibility between other applications, documents etc.

Please note the I am not against FT, but due to its incompatibility with MS, I am forced away from it.

Cheers
Paul
I went back over all the comments today on this problem and thought long about what yours was about.  It finally occurred to me that what you were suggesting sounded really good.

Change the way Windows displays its menus, rather than change how Delphi works with them!

This problem took a lot of different approaches, but in the end this simple method of changing the fonts in the Windows Settings works really well.

In the end I used a Hebar font and I can see everything in Bulgarian!

Thanks!
Paul
This was a brutal problem and I have to thank everyone involved for their individual contributions and help.  Although the points were awarded to SASSAS, I have to thank everyone.

There were many dimensions, and possible solutions to this one, and in the end I needed to have all the information, from all paths to determine the best, and workable solution.

I can't recall who's comments gave me which ideas, but suffice it to say that everyone contributed something.  Thanks again to ITugay for testing out the program under a russian OS.

Cheers and thanks
Paul