VS2008(SP1)在静态编译的程序中,可能VS2010也是一样. CMFCColorDialog弹不出来或者CMFCColorButton的Other按钮无效(其实本人目前发现这些新特性控件中CMFCEditBrowseCtrl控件的图标也是,
CMFCTabCtrl控件创建成CMFCTabCtrl::STYLE_FLAT式样时也需要加载ribbon资源, 不然那些箭头不能显示),这时需要手动修改一下rc文件.
在Edit菜单中选择resource includes
在Read only symbol directives里面加入
#if !defined(_AFXDLL) #include "afxribbon.rc" // MFC ribbon and control bar resources #endif
=============================================
插一句, 上面是在网上看到的, 其实不对的, 这里是今天修改的, 其实参考NewControls的列子, 用记事本打开*.rc文件修改后面的, 下面绿色粗体字是要自己添加的 (其实是用资源视图时, "编辑"->"资源包括", 在"编译时指令"中添加, 记得不要加错地方就行了)
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE 9, 1
#pragma code_page(1252)
#endif //_WIN32
#include "res\NewControls.rc2" // non-Microsoft Visual C++ edited resources
#include "afxres.rc" // Standard components
#ifndef _AFXDLL
#include "afxribbon.rc" // Ribbon and control bars
#endif
#endif
#ifdef _WIN32
LANGUAGE 9, 1
#pragma code_page(1252)
#endif //_WIN32
#include "res\NewControls.rc2" // non-Microsoft Visual C++ edited resources
#include "afxres.rc" // Standard components
#ifndef _AFXDLL
#include "afxribbon.rc" // Ribbon and control bars
#endif
#endif
===========================分割线==========================
CMFCColorButton的other按钮弹不出来颜色对话框,是因为CMFCColorButton默认使用CMFCColorDialog来弹出来的,而这个对话框需要手动编辑一下资源,但是添加"afxribbon.rc"
后出现资源错误,郁闷,55555.......不过可以修改CMFCColorButton弹出系统颜色对话框来.就是下面这样... CMFCColorButton::bAltColorDlg变量为FALSE即可....
后出现资源错误,郁闷,55555.......不过可以修改CMFCColorButton弹出系统颜色对话框来.就是下面这样... CMFCColorButton::bAltColorDlg变量为FALSE即可....
#ifndef _AFXDLL m_ColorPicker.EnableOtherButton(_T("Other"), FALSE, TRUE); #endif
========================简单自绘CMFCColorButton=============================
//头文件MyColorButton.h
#pragma once #include "afxcolorbutton.h" class CMyColorButton : public CMFCColorButton { public: CMyColorButton(void); ~CMyColorButton(void); virtual void OnDraw(CDC* pDC, const CRect& rect, UINT uiState); virtual void OnDrawFocusRect(CDC* pDC, const CRect& rectClient); };
//实现文件MyColorButton.cpp
#include "StdAfx.h" #include "MyColorButton.h" CMyColorButton::CMyColorButton(void) { } CMyColorButton::~CMyColorButton(void) { } void CMyColorButton::OnDraw(CDC* pDC, const CRect& rect, UINT uiState) { ASSERT_VALID(pDC); if (m_pPalette == NULL) { RebuildPalette(NULL); } CPalette* pCurPalette = pDC->SelectPalette(m_pPalette, FALSE); pDC->RealizePalette(); CSize sizeArrow = CMenuImages::Size(); CRect rectColor = rect; COLORREF color = m_Color; if (color == (COLORREF) -1) // Automatic { //--------------------------- // Draw automatic text label: //--------------------------- color = m_ColorAutomatic; } //---------------- // Draw color box: //---------------- rectColor.DeflateRect(2, 2); pDC->Draw3dRect(rectColor, afxGlobalData.clrBtnHilite, afxGlobalData.clrBtnHilite); rectColor.DeflateRect(1, 1); pDC->Draw3dRect(rectColor, afxGlobalData.clrBtnDkShadow, afxGlobalData.clrBtnDkShadow); rectColor.DeflateRect(1, 1); if (color != (COLORREF)-1 && (uiState & ODS_DISABLED) == 0) { if (afxGlobalData.m_nBitsPerPixel == 8) // 256 colors { ASSERT_VALID(m_pPalette); color = PALETTEINDEX(m_pPalette->GetNearestPaletteIndex(color)); } CBrush br(color); pDC->FillRect(rectColor, &br); } if (pCurPalette != NULL) { pDC->SelectPalette(pCurPalette, FALSE); } } void CMyColorButton::OnDrawFocusRect(CDC* pDC, const CRect& rectClient) { CSize sizeArrow = CMenuImages::Size(); CRect rectColor = rectClient; CMFCButton::OnDrawFocusRect(pDC, rectColor); }