Solved

Right aligned menubar

Posted on 2004-08-24
3
179 Views
Last Modified: 2010-08-05
Please help me:

How can I make Form1.MainMenu stick to right, without changing the BiDiMode of Form1. I mean any thing is ok but MainMenu1.

More Detail: I'm in XP with Delphi7 and like to run my application in any version of Windows.
0
Comment
Question by:szayeri
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 85 total points
ID: 11883513
var
  MenuItemInfo: TMenuItemInfo;
  Buffer: array[ 0..79 ] of Char;
begin
  MenuItemInfo.cbSize := 44; // Required for Windows 95
  MenuItemInfo.fMask := MIIM_TYPE;
  MenuItemInfo.dwTypeData := Buffer;
  MenuItemInfo.cch := SizeOf( Buffer );
  if GetMenuItemInfo( MainMenu1.Handle, MainMenu1.Items.IndexOf( Edit1 ), True, MenuItemInfo ) then begin
    MenuItemInfo.fType := MenuItemInfo.fType or MFT_RIGHTJUSTIFY;
    SetMenuItemInfo( MainMenu1.Handle, MainMenu1.Items.IndexOf( Edit1 ), True, MenuItemInfo );
  end;
end;

MainMenu1 is my main menu, Edit1 is the second menu-item in the top.
0
 

Author Comment

by:szayeri
ID: 11889794
Dear Workshop Alex

Thank You. Your code works fine but there is some questions remaining:
1) How can I force menu items to be redrawn in order to make them appear at right? They are actually right aligned but their position before redrawing does not say so.
2) when I rename Edit1 every thing goes back. why is it so and how much can I trust in this code in special conditions (renaming, changing menuindex, closing form and so on)?
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 11929292
The problem with my solution is that while you explicitly tell the menu to be right-alighned once, the TMemu component isn't really aware of this yet. Thus, when the TMenu recreates the menu for whatever reason, (like renaming) it will bring the menu back to it's original position. Basically, you should inherit a new component from TMainMenu and add the functionality for this new right-alignment property, which is not an easy job. This new component could then respond to changes in the menu and make sure the MFT_RIGHTJUSTIFY is set for a specific menuitem.
Basically, the whole secret behind right-aligned menus is just this flag...
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi application Soap connection 5 152
Base1 Encode/Decode 3 100
Graphics32 under Delphi 10.1 Berlin 2 181
scroll down TListBox component in Delphi 1 44
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question