zoukankan      html  css  js  c++  java
  • VC++ 对话框下使用工具栏

     关于这一技术网上也有很多的记录,下面仅记录我测试OK的代码。

        在CXXDlg.h中添加如下成员变量:

      CToolBar m_ToolBar;

      CBitmap m_bmpTool;

      在CXXDlg.cpp的OnInitDialog中添加如下代码:

     1      UINT nIDs[] = 
     2      {
     3          IDC_OPEN,
     4          IDC_CLOSE,
     5          IDC_FIND,
     6          IDC_COPY,
     7      };
     8  
     9      m_ToolBar.Create(this);
    10      m_bmpTool.LoadBitmapW(IDB_BITMAP2);
    11      m_ToolBar.SetBitmap(m_bmpTool);
    12      m_ToolBar.SetButtons(nIDs,4);
    13      m_ToolBar.SetButtonText(0,_T("打开"));
    14      m_ToolBar.SetButtonText(1,_T("关闭"));
    15      m_ToolBar.SetButtonText(3,_T("复制"));
    16      m_ToolBar.SetButtonText(2,_T("查找"));
    17      m_ToolBar.SetSizes(CSize(55,55),CSize(32,32));
    18  
    19      CRect rcClientStart;  
    20      CRect rcClientNow;  
    21      GetClientRect(rcClientStart);  
    22      RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, reposQuery, rcClientNow);  
    23    
    24      CPoint ptOffset(rcClientNow.left - rcClientStart.left,  
    25      (rcClientNow.top - rcClientStart.top));  
    26    
    27      CRect  rcChild;  
    28      CWnd* pwndChild = GetWindow(GW_CHILD);  
    29      while (pwndChild)  
    30      {  
    31          pwndChild->GetWindowRect(rcChild);  
    32          ScreenToClient(rcChild);  
    33          rcChild.OffsetRect(ptOffset);  
    34          pwndChild->MoveWindow(rcChild, FALSE);  
    35          pwndChild = pwndChild->GetNextWindow();  
    36      }  
    37    
    38      CRect rcWindow;  
    39      GetWindowRect(rcWindow);  
    40      rcWindow.right += rcClientStart.Width() - rcClientNow.Width();  
    41      rcWindow.bottom += (rcClientStart.Height() - rcClientNow.Height());  
    42      MoveWindow(rcWindow, FALSE);  
    43      
    44      RepositionBars(AFX_IDW_CONTROLBAR_FIRST,  
    45      AFX_IDW_CONTROLBAR_LAST, 0, reposExtra); 
    46      CenterWindow();

        按钮的消息效应操作如下:

      消息映射如下:

      ON_COMMAND(IDC_OPEN,&CXXDlg::OnBtnOpen)
      ON_COMMAND(IDC_CLOSE,&CXXDlg::OnBtnClose)
      ON_COMMAND(IDC_FIND,&CXXDlg::OnBtnFind)
      ON_COMMAND(IDC_COPY,&CXXDlg::OnBtnCopy)

     当然这几个消息映射函数定义为了CXXDlg的成员函数,如下: 

     afx_msg void OnBtnOpen();
       afx_msg void OnBtnClose();
       afx_msg void OnBtnFind();
       afx_msg void OnBtnCopy();

     再去实现这些成员函数既可。

     实际效果如下图:

      

  • 相关阅读:
    android 网络加载图片,对图片资源进行优化,并且实现内存双缓存 + 磁盘缓存
    Web前端框架与类库的思考
    android应用开发(十):widget的使用
    响应式WEB设计的9项基本原则
    谈一下关于CQRS架构如何实现高性能
    迪杰斯特拉算法——PAT 1003
    Android开发-SQLite数据库
    寻找水王(2)
    PAT-1003
    PAT-1002
  • 原文地址:https://www.cnblogs.com/kanite/p/5038405.html
Copyright © 2011-2022 走看看