NO

Author Topic: right aligned shortcut key in menu item  (Read 5156 times)

czerny

  • Guest
right aligned shortcut key in menu item
« 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?

Offline jj2007

  • Member
  • *
  • Posts: 506
Re: right aligned shortcut key in menu item
« Reply #1 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?
« Last Edit: August 18, 2014, 03:14:02 pm by jj2007 »

czerny

  • Guest
Re: right aligned shortcut key in menu item
« Reply #2 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!

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1696
Re: right aligned shortcut key in menu item
« Reply #3 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"
« Last Edit: August 18, 2014, 04:04:56 pm by frankie »

JohnF

  • Guest
Re: right aligned shortcut key in menu item
« Reply #4 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

czerny

  • Guest
Re: right aligned shortcut key in menu item
« Reply #5 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
and http://stackoverflow.com/questions/4975077/how-do-i-right-align-the-shortcut-keys-in-menu
« Last Edit: August 18, 2014, 06:45:20 pm by czerny »

JohnF

  • Guest
Re: right aligned shortcut key in menu item
« Reply #6 on: August 18, 2014, 07:47:48 pm »
To the right. See image

I can send the project if you want.

John

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 1836
Re: right aligned shortcut key in menu item
« Reply #7 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.
May the source be with you

JohnF

  • Guest
Re: right aligned shortcut key in menu item
« Reply #8 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

czerny

  • Guest
Re: right aligned shortcut key in menu item
« Reply #9 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!

JohnF

  • Guest
Re: right aligned shortcut key in menu item
« Reply #10 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

czerny

  • Guest
Re: right aligned shortcut key in menu item
« Reply #11 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.
« Last Edit: August 19, 2014, 10:30:57 am by czerny »

JohnF

  • Guest
Re: right aligned shortcut key in menu item
« Reply #12 on: August 19, 2014, 10:42:27 am »
What am I missing? The short cuts look right aligned to me.

John

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 1696
Re: right aligned shortcut key in menu item
« Reply #13 on: August 19, 2014, 11:15:50 am »
Czerny mean right justifyed.

JohnF

  • Guest
Re: right aligned shortcut key in menu item
« Reply #14 on: August 19, 2014, 11:40:05 am »
Like this.

John