Solved

Right aligned menubar

Posted on 2004-08-24
3
176 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
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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