Pelles C forum

C language => Windows questions => Topic started by: czerny on August 18, 2014, 12:55:47 PM

Title: right aligned shortcut key in menu item
Post by: czerny on August 18, 2014, 12:55:47 PM
Hallo,

with a menu item string "Example\tCtrl-x" I get left aligned shurtcuts. But I want them right aligned.

After a bit of googling I found "Example\aCtrl-x". But it is not working, neither in resources nor with AppendMenu. Pelle doubles the backshlash. Is there an other methode?
Title: Re: right aligned shortcut key in menu item
Post by: jj2007 on August 18, 2014, 03:08:40 PM
If the escapes don't work properly, use an array of chars?

  char x[] = {'E', 'x', 'a', 'm', 'p', 'l', 'e', 7, 'C', 't', 'r', 'l', '-', 'x', 0};
  printf("The string: [%s]\n", x);

(assuming \a means Ascii 7...)

P.S.: In assembler, one would use chr$("Example", 7, "Ctrl-X", 0)
Is there a C equivalent to that syntax?
Title: Re: right aligned shortcut key in menu item
Post by: czerny on August 18, 2014, 03:26:16 PM
P.S.: In assembler, one would use chr$("Example", 7, "Ctrl-X", 0)
Is there a C equivalent to that syntax?
Code: [Select]
"Example\07Ctrl-X" // doesn't work!

sprintf(MenuItem, "%s%cCtrl-X", "Example", 7); // doesn't work!
Title: Re: right aligned shortcut key in menu item
Post by: frankie on August 18, 2014, 04:01:32 PM
In assembler, one would use chr$("Example", 7, "Ctrl-X", 0)
Is there a C equivalent to that syntax?

char string[] = "Example\x07Ctrl-X"
Title: Re: right aligned shortcut key in menu item
Post by: JohnF on August 18, 2014, 04:16:02 PM
Found this, it works ok here using \t.

Code: [Select]
hMenu = CreateMenu();

hSubMenu = CreatePopupMenu();
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, TEXT("&File"));
AppendMenu(hSubMenu, MF_STRING, MENU_FILE_NEW, TEXT("&New\tCtrl+N"));


John
Title: Re: right aligned shortcut key in menu item
Post by: czerny on August 18, 2014, 06:26:04 PM
Found this, it works ok here using \t.

Code: [Select]
hMenu = CreateMenu();

hSubMenu = CreatePopupMenu();
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, TEXT("&File"));
AppendMenu(hSubMenu, MF_STRING, MENU_FILE_NEW, TEXT("&New\tCtrl+N"));


John

John! If you do this
Code: [Select]
hMenu = CreateMenu();

hSubMenu = CreatePopupMenu();
AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, TEXT("&File"));
AppendMenu(hSubMenu, MF_STRING, MENU_FILE_NEW, TEXT("&New\tCtrl+N"));
AppendMenu(hSubMenu, MF_STRING, MENU_FILE_BLA, TEXT("&Bla\tAlt+Ctrl+B"));


is than 'Ctrl+N' and 'Alt+Ctrl+B' left aligned or right aligned?

See http://msdn.microsoft.com/en-us/library/windows/desktop/aa381024(v=vs.85).aspx (http://msdn.microsoft.com/en-us/library/windows/desktop/aa381024(v=vs.85).aspx)
and http://stackoverflow.com/questions/4975077/how-do-i-right-align-the-shortcut-keys-in-menu (http://stackoverflow.com/questions/4975077/how-do-i-right-align-the-shortcut-keys-in-menu)
Title: Re: right aligned shortcut key in menu item
Post by: JohnF on August 18, 2014, 07:47:48 PM
To the right. See image

I can send the project if you want.

John
Title: Re: right aligned shortcut key in menu item
Post by: TimoVJL on August 19, 2014, 05:00:01 AM
I think czerny has found bug in porc.exe. It doesn't handle that escape \a correctly.
That left-hand aligning is WinForms feature and needs OwnerDraw for WinAPI32.
Title: Re: right aligned shortcut key in menu item
Post by: JohnF on August 19, 2014, 06:41:58 AM
I think czerny has found bug in porc.exe. It doesn't handle that escape \a correctly.
That left-hand aligning is WinForms feature and needs OwnerDraw for WinAPI32.

