Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Right align a menu item!

Posted on 2000-05-03
8
Medium Priority
?
431 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 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Independent Software Vendors: 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!

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

916 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