本文介绍了无法使选项卡在菜单项描述中起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经花了一整天的时间没有在哪里,我希望有人可以帮助



i有一个vs2010 MFC应用程序我有一些菜单项目项目。每个菜单项都有一个与之关联的键盘键,因此我想使用类似于用于制作剪切,复制和粘贴菜单项的字符串



& ;复制\tCtrl + C这显示在菜单中,复制左对齐,Ctrl + C右对齐



所以我想简单,我让我的琴弦Snare drum\tS,Bass drum\tB等等

带着得到这样的东西

军鼓   S

低音鼓    B

与S和B右对齐

但它不起作用, S和B完全没有显示



我已经厌倦了将它们添加为加速器,我尝试过简单地使用空格但是菜单显示为非固定宽度的字体,所以他们没有正确对齐。它很混乱。也许如果我能找到一种方法来将菜单变成固定宽度的东西,这将有所帮助。



顺便说一下,如果我从中移除\tCtrl + C复制的描述仍然显示它。我怀疑\tCtrl + C是保存在系统注册表的某个地方,但不认为这有助于我



有没有人有想法?

i've spent a whole day on this and got no where, i hope someone can help

i have a vs2010 MFC application and i have a number of menu item items. each menu item has a keyboard key associated with it so i want to use something like the string that is used to make the cut, copy and paste menu items

"&Copy\tCtrl+C" this is displayed in the menu with "Copy" left aligned and "Ctrl+C" right aligned

so i thought simple, i make my strings "Snare drum\tS", "Bass drum\tB", etc
with the expection of getting something like this
Snare drum  S
Bass drum    B
with the S and the B right aligned
but it doesn't work, the S and the B don't show up at all

i've tired adding them as accelerators, i've tried simply using spaces but the menu is displayed with non fixed width fonts so they don't right align nicely. its very confusing. maybe if i can find a way to chenge the menu for to something fixed width that will help.

by the way, if i remove \tCtrl+C from the description of Copy is still displays it. i suspect the \tCtrl+C is saved in the system registry somewhere but don't think that helps me

does anyone have an ideas please?

推荐答案


IDR_POPUP_CONFIG_THIS MENU
BEGIN
    POPUP "Popup"
    BEGIN
        MENUITEM "Delete Configuration\tDel",   ID_DELETE_ITEM
    END
END





当菜单显示时,末尾的\tDel被剥离。



经过多次痛苦和痛苦:),我在以下函数的框架内跟踪调用:



the "\tDel" at the end was stripped off when the menu was displayed.

After much pain and suffering :), I tracked it down to calls within the framework of the following functions:

CKeyboardManager::FindDefaultAccelerator()



由以下人员调用:


which is called by:

CMFCToolBarMenuButton::OnCalculateSize()



弹出菜单项显然是一种CMFCToolBarMenuButton。无论如何,后一个函数抓取一个指向CFrameWnd的指针,在我的情况下,它最终成为应用程序的主窗口。然后它调用CKeyboardManager :: FindDefaultAccelerator(),并传递CFrameWnd指针。此函数搜索CFrameWnd类的加速器表,并尝试查找命令ID的匹配加速键。如果是,它使用CMFCAcceleratorKey的实例来获取与匹配加速器的击键相对应的相应字符串,并将该字符串通过CKeyboardManager :: FindDefaultAccelerator()的参数列表传递给另一个函数,该函数连接菜单项中已有的文本与CMFCAccelerator实例找到的一个。所有这些都支持键盘自定义,如果您考虑它,如果您将快捷键名称放在资源脚本的菜单项中,则通常无法正常工作。我的应用程序没有这样的自定义。



问题是主窗口的加速器表没有CTreeView派生类的加速键。所以需要做的就是将这些加速器添加到主窗口的加速器表中,对吧?嗯,差不多,但还有另一个皱纹。当我修复主窗口的加速器表时,它仍然无法正常工作。深入挖掘,我发现主窗口新修改的加速器表有15个条目,但是在CKeyboardManager :: FindDefaultAccelerator()的主窗口中获取加速器计数的调用只产生了14.这里发生了什么?事实证明,这些加速器存储在注册表中,看起来像ThisApp\\\\\\\\\\\\\\\\\\\\\\\\\我关闭了应用程序,并从注册表中删除了这个密钥文件夹,并且繁荣,加速器密钥计数现在从错误的值14变为正确的值15.看起来这些注册表项跟踪用户所做的更改,但是不是开发者!我尝试从资源脚本中的主窗口加速器表中删除添加的加速器,并且在CKeyboardManager :: FindDefaultAccelerator()中,它仍然告诉我有15个项目,并且仍然在我的菜单上显示加速键文本,即使有在主窗口的加速器表中没有这样的加速器!同样,删除上述注册表项文件夹使所有内容恢复同步。



