MFC Feature Pack 类菜单上的图标

Icons on menus of MFC Feature Pack classes(MFC Feature Pack 类菜单上的图标)

本文介绍了MFC Feature Pack 类菜单上的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新的 MFC 功能(功能包)中有三个地方显示菜单:

There are three places where menus show up in the new MFC functionality (Feature Pack):

  • 在菜单栏中 (CMFCMenuBar)
  • 在弹出菜单中 (CMFCPopupMenu)
  • 在 CMFCButton 的下拉菜单"版本中

我想把图标(高颜色和透明)放在所有的菜单中.我找到了 CFrameWndEx::OnDrawMenuImage() ,我可以用它来自定义在菜单栏项目前面绘制图标.这不是很方便,必须在2008年实现图标绘制,但它可以工作.对于其他人,我还没有找到解决方案.有没有自动设置菜单图标的方法?

I want to put icons (high-color and with transparancy) in the menus in all of them. I have found CFrameWndEx::OnDrawMenuImage() which I can use to custom draw the icons in front of the menu bar items. It's not very convenient, having to implement icon drawing in 2008, but it works. For the others I haven't found a solution yet. Is there an automagic way to set icons for menus?

推荐答案

这就是我的工作方式:

,正如其他人所说,在您的主工具栏旁边创建一个不可见的工具栏(我使用基于 AppWizard 名称的常用名称):

, as the others said, create an invisible toolbar next to your main toolbar (I'm using the usual names based on AppWizard's names):

MainFrm.h:
class CMainFrame
{
    //...    
    CMFCToolBar m_wndToolBar;
    CMFCToolBar m_wndInvisibleToolBar;
    //...
};

MainFrm.cpp:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    //...

    // Normal, visible toolbar
    if(m_wndToolBar.Create(this,
        TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC))
    {
        VERIFY( m_wndToolBar.LoadToolBar(
            theApp.m_bHiColorIcons ? IDR_MAINFRAME_256 : IDR_MAINFRAME) );

        // Only the docking makes the toolbar visible
        m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
        DockPane(&m_wndToolBar);
    }

    // Invisible toolbar; simply calling Create(this) seems to be enough
    if(m_wndInvisibleToolBar.Create(this))
    {
        // Just load, no docking and stuff
        VERIFY( m_wndInvisibleToolBar.LoadToolBar(IDR_OTHERTOOLBAR) );
    }
}

二:图片和工具栏资源

IDR_MAINFRAMEIDR_MAINFRAME_256 由 AppWizard 生成.前者是丑16色版,后者是趣味高彩版.
尽管它的名字,如果我没记错的话,即使是 AppWizard 生成的图像也有 24 位色深.很酷的事情:只需用 32 位图像替换它,这也可以.

Second: The images and toolbar resources

IDR_MAINFRAME and IDR_MAINFRAME_256 were generated by AppWizard. The former is the ugly 16 color version and the latter is the interesting high color version.
Despite its name, if I remember correctly, even the AppWizard-generated image has 24bit color depth. The cool thing: Just replace it with a 32bit image and that'll work, too.

有一个不可见的工具栏IDR_OTHERTOOLBAR:我用资源编辑器创建了一个工具栏.只是一些虚拟图标和命令 ID.然后 VS 生成了一个位图,我用我的高彩版本替换了它.完成!

There is the invisible toolbar IDR_OTHERTOOLBAR: I created a toolbar with the resource editor. Just some dummy icons and the command IDs. VS then generated a bitmap which I replaced with my high color version. Done!

不要使用资源编辑器打开工具栏:它可能必须先将其转换为 4bit,然后才能对其进行任何操作.即使如果你让它这样做(因为,在 Visual Studio 的背后,你会再次用高彩色图像替换结果,哈!),我发现它(有时?)根本无法编辑工具栏.很奇怪.
在这种情况下,我建议直接编辑 .rc 文件.

Don't open the toolbars with the resource editor: It may have to convert it to 4bit before it can do anything with it. And even if you let it do that (because, behind Visual Studio's back, wou're going to replace the result with the high color image again, ha!), I found that it (sometimes?) simply cannot edit the toolbar. Very strange.
In that case I advise to directly edit the .rc file.

这篇关于MFC Feature Pack 类菜单上的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:MFC Feature Pack 类菜单上的图标

基础教程推荐