在 Toolbar 上加上汉字显示,却始终显示不出来,但我用GetButtonText可以获得那些汉字。请问可能原因是什么?
解决方案 »
- HOOK安装全局WH_GETMESSAGE用来截取键盘输入的问题
- VS2010中view类的OnDraw不响应
- 通信程序 客户端外网connect连接就10060错误,服务端和客户在本机测试就没事?
- 求助:数据转换
- 求助AppendChunk的使用
- 非常郁闷的问题: ADO连Access在Debug下没问题,Release下面出现"[Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动
- CSplitter 分割后请问怎么控制两个CView的控件---欲与结识端口,驱动编程的朋友
- 几个问题!
- !!!!!!!各位熟悉图像格式的高手们,有谁知道RAW格式的读取,如果能有源程序更好,分不够,可以再加。
- asp中用get传递textarea中的内容时长度有限制,如何解决
- 网上的Carlos Antollini 的 ado.h,ado.cpp SQL数据库可以用吗?急
- MFC中用AfxBeginThread创建一个工程线程,在线程中使用::PostMessage和SYSTEMTIME结构出现问题!
{
public:
int GetHeight();
void AttachToolBarImages(UINT nNormalImageID,
UINT nDisabledImageID,
UINT nHotImageID);
void AddButtonText(const std::vector<CString>& vecButtonText, BOOL bRecalc = TRUE);private:
void _MakeToolBarImageList(UINT nBitmapID, CImageList& outImageList);
void _ReplaceBackgroundColor(CBitmap& ioBM);private:
CImageList _imageListNormal;
CImageList _imageListDisabled;
CImageList _imageListHot;
// Construction
public:
CImageToolBar();// Attributes
public:// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CImageToolBar)
//}}AFX_VIRTUAL// Implementation
public:
virtual ~CImageToolBar(); // Generated message map functions
protected:
//{{AFX_MSG(CImageToolBar)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG DECLARE_MESSAGE_MAP()
};
//
static const int kImageWidth (35);
static const int kImageHeight (35);
static const int kNumImages (11);
static const UINT kToolBarBitDepth (ILC_COLOR24);
static const RGBTRIPLE kBackgroundColor = {192, 192, 192};
//////////////////////////////////////////////////////////////////////////
CImageToolBar::CImageToolBar()
{
}CImageToolBar::~CImageToolBar()
{
}int CImageToolBar::GetHeight()
{
CRect rect;
GetToolBarCtrl().GetWindowRect(&rect); return rect.Height();
}void CImageToolBar::AttachToolBarImages(UINT nNormalImageID, UINT nDisabledImageID, UINT nHotImageID)
{
// make high-color image lists for each of the bitmaps
_MakeToolBarImageList (nNormalImageID, _imageListNormal);
_MakeToolBarImageList (nDisabledImageID, _imageListDisabled);
_MakeToolBarImageList (nHotImageID, _imageListHot); // get the toolbar control associated with the CToolbar object
CToolBarCtrl& barCtrl = GetToolBarCtrl(); // attach the image lists to the toolbar control
barCtrl.SetImageList (&_imageListNormal);
barCtrl.SetDisabledImageList (&_imageListDisabled);
barCtrl.SetHotImageList (&_imageListHot);
}void CImageToolBar::AddButtonText(const std::vector<CString>& vecButtonText, BOOL bRecalc /* = TRUE */)
{
CSize sizeMax;
if(bRecalc)
{
sizeMax.cx = 0;
sizeMax.cy = 0; // 取得最大尺寸
CRect rect;
for (int i = 0; i < GetCount(); ++i)
{
SetButtonText(i, vecButtonText[i]);
GetItemRect(i, rect);
sizeMax.cx = __max(rect.Size().cx, sizeMax.cx);
sizeMax.cy = __max(rect.Size().cy, sizeMax.cy);
}
}
//设置按钮尺寸
SIZE sizeButton, sizeImage;
sizeButton.cx = sizeMax.cx;
sizeButton.cy = sizeMax.cy;
sizeImage.cx = 32;
sizeImage.cy = 32;
SetSizes(sizeButton, sizeImage); RedrawWindow();
}void CImageToolBar::_MakeToolBarImageList(UINT nBitmapID, CImageList& outImageList)
{
CBitmap bm; // if we use CBitmap::LoadBitmap() to load the bitmap, the colors
// will be reduced to the bit depth of the main screen and we won't
// be able to access the pixels directly. To avoid those problems,
// we'll load the bitmap as a DIBSection instead and attach the
// DIBSection to the CBitmap.
VERIFY (bm.Attach (::LoadImage (::AfxFindResourceHandle(
MAKEINTRESOURCE (nBitmapID), RT_BITMAP),
MAKEINTRESOURCE (nBitmapID), IMAGE_BITMAP, 0, 0,
(LR_DEFAULTSIZE | LR_CREATEDIBSECTION)))); // replace the specified color in the bitmap with the user's
// button color
//::_ReplaceBackgroundColor (bm); // create a 24 bit image list with the same dimensions and number
// of buttons as the toolbar
VERIFY (outImageList.Create (
kImageWidth, kImageHeight, kToolBarBitDepth |ILC_MASK, kNumImages, 0));
outImageList.SetBkColor(::GetSysColor(COLOR_BTNFACE)); // attach the bitmap to the image list
VERIFY (outImageList.Add (&bm, RGB(214, 209, 198)) != -1);
}void CImageToolBar::_ReplaceBackgroundColor(CBitmap& ioBM)
{
// figure out how many pixels there are in the bitmap
BITMAP bmInfo; VERIFY (ioBM.GetBitmap (&bmInfo));
// add support for additional bit depths here if you choose
VERIFY (bmInfo.bmBitsPixel == 8);
VERIFY (bmInfo.bmWidthBytes == bmInfo.bmWidth); const UINT numPixels (bmInfo.bmHeight * bmInfo.bmWidth); // get a pointer to the pixels
DIBSECTION ds; VERIFY (ioBM.GetObject (sizeof (DIBSECTION), &ds) == sizeof (DIBSECTION)); RGBTRIPLE* pixels = reinterpret_cast<RGBTRIPLE*>(ds.dsBm.bmBits);
VERIFY (pixels != NULL); // get the user's preferred button color from the system
const COLORREF buttonColor (::GetSysColor (COLOR_BTNFACE));
const RGBTRIPLE userBackgroundColor = {
GetBValue (buttonColor), GetGValue (buttonColor), GetRValue (buttonColor)}; // search through the pixels, substituting the user's button
// color for any pixel that has the magic background color
for (UINT i = 0; i < numPixels; ++i)
{
if (pixels [i].rgbtBlue == kBackgroundColor.rgbtBlue &&
pixels [i].rgbtGreen == kBackgroundColor.rgbtGreen &&
pixels [i].rgbtRed == kBackgroundColor.rgbtRed)
{
pixels [i] = userBackgroundColor;
}
}
}BEGIN_MESSAGE_MAP(CImageToolBar, CToolBar)
//{{AFX_MSG_MAP(CImageToolBar)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
是style属性设置的问题吧,呵呵