Solved

Right aligned menubar

Posted on 2004-08-24
3
173 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
  • 2
3 Comments
 
LVL 17

Accepted Solution

by:
Wim ten Brink earned 85 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now