Solved

Right align a menu item!

Posted on 2000-05-03
8
421 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
Comment Utility
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
Comment Utility
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
Comment Utility
What does the C code look like?
0
 

Author Comment

by:TL010600
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 15

Expert Comment

by:Tommy Hui
Comment Utility
//  lpmii->fType = lpmii->fType || MFT_RIGHTJUSTIFY;

should be

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

Notice the || should be |

0
 

Author Comment

by:TL010600
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

763 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now