设为首页 加入收藏

TOP

13.2.4 为工具栏添加图像资源关联
2013-10-07 14:35:32 来源: 作者: 【 】 浏览:60
Tags:13.2.4 工具 添加 图像 资源 关联

13.2.4  为工具栏添加图像资源关联

实现一个函数,在这个函数中将根据串口开关状态为工具栏载入位图资源。

  1. 01  void CComElvesDlg::SetOpenButton()  
  2. 02  {  
  3. 03      CImageList  imageList;  
  4. 04      CBitmap     bitmap;  
  5. 05      if(!m_bOpened)  
  6. 06      {  
  7. 07          //创建并设置串口关闭时工具栏位图链表  
  8. 08          bitmap.LoadBitmap(IDB_TOOL_CLOSE);  
  9. 09          imageList.Create(32, 32, ILC_COLORDDB|ILC_MASK, 13, 1);  
  10. 10          imageList.Add(&bitmap, RGB(192,192,192));   
  11. 11      }  
  12. 12      else  
  13. 13      {  
  14. 14          //创建并设置串口打开时工具栏位图链表  
  15. 15          bitmap.LoadBitmap(IDB_TOOL_OPEN);  
  16. 16          imageList.Create(32, 32, ILC_COLORDDB|ILC_MASK, 13, 1);  
  17. 17      }   
  18. 18      imageList.Add(&bitmap, RGB(192,192,192));   
  19. 19      //向工具栏发送消息添加位图链表  
  20. 20      m_ToolBar.SendMessage(TB_SETIMAGELIST, 0,   
  21. 21                              (LPARAM)imageList.m_hImageList);  
  22. 22      imageList.Detach();  
  23. 23      bitmap.Detach();  
  24. 24      m_ToolBar.Invalidate();  
  25. 25  } 

【代码解析】

第5~11行载入串口关闭时的位图资源,第12~18行载入串口打开时的位图资源。第19行将位图插入图像列表,第20行将向工具栏发送插入图像列表的消息,将刚刚插入位图资源的图像列表作为工具栏位图。如此便完成了自定义位图的工具栏。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇11.6.3 截图功能的设计与实现(4) 下一篇13.2.5 为工具栏添加提示信息

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: