Force a popup menu hosted in a CDialog to show up its accelerators keys
-
Hi, I have a dialog form inside a pane that has a popup menu which messages are handled in the CMainFrame. I am doing this because the same menu exists also in another pane. In this case, the acceleratos of the Dialog's popupmenu are hidden since the MFC framework does not "see" any message handlers inside the dialog. The messages as I said before, are handled in the CMainFrame. The accelerators itself works just fine, the only problem is that does not show up in the screen to inform the user. So, how to force MFC framework to show the dialog's accelerator keys ? I tried to add message handlers in the dialog class but it didn't worked.
sdancer75
-
Hi, I have a dialog form inside a pane that has a popup menu which messages are handled in the CMainFrame. I am doing this because the same menu exists also in another pane. In this case, the acceleratos of the Dialog's popupmenu are hidden since the MFC framework does not "see" any message handlers inside the dialog. The messages as I said before, are handled in the CMainFrame. The accelerators itself works just fine, the only problem is that does not show up in the screen to inform the user. So, how to force MFC framework to show the dialog's accelerator keys ? I tried to add message handlers in the dialog class but it didn't worked.
sdancer75
Going on a screen-shot in this article: An examination of menus from a beginner's point of view[^] Particularly, this image: http://www.codeproject.com/KB/menus/MenusForBeginners/MenuItemEdit.jpg[^] You can see that adding a tab character and then the text to indicate the accelerator is the way it's done. So, to make a menu item that says "Bold" and indicates the functionality can be achieved by hitting Ctrl-B, I'd use the text "Bold\tCtrl-B". Unlike the use of the & character to underline the following letter _and_ make the folowing letter actually work, with accelerators, you have to add the text and the accelerator yourself in 2 steps. One as I mentioned, by adding a tab separator between the main text and the accelerator text and the other, by adding an accelerator table,as you've already done.
"When I was 5 years old, my mother always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down 'happy'. They told me I didn't understand the assignment, and I told them they didn't understand life." - John Lennon
-
Going on a screen-shot in this article: An examination of menus from a beginner's point of view[^] Particularly, this image: http://www.codeproject.com/KB/menus/MenusForBeginners/MenuItemEdit.jpg[^] You can see that adding a tab character and then the text to indicate the accelerator is the way it's done. So, to make a menu item that says "Bold" and indicates the functionality can be achieved by hitting Ctrl-B, I'd use the text "Bold\tCtrl-B". Unlike the use of the & character to underline the following letter _and_ make the folowing letter actually work, with accelerators, you have to add the text and the accelerator yourself in 2 steps. One as I mentioned, by adding a tab separator between the main text and the accelerator text and the other, by adding an accelerator table,as you've already done.
"When I was 5 years old, my mother always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down 'happy'. They told me I didn't understand the assignment, and I told them they didn't understand life." - John Lennon
Hi, You may did not understand the problem. The menus are created dynamically and they have their accelerators shortcut keys as declared below.
VERIFY(popmenu.CreatePopupMenu());
popmenu.AppendMenu(MF_STRING, ID_MENU_STRETCH_NORMAL, _T("&Option 1\tAlt+1"));
popmenu.AppendMenu(MF_STRING, ID_MENU_STRETCH_MAX, _T("&Option 2\tAlt+2"));The problem is that when the popup is showning up to the screen, the acceleratos keys are hidden for the reason I explained in my first post. Regards,
sdancer75
-
Hi, You may did not understand the problem. The menus are created dynamically and they have their accelerators shortcut keys as declared below.
VERIFY(popmenu.CreatePopupMenu());
popmenu.AppendMenu(MF_STRING, ID_MENU_STRETCH_NORMAL, _T("&Option 1\tAlt+1"));
popmenu.AppendMenu(MF_STRING, ID_MENU_STRETCH_MAX, _T("&Option 2\tAlt+2"));The problem is that when the popup is showning up to the screen, the acceleratos keys are hidden for the reason I explained in my first post. Regards,
sdancer75
sdancer75 wrote:
Hi, You may did not understand the problem.
Hi, Yes, I think that is true. If I understand correctly, the accelerator 'hints' on the popup menu are fine. However, when the popup is displayed, the accelerator hints of the dialog are hidden. If so, I'm still not sure I understand what the issue is - i.e, a popup menu has the keyboard and mouse focus until it dissapears. It is the WindowProc of the popup that receives all input, so in that case it seems to me, that displaying the accelerators of the dialog would not be useful. However, you've already mentioned that the accelerators are working correctly. This, combined with the thread title and your last post leaves me confused as to what your intentions and problem are. :confused:
"When I was 5 years old, my mother always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down 'happy'. They told me I didn't understand the assignment, and I told them they didn't understand life." - John Lennon
-
sdancer75 wrote:
Hi, You may did not understand the problem.
Hi, Yes, I think that is true. If I understand correctly, the accelerator 'hints' on the popup menu are fine. However, when the popup is displayed, the accelerator hints of the dialog are hidden. If so, I'm still not sure I understand what the issue is - i.e, a popup menu has the keyboard and mouse focus until it dissapears. It is the WindowProc of the popup that receives all input, so in that case it seems to me, that displaying the accelerators of the dialog would not be useful. However, you've already mentioned that the accelerators are working correctly. This, combined with the thread title and your last post leaves me confused as to what your intentions and problem are. :confused:
"When I was 5 years old, my mother always told me that happiness was the key to life. When I went to school, they asked me what I wanted to be when I grew up. I wrote down 'happy'. They told me I didn't understand the assignment, and I told them they didn't understand life." - John Lennon
enhzflep wrote:
If I understand correctly, the accelerator 'hints' on the popup menu are fine. However, when the popup is displayed, the accelerator hints of the dialog are hidden.
That's correct. By default if you start a new MFC app and you create a menu that have some acceleration keys, if you are not handling in some way their messages ie loading the accel table, then it automatically disables them. The problem is that I handle the accel keys not in the dialog but in the MainFrame where the same menu also exists !!! Regards,
sdancer75