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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What does the C code look like?
ASKER
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(Ha ndle), 1, True, lpmii);
// ShowMessage(IntToStr(GetMe nuString(M ,1,title,5 0,MF_BYPOS ITION)));
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.... :(
{
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
// Failes HERE!
// lpmii->fType = lpmii->fType || MFT_RIGHTJUSTIFY;
// SetMenuItemInfo(GetMenu(Ha
// ShowMessage(IntToStr(GetMe
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 |
should be
lpmii->fType = lpmii->fType | MFT_RIGHTJUSTIFY;
Notice the || should be |
ASKER
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!" );
if (!GetMenuItemInfo(M,1,True
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!" );
{
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!" );
ASKER
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 :)
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 :)
ASKER
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?