I recently needed to have 256 color toolbars in my app. If you create 256 color bitmaps in devstudio, and try to use them with CToolbar it won't work. The problem is in the LoadBitmap() member or CToolbar. Appwizard will create the following line in your CMainFrame class:
m_wndToolBar.LoadBitmap(IDR_MAINFRAME) Here is the fix, just replace the load bitmap call with a call to the control itself:
m_wndToolBar.GetToolBarCtrl().AddBitmap(iNumButtons,IDR_MAINFRAME);It really is that easy, I found this solution after writing my own toolbar class that used the tool control directly, and 256 color bitmaps worked fine. I couldn't believe it, but it works! Comments:
m_wndToolBar.LoadBitmap(IDR_MAINFRAME) Here is the fix, just replace the load bitmap call with a call to the control itself:
m_wndToolBar.GetToolBarCtrl().AddBitmap(iNumButtons,IDR_MAINFRAME);It really is that easy, I found this solution after writing my own toolbar class that used the tool control directly, and 256 color bitmaps worked fine. I couldn't believe it, but it works! Comments:
解决方案 »
- 关于MDI中使用opencv的2019报错的问题
- 关于Cwebbrowser2的使用(VC++)!
- 类内的静态字符串问题
- 请问:如何选择ListCtrl控件的某一个单元格?
- 怎样禁止combox控件的输入
- gethostbyaddr()扫描不存在IP时的等待时间可否改变?
- 为什么我自定义的继承于CWnd的类接受不到某些消息,比如WM_MOUSELEAVE?
- 如何用mfc实现对注册表的查询?急!!
- c语言将一个数组写入文件出错
- win Socket的默认发送与接收缓冲区的大小的多少。
- 为什么不能在CEditView 派生出来的窗口上使用TextOut 函数! 是我做错了,还是有什么 其他的原因!
- 如何判断windows的版本信息(windows95、98or 2000)
CImageList *imgLst;
imgLst = new CImageList();
imgLst->Create(32,32,ILC_COLOR32 | ILC_MASK,1,2);
CBitmap bmp;
bmp.LoadBitmap(IDR_MAINFRAME);
imgLst->Add(&bmp,(COLORREF)0xFFFFFF) //白色为透明色
m_wndToolBar.SetImageList(&imgLst);
TBBUTTON tbtButton[1];
LPTBBUTTON pBtn;
tbtButton[0].fsStyle=TBSTYLE_BUTTON; //TBSTYLE_CHECK 为选项按钮
tbtButton[0].fsState=TBSTATE_ENABLED //设置按钮可用
int nPos;
CString strLabel;
strLabel="示例\0";
nPos = m_wndToolBar.AddStrings(strLabel);
tbtButton[0].iString=nPos;
tbtButton[0].iBitmap=0;
tbtButton[0].iCommand=300001; //这个值的OnCommand事件中的LOWORD(wParam),也就是资源ID一样
pBtn=tbtButton;
m_wndToolBar.AddButtons(1,pBtn);
//设置Hot ToolBar;
CImageList imageList;
CBitmap bitmap;
//Create and set the normal toolbar image list
bitmap.LoadBitmap(IDB_TOOLBAR_HOT);
imageList.Create(25, 20, ILC_COLORDDB, 13, 1);
imageList.Add(&bitmap, RGB(255, 0, 255));
m_wndToolBar.GetToolBarCtrl().SetHotImageList(&imageList);
imageList.Detach();
bitmap.Detach();