代码之家  ›  专栏  ›  技术社区  ›  foraidt

如何使CMFCToolBar识别图像遮罩?

  •  1
  • foraidt  · 技术社区  · 17 年前

    CMFCToolBar -派生类及其派生类是 CDockablePane -派生类。

    我查看了VisualStudioDemo示例以了解它是如何完成的,到目前为止:

    int CMyPane::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
        // Removed all "return -1 on error" code for better readability
    
        CDockablePane::OnCreate(lpCreateStruct);
    
        if(m_toolBar.Create(this, AFX_DEFAULT_TOOLBAR_STYLE, IDR_MY_TOOLBAR) &&
           m_toolBar.LoadToolBar(IDR_MY_TOOLBAR, 0, 0, TRUE /* Is locked */))
        {
    
            if(theApp.m_bHiColorIcons) // Is true, i.e. following code is executed
            {
                m_toolBar.CleanUpLockedImages();
                m_toolBar.LoadBitmap(IDB_MY_TOOLBAR_24, 0, 0, TRUE /*Locked*/);
            }
    
            m_toolBar.SetPaneStyle(m_toolBar.GetPaneStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
            m_toolBar.SetPaneStyle(m_toolBar.GetPaneStyle() & ~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));
    
            m_toolBar.SetOwner(this);
    
            // All commands will be routed via this control , not via the parent frame:
            m_toolBar.SetRouteCommandsViaFrame(FALSE);
        }
    
        return 0;
    }
    

    高颜色图像(24位)已加载,但洋红遮罩(R255 G0 B255)可见。我不知道如何告诉工具栏识别掩码。

    3 回复  |  直到 17 年前
        1
  •  3
  •   djeidot    17 年前

    我不知道这是否每次都有效,但我使用 RGB(192, 192, 192) 作为遮罩颜色,它确实会被识别。

    (似乎CMFCToolBar控件已准备好使用 ::GetSysColor(COLOR_BTNFACE) 作为透明色…)

        2
  •  0
  •   foraidt    17 年前

    我刚刚发现一个解决方法是使用32位图像和它们的alpha通道。 我之前尝试过使用32位图像,但由于其他原因无法正常工作,然后认为32位图像无法正常工作。

        3
  •  0
  •   Rohit Vipin Mathews    13 年前

    CBitmap 改用 ATL::CImage CPNGImage object 并相应加载 resource ID

    推荐文章