在Codejock工具条里加入控件的方法

本文介绍如何在MFC应用程序中集成自定义工具栏和组合框控件,包括在MainFrame中定义变量、声明消息处理程序、创建工具栏及组合框等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

1。在MainFrame中定义相关变量

 CXTPToolBar*  m_pToolbar;
 CXTPControlComboBox* m_pCombox;

2.在MainFrame中声明系统消息处理程序

   afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
   afx_msg int OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl);

3。在函数OnCreate中加入下面的语句

 CXTPCommandBars* pCommandBars = GetCommandBars();
    if(pCommandBars == NULL)
    {
        TRACE0("Failed to create command bars object./n");
        return -1;      // fail to create
    }

 m_pToolbar = (CXTPToolBar*)
        pCommandBars->Add(_T("工具栏"), xtpBarTop);
    if (!m_pToolbar || !m_pToolbar->LoadToolBar(IDR_TOOLBAR))
    {
        TRACE0("Failed to create toolbar/n");
        return -1;
    }

4. 在MainFrame.cpp中加入消息图

BEGIN_MESSAGE_MAP(CMainFrame, CXTPMDIFrameWnd)
 ON_XTP_CREATECONTROL()
END_MESSAGE_MAP()

5。在函数OnCreateControl中加入类似于下面的语句。这和具体使用的控件相关

 if (lpCreateControl->bToolBar)
 {
  CXTPToolBar* pToolBar = DYNAMIC_DOWNCAST(CXTPToolBar, lpCreateControl->pCommandBar);
  if (!pToolBar)
   return FALSE;

  //波形显示模块中的横向显示选择
  if (lpCreateControl->nID == ID_COMBOX && pToolBar->GetBarID() == IDR_TOOLBAR)
  {
   m_pCombox = (CXTPControlComboBox*)CXTPControlComboBox::CreateObject();
   m_pCombox->SetDropDownWidth(80);
   lpCreateControl->pControl = m_pCombox;
   return TRUE;
  }

6.在View的适当函数中加入类似于下面的语句,这和具体使用的控件相关。

  CChildFrame* pChild = (CChildFrame*)GetParentFrame();
  pChild->m_pWndMainFrm->m_pCombox->ResetContent();
  pChild->m_pWndMainFrm->m_pCombox->AddString(str1);
  pChild->m_pWndMainFrm->m_pCombox->AddString(str2);
  pChild->m_pWndMainFrm->m_pCombox->AddString(str3);
  pChild->m_pWndMainFrm->m_pCombox->AddString(str4);
  pChild->m_pWndMainFrm->m_pCombox->SetCurSel(2);


 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值