Question

Delphi Xe2U4. Main menu items: File, Option, Help (name: HelpMenuItem). 2 buttons. Use StyleManager Xe2 (in project option enabled xe2 themes, and default set 'Metro Blue').

Procedure TForm1.RightMenu; // Shift in the right of last item of the menu
var mii: TMenuItemInfo;MainMenu: hMenu; Buffer: array[0..79] of Char;
begin
  MainMenu := Self.Menu.Handle;
  mii.cbSize := SizeOf(mii) ;
  mii.fMask := MIIM_TYPE;
  mii.dwTypeData := Buffer;
  mii.cch := SizeOf(Buffer) ;
  GetMenuItemInfo(MainMenu, HelpMenuItem.Command, false, mii) ;
  mii.fType := mii.fType or MFT_RIGHTJUSTIFY;
  SetMenuItemInfo(MainMenu, HelpMenuItem.Command, false, mii) ;
end;

procedure TForm1.Metro1Click(Sender: TObject); // Not Work
begin
TStyleManager.TrySetStyle('Metro Blue'); // or any other
RightMenu;
end;

procedure TForm1.Windows1Click(Sender: TObject); // Work
begin
TStyleManager.TrySetStyle('Windows'); // standart theme
RightMenu;
end;

Why does not work at use theme? Whether or there is a normal way to shift last point of the menu in the right, whether is not dependent schemes are applied or not?

Was it helpful?

Solution

Unfortunally the vcl style hook of the TMainMenu doesn't implement the code to draw a particular menu item aligned to the right. Also this vcl style hook (TMainMenuBarStyleHook) is embedded in the TFormStyleHook (the vcl style hook for the forms) as a strict private member, so there is not much room for modifications here. Fix this issue will require which you rewrite the a new vcl style hook for the TForms and the TMainMenus. So If you want do this you must copy the TFormStyleHook class from the Vcl.Forms unit to a new unit and then fix the implementation of the TFormStyleHook.TMainMenuBarStyleHook.DrawItem and the TFormStyleHook.TMainMenuBarStyleHook.Paint methods.

OTHER TIPS

Procedure TForm1.RightMenu; // Shift in the right of last item of the menu
var mii: TMenuItemInfo;MainMenu: hMenu; Buffer: array[0..79] of Char;
begin
  MainMenu := Self.Menu.Handle;
  mii.cbSize := SizeOf(mii) ;
  mii.fMask := MIIM_TYPE;
  mii.dwTypeData := Buffer;
  mii.cch := SizeOf(Buffer) ;
  GetMenuItemInfo(MainMenu, HelpMenuItem.Command, false, mii) ;
  mii.fType := mii.fType or MFT_RIGHTJUSTIFY;
  if SetMenuItemInfo(MainMenu, HelpMenuItem.Command, false, mii) then DrawMenuBar(self.Menu.WindowHandle);

end;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top