1. Miguel Leeuwe
  2. PowerBuilder
  3. Tuesday, 23 July 2024 16:33 PM UTC

Hi,

I work with 'classical' menus.

I need to change the text of a menu item from code, but when I do so, I lose the shortcut. My manager doesn't want to see the shortcut in the menu text. (if it would be there it would work!). So does anyone know how to assign the shortcut without showing it in the menu item text?

A menu item has a property "shortcut" but that one seems to be read only.

TIA,

MiguelL

Accepted Answer
René Ullrich Accepted Answer Pending Moderation
  1. Wednesday, 24 July 2024 05:28 AM UTC
  2. PowerBuilder
  3. # Permalink

Hi Miguel,

the shortcut code (property "shortcut") and the menu text including the text for the shortcut (property "text") are undepended.

You can change the property "text" at runtime. If you want to see the shortcut in the text you have to add it after a tabulator (e.g. "Print...~tCTRL+P"). This is only a text and does not change the shortcut!

If you want you can also ommit the shortcut text. The shortcut is still working.

You can't change the "shortcut" code property because it is set to systemwrite. So I don't know a way how to change a menu shortcut at runtime.

HTH,

René

Comment
  1. Miguel Leeuwe
  2. Wednesday, 24 July 2024 08:21 AM UTC
Hi Rene,

I know how to set the text, which does seem to work, but cannot set the shortcut from code. That's not what I'm experiencing.

Later I'll make a small sample app. Maybe there's something wrong with my huge pfc based menu.

regards
  1. Helpful
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Tuesday, 23 July 2024 16:50 PM UTC
  2. PowerBuilder
  3. # 1

When you say shortcut, are you talking about adding & in front of one of the letters in the text so that it is underlined and becomes a keyboard shortcut?

The underline being visible or not is a Windows setting.

https://www.tenforums.com/tutorials/97413-turn-off-underline-access-key-shortcuts-menus-windows-10-a.html

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Tuesday, 23 July 2024 18:47 PM UTC
  2. PowerBuilder
  3. # 2

Hi Roland,

I'm speaking of the attributes of a menuitem, as you can see on the right below of this image.

 

Comment
There are no comments made yet.
John Fauss Accepted Answer Pending Moderation
  1. Wednesday, 24 July 2024 02:26 AM UTC
  2. PowerBuilder
  3. # 3

Hi, Miguel -

From the research I've done this evening, it appears that the keyboard shortcuts you are referring to (such as the association of the Ctrl+P keystrokes to the File -> Print menu item, for example) are not implemented in the Windows O/S as menu item properties, but as a Keyboard Shortcut. Evidently, PB executes the C++ interface(s) to establish a keyboard shortcut when a menu item is instantiated. There are no MenuItem Windows API functions or properties in Windows to set/modify/delete this type of keyboard shortcut. Presumably, this is why you cannot modify this behavior dynamically as you described.

Best regards, John

Comment
  1. Roland Smith
  2. Wednesday, 24 July 2024 18:43 PM UTC
My Icontray example has API functions for registering hotkeys:

https://www.topwizprogramming.com/freecode_icontray.html

I'm still wondering why changing the menu item text would disable keyboard shortcuts.
  1. Helpful 1
  1. Miguel Leeuwe
  2. Wednesday, 24 July 2024 19:06 PM UTC
That was my initial impression, but it turns out it doesn't. The piece of stupid code that made me think so, was some code in w_master that set the m_selectall menuitem to "disabled" and therefore things no longer worked.

regards.
  1. Helpful
  1. Miguel Leeuwe
  2. Wednesday, 24 July 2024 19:09 PM UTC
*disabled would be *enabled = false
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 24 July 2024 11:44 AM UTC
  2. PowerBuilder
  3. # 4

Hi all,

Thanks for your help. I created a simple app and everything works correctly.

I still have to figure out why it doesn't in my main application. I think it has something to do with having a menu inherited from the main (frame) menu.

I'll get there sooner or later.

regards and thanks again.

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 24 July 2024 18:41 PM UTC
  2. PowerBuilder
  3. # 5

FYI:

In the end it all come done of someone thinking it was a good idea to manage the m_selectAll menu option in the w_master window of the PFCs. (most likely me).

:)

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.