Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Right align a menu item!

Posted on 2000-05-03
8
Medium Priority
?
430 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
[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
  • 4
  • 4
8 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 200 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

705 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