Link to home
Start Free TrialLog in
Avatar of TL010600
TL010600

asked on

Right align a menu item!

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?
ASKER CERTIFIED SOLUTION
Avatar of Tommy Hui
Tommy Hui

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TL010600
TL010600

ASKER

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?
What does the C code look like?
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.... :(
//  lpmii->fType = lpmii->fType || MFT_RIGHTJUSTIFY;

should be

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

Notice the || should be |

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!" );
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!" );

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 :)