V.2.9
ctlUTF8Menu

Unicode Menu from VB6 standard menu
>>Common properties

VERY IMPORTANT
From version 2.8 the UTF8Menu should not be used with StringMode=UTF8; you have to use the StringMode=Hex instead of this if you want to be compatible with all locales.

Explanation:
The UTF8 encoding cannot be used as a string container for menu controls in many systems because it can contain the full set of ANSI chars (0..255, supported only in full ANSI systems like US, GB, IT, etc...); for example in Chinese/Vietnamese systems, some chars were lost and the menu doesn't work correctly. Now it is possible to use a special encoding for the menu. You can translate strings from UTF16 to Hexadecimal values using the HexToStr or StrToHex functions. The menu can be set to Hex mode as it is able to check Hexadecimal strings and translate them if needed.
It is possible to manually check if a string is encoded in Hex using the function IsHexString

Hexadecimal Encoding
This is a quite simple translation of an Unicode string using the Base64 encoding plus some control chars. The first two letters represent the Hex identifier, the last two bytes of the string contain the XOR hexadecimal value of every character index so it is simple to check for an Hexadecimal encoded string :-)

For example the italian string "
pippo" is encoded in Hex as "0XcABpAHAAcABvAA==0F" that should be fully compatible with all systems because it uses only numbers and very few ANSI letters.
Unicode String pippo
Hexadecimal Encoding 0X
(identifier)
cABpAHAAcABvAA==
(Base64)
&H0F
(CRC)
Some Properties/Methods:
StringMode VERY IMPORTANT!!!
use UTF8, Hex or ANSI strings in menu items
Attach start the ownerdrawn menu
CustomFontFace permits you to customize the font used for the menu without changing the one used by Windows. You can for example set the font to "Arial Unicode MS" for displaying Vietnamese and Chinese words in the menu.
If this property is blank the control will use the one used by the system.
Detach end the ownerdrawn menu
ExtSepBackColor / ExtSepForeColor colors for extended separators
FadeBackground do you want to use a fade background for the menu?
FadeExtSep do you want to use a fade background for extended separators?
FadeLeftBand do you want to use a fade background for the left band?
FullSelector do you want to select the entire row when highlighting a menu item?
IconDim represents the standard size of the item image
ImageArray You can specify a collection of StdPictures used to place icons in the menu, by default this collection is nothing so you need to create a new collection and use the:

set ImageArray=YourCollection

to use image indexes at design time (see below)
LeftBand do you want a left vertical band behind icons?
LeftBandBackColor color of the left band when used
LeftBandSeparators do you want a vertical separator between the menu and the left band?
MenuBackColor / MenuForeColorNormal / MenuForeColorDisabled menu colors
SelectorBackColor / SelectorForeColor selector colors
Separators3D use 3D or flat separators?
Events:

OnOwnerDrawn - raised when an element needs to be drawn, permits you to personalize icons and menu items at run-time

How to use the control:
Place this control in every form with a menu; it permits you to turn a VB6 menu into an Unicode menu, use the 'Attach' method to start the menu in a form.
The Hexadecimal encoding permits you to use an ANSI string to specify an UNICODE string; in the clsCommonWrapper class you'll find convertion functions between UTF8, Hex and UNICODE strings.
The first pixel (0,0) of the image will be used as transparent color for items.

Choose the menu type using the StringMode property (available only at design time) , 'Hex' is the default as the menu is able to check if strings are encoded in Hex or not.

StringMode=HEX

When using the Hex mode you can load every menu items using Hex encoded strings

Ex:
mnuFile.Caption=clsCommonWrapper.StrToHex(myUnicodeString)

you can also design your menu at design time placing Hex strings into Captions (quite difficult to maintain).
You can also translate your strings to UNICODE at run-time changing strings in the OnOwnerDraw event.

StringMode=UTF8 (Available only for backward compatibility)
When using the UTF8 mode you can load every menu items using UTF8 strings

Ex:
mnuFile.Caption=clsCommonWrapper.StrToUTF8(myUnicodeString)

you can also design your menu at design time placing UTF8 strings into Captions.
You can also translate your strings to UNICODE at run-time changing strings in the OnOwnerDraw event.

StringMode=AsIs (no encoding)
The only way to use UNICODE strings is to translate/set them at run-time using the OnOwnerDraw event.
This option is very useful when you need only an advanced menu control without translation (for example you use only the English alphabet).

When using a MDI child form which replaces a parent MDI form menu remember that the child menu (OnOwnerDraw event) is managed by the parent.
In order to place extended separators, prefix a menu caption with [SEP]; the control will translate this item to an extended separator.
It's possible to assign icons to items at design time by adding to the Caption the "|" character followed by the Index of the image in the ImageArray property (see above).

IMPORTANT:
Working on multiple languages on the same application:
When working with many languages in the same application you probably need to translate the entire menu and the title of your form when a user choose to change the actual language.
Unfortunately there is no way for the ctlUTF8Menu to receive a notification from Windows that a Top level menu item (items on the menu toolbars) has been changed and need to be refreshed.
Sub-level menu items are automatically refreshed when they change.

You can avoid this problem by acting in this way:

ctlMenu.Detach

'<...Do your translations to the menu and to the Title of your Form...>

ctlMenu.Attach
Menu Sample:

• Put menu images into a ctlImageBag control (use bitmaps not icons)
• Draw a ctlUTF8Menu control into your form
Set StringMode=Hex (you must use Hex strings for menu captions); you can use the UTF8Conv program to translate Unicode strings to Hex strings. You can also use the clsCommonWrapper class to make conversions.
• Write Hex strings into the menu designer (if you want) or setup them later using conversion functions (mnuItem1.Caption=oCommonWrapper.StrToHex(UTF16String))
• In the Form_Load event of your form call the "
Attach" method to start the menu

Item Images:
I suggest you to use a private enum in order to store image indexes ;-)

Method 1:

• Use a |<index> after the caption to setup images at design time (ex. Item2|2 uses the second image in the ctlUTF8Menu.ImageArray collection) or manage the onOwnerDrawn event
• Create a collection, add images clones (ctlImageBag.GetPictureClone()) to the collection
• Set the new collection to the ctlUTF8Menu

Method 2:

Manage the OnOwnerDraw event of ctlUTF8Menu and set the oItemPic variable using the ctlImageBag control:

Private Sub ctlUTF8Menu1_OnOwnerDraw( _
sItemText As String, _
oItemPic As stdole.StdPicture, _
iItemPicWidth As Integer, _
iItemPicHeight As Integer, _
bItemPicTransp As Boolean, _
ByVal bItemSelected As Boolean)

Select Case sItemText
Case Item1.Caption
Set oItemPic = ctlImageBag1.GetPictureClone(1)
Case Item2.Caption
Set oItemPic = ctlImageBag1.GetPictureClone(2)
End Select
End Sub

ATTENTION!
If you change a Top Level menu item caption after having called the
".Attach" method of the usercontrol, you need to use the ".Refresh" method to refresh menu items. This because there isn't a way to do such as thing automatically.
If you change all other menu items you don't need to do anything.
Unicode Icon Menu for VB6
http://www.hexagora.com
Thu, 5 Nov 2009 09:17:21 UT
Copyright 2003-10 by Lorenzi Davide