Author: Jonas Bilinkevicius
I want to write a TMenu component where all items and sub menus are right justified.
Answer:
You can change the item's justification, if you add the MFT_RIGHTJUSTIFY constant
to the item's type (fType member of the TMenuItemInfo structure). You can do it in
the main menu's OnChange event handler. Here's an example:
1 2 procedure TForm1.MainMenu1Change(Sender: TObject; Source: TMenuItem; Rebuild:
3 Boolean);
4 var5 XHandle: HMENU;
6 XMenuItemInfo: TMenuItemInfo;
7 XBuffer: array[0..79] of Char;
8 begin9 XHandle := TMainMenu(Sender).Handle;
10 XMenuItemInfo.cbSize := 44;
11 XMenuItemInfo.fMask := MIIM_TYPE;
12 XMenuItemInfo.dwTypeData := XBuffer;
13 XMenuItemInfo.cch := SizeOf(XBuffer);
14 if GetMenuItemInfo(XHandle, 0, true, XMenuItemInfo) then15 begin16 XMenuItemInfo.fType := XMenuItemInfo.fType or MFT_RIGHTORDER or17 MFT_RIGHTJUSTIFY;
18 XMenuItemInfo.fMask := MIIM_TYPE;
19 SetMenuItemInfo(XHandle, 0, true, XMenuItemInfo);
20 end;
21 end;