MFC Feature Pack类菜单上的图标 [英] Icons on menus of MFC Feature Pack classes

查看:58
本文介绍了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,然后才能对其执行任何操作.甚至 if 都让它做到了(因为在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类菜单上的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