总结一下,如果你有一个子窗口通过覆盖PreTranslateMessage()来处理自己的加速器要调用:: TranslateAccelerator(),并且您希望加速器的文本显示在子窗口的上下文菜单中,您必须做两件事:



1)将加速器添加到主窗口的加速器表以及

2)删除注册表项,例如此App看起来像ThisApp \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\该解决方案不需要代码,只需编辑.rc文件和注册表。这就是为什么上面列出的唯一代码是MFC功能包中用于进行菜单文本分配的部分。



希望这有助于某人。


A popup menu item is apparently a kind of CMFCToolBarMenuButton. At any rate, the latter function grabs a pointer to a CFrameWnd, which in my case ended up being the main window of the application. Then it calls CKeyboardManager::FindDefaultAccelerator(), passing it the CFrameWnd pointer. This function searches the accelerator table of the CFrameWnd class, and tries to find a matching accelerator key for the command ID. If it does, it uses an instance of CMFCAcceleratorKey to get the appropriate string corresponding to the keystroke of the matching accelerator and passes that string through the argument list of CKeyboardManager::FindDefaultAccelerator() to another function that concatenates the text already in the menu item with the one found by the CMFCAccelerator instance. All of this is in support of the keyboard customization, which, if you think about it, won't work properly in general if you put shortcut key names in the menu item in the resource script. My app does not have such customization.

The problem was that the main window's accelerator table did not have the accelerator keys for the CTreeView-derived class. So all that needs to be done is to add these accelerators to the accelerator table of the main window, right? Well, almost, but there's another wrinkle. When I made the fix to the main window's accelerator table, it still didn't work. Digging a little deeper, I found that the main window's newly-modified accelerator table had 15 entries, but the call to get the count of accelerators in the main window in CKeyboardManager::FindDefaultAccelerator() only yielded 14. What's going on here? It turns out that these accelerators are stored in the registry, in a section that looks like ThisApp\\Workspace\\Keyboard-0. I shut down the app and deleted this key folder from the registry, and boom, the accelerator key count now went from the incorrect value of 14 to the correct value of 15. It looks like these registry entries track changes made by the user, but not the developer! I tried removing the added accelerator from the main window's accelerator table in the resource script, and in CKeyboardManager::FindDefaultAccelerator(), it still told me there were 15 items, and still showed the accelerator key text on my menu, even when there was no such accelerator in the main window's accelerator table! Again, deleting the aforementioned registry key folder brought everything back in sync.

To sum up, if you have a child window that handles its own accelerators by overriding PreTranslateMessage() to call ::TranslateAccelerator(), and you want the text of the accelerators to show up in the context menus of the child window, you must do two things:

1) Add the accelerators to the main window's accelerator table as well
2) Delete the registry key for e.g. ThisApp that looks like ThisApp\\Workspace\\Keyboard-0.

This registry key will be regenerated by the framework on application exit. The solution requires no code, only editing the .rc file and the registry. That's why the only code listed above is the portion of the MFC feature pack in which the menu text assignment takes place.

Hope this helps someone.


void CTabTraxView::OnRButtonUp(UINT /* nFlags */, CPoint point)
{
    ClientToScreen(&point);
    OnContextMenu(this, point);
}
void CTabTraxView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
    theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}



启动鼠标左键弹出,但它是由向导所以我希望它正确



这样的字符串厕所


launches the right mouse popup but it was generated by the wizard so i expect its correct

the string loo like this

BEGIN
            MENUITEM "Snare\tS",        ID_EDIT_SNARE
            MENUITEM "Kick (Bass drum)\tK",        ID_EDIT_BASS
            MENUITEM "Closed High Hat\tH",        ID_EDIT_HIGHHAT
            MENUITEM "Open High Hat\t O",        ID_EDIT_OPENHIGHHAT
        END









我在Windows 7和我'我花了一整天的时间来编译并测试它



etc

i'm on windows 7 and i've spent all day compiling and testing it


这篇关于无法使选项卡在菜单项描述中起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 09:15
查看更多