Welcome back!

John
Title: Re: right aligned shortcut key in menu item
Post by: czerny on August 19, 2014, 08:37:15 AM
I am a little bit confused.

I think czerny has found bug in porc.exe. It doesn't handle that escape \a correctly.
That left-hand aligning is WinForms feature and needs OwnerDraw for WinAPI32.

Do you really mean that the left-hand aligning is WinForms feature?

John: If this is a Pelles C project, then please post the project!
Title: Re: right aligned shortcut key in menu item
Post by: JohnF on August 19, 2014, 09:15:30 AM
I am a little bit confused.

I think czerny has found bug in porc.exe. It doesn't handle that escape \a correctly.
That left-hand aligning is WinForms feature and needs OwnerDraw for WinAPI32.

Do you really mean that the left-hand aligning is WinForms feature?

John: If this is a Pelles C project, then please post the project!

Here it is.

John
Title: Re: right aligned shortcut key in menu item
Post by: czerny on August 19, 2014, 10:27:50 AM
Here it is.
And it is not right-aligned!

See the Pelles C IDE edit menu as an example.
Title: Re: right aligned shortcut key in menu item
Post by: JohnF on August 19, 2014, 10:42:27 AM
What am I missing? The short cuts look right aligned to me.

John
Title: Re: right aligned shortcut key in menu item
Post by: frankie on August 19, 2014, 11:15:50 AM
Czerny mean right justifyed.
Title: Re: right aligned shortcut key in menu item
Post by: JohnF on August 19, 2014, 11:40:05 AM
Like this.

John
Title: Re: right aligned shortcut key in menu item
Post by: czerny on August 19, 2014, 12:14:01 PM
Like this.
Yes! What have you done?
Title: Re: right aligned shortcut key in menu item
Post by: JohnF on August 19, 2014, 12:20:33 PM
That is exactly what that app does.

Note the "&Copy\tC"

Code: [Select]
AppendMenu(hSubMenu, MF_STRING, MENU_EDIT_CUT, TEXT("Cu&t\tCtrl+X"));
AppendMenu(hSubMenu, MF_STRING, MENU_EDIT_COPY, TEXT("&Copy\tC"));

John
Title: Re: right aligned shortcut key in menu item
Post by: czerny on August 19, 2014, 12:41:32 PM
That is exactly what that app does.

I have not compiled your SmallEd2 example and we have different looks. Doesn't that mean that it is OS dependent?

I am working here with XP SP3.
Title: Re: right aligned shortcut key in menu item
Post by: JohnF on August 19, 2014, 01:10:20 PM
That is exactly what that app does.

I have not compiled your SmallEd2 example and we have different looks. Doesn't that mean that it is OS dependent?

I am working here with XP SP3.

Yes, I just tried it on an old XP - it is not working the same. Don't know what to suggest.

John
Title: Re: right aligned shortcut key in menu item
Post by: czerny on August 19, 2014, 01:53:31 PM
So the question arises: How can you left-align your shurtcuts?

Here (XP SP3) Pelles C ide shurtcuts are right-aligned and per example notepad is left-aligned. So there should be a difference. Do you have any differences?

Could anybody else try the SmallEd2 example and look at the edit menu?
Title: Re: right aligned shortcut key in menu item
Post by: czerny on August 19, 2014, 04:13:13 PM
Code: [Select]
sprintf(MenuItem, "%s%cCtrl-X", "Example", 8); // works!Though
Code: [Select]
'\a' == 7 a value of 8 is working.
'\b' is working too!
Title: Re: right aligned shortcut key in menu item
Post by: jj2007 on August 19, 2014, 05:13:58 PM
Ascii 7 doesn't work on XP SP3 (inserts a black dot),
8 means right-aligned,
9 means left-aligned.

Now the question is how it works on Win 7 + 8...
Title: Re: right aligned shortcut key in menu item
Post by: JohnF on August 19, 2014, 05:22:30 PM
On Win7 \t and \b work the same, right aligned.

John