Solved

Right align a menu item!

Posted on 2000-05-03
8
424 Views
Last Modified: 2008-01-16
I want to make my "Help" menu item appear on the right side of the window
I got the source to do this in Delphi - worx fine...but i cant translate the code to C . I'm a Delphi coder and I soon moved to Borland C Builder 4
...I'm SO confused....
Does anyone know any good reference material for such situation?
0
Comment
Question by:TL010600
  • 4
  • 4
8 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 100 total points
ID: 2773689
You can do it via the menu resource, instead of doing it through code. In the MENUITEM of the resource, use \a to right align the menuitem.

MENUITEM text, result, [[optionlist]]  

Parameters
text
A string that indicates the name of the menu item.
The string can contain the escape characters \t and \a. The \t character inserts a tab in the string and is used to align text in columns. Tab characters should be used only in menus, not in menu bars. (For information on menus, see POPUP Resource.) The \a character aligns all text that follows it flush right to the menu bar or pop-up menu.


0
 

Author Comment

by:TL010600
ID: 2780024
in fact I need an explanation why doesnt this fine Delphi code work when translated to C:

var
    MMI: TMenuItemInfo;
    MyMenu: hMenu;
    Buffer: array[0..79] of Char;

begin
     MyMenu := GetMenu(Handle);
     MMI.cbSize := SizeOf(MMI);
     MMI.fMask := MIIM_TYPE;
     MMI.dwTypeData := Buffer;
     MMI.cch := SizeOf(Buffer);
     GetMenuItemInfo(MyMenu, 1, True, MMI);
     MMI.fType := MMI.fType or MFT_RIGHTJUSTIFY;
     SetMenuItemInfo(MyMenu, 1, True, MMI);

Any ideas?
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 2781756
What does the C code look like?
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Comment

by:TL010600
ID: 2783664
void __fastcall TForm1::FormCreate(TObject *Sender)
{
    LPMENUITEMINFO lpmii;
    HMENU M;
    char buffer[110];

  M = GetMenu(Handle);

  lpmii->cbSize = sizeof(lpmii);
  lpmii->fMask = MIIM_TYPE;
  lpmii->dwTypeData = buffer;
  lpmii->cch = sizeof(buffer);

  if (!GetMenuItemInfo(M,1,True, lpmii)) ShowMessage("Failed!" );
// Failes HERE!

//  lpmii->fType = lpmii->fType || MFT_RIGHTJUSTIFY;
//  SetMenuItemInfo(GetMenu(Handle), 1, True, lpmii);
//  ShowMessage(IntToStr(GetMenuString(M,1,title,50,MF_BYPOSITION)));

I'm a BAD C translater!
Also I cant find how to declare string types in C!!! ALL Win functions that are supposed to work with PChars aways fail!...and I tought coding in C for Windows would be easier.... :(
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 2785336
//  lpmii->fType = lpmii->fType || MFT_RIGHTJUSTIFY;

should be

lpmii->fType = lpmii->fType | MFT_RIGHTJUSTIFY;

Notice the || should be |

0
 

Author Comment

by:TL010600
ID: 2789563
OK, but it seems my proggie failes before it reaches this line -> notice that it's commented above - My GetMenuItemInfo function FAILES! );

  if (!GetMenuItemInfo(M,1,True, lpmii)) ShowMessage("Failed!" );
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 2789731
That's because you should be using an object and not a pointer to an object:

{
  MENUITEMINFO mii;
  // rest is same
  ZeroMemory(&mii, sizeof(mii)); //Add this line to zero out the buffer before using
  mii.cbSize = sizeof(mii);
  mii.fMask = MIIM_TYPE;
  mii.dwTypeData = buffer;
  mii.cch = sizeof(buffer);

  if (!GetMenuItemInfo(M, 1, True, &mii)) ShowMessage("Failed!" );

0
 

Author Comment

by:TL010600
ID: 2792819
THANX!
Finally it workx!
It seems a bit too confusing for me, but I think I should go through some tutorials first, before continuing with C++ ...
....I'd be glad to return the favour, of course if I can...

TL :)
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

803 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