利用CRebar和CDialogBar编写可浮动的dialog类型的工具栏

这个crebar用起来参数真奇怪, 算了, 直接上代码吧:
先弄一个基于cdialog的类CMyDlgBar,将基类改为cdialogbar, 需要注意必须修改 constructor(没有参数), OnInitDialog(里面需要初始化)
class  CMyDlgBar :  public  CDialogBar
ExpandedBlockStart.gifContractedBlock.gif
{
    DECLARE_DYNAMIC(CMyDlgBar)

public:
    CMyDlgBar();   
// standard constructor
    virtual ~CMyDlgBar();

// Dialog Data
ExpandedSubBlockStart.gifContractedSubBlock.gif
    enum { IDD = IDD_DIALOG1 };

protected:
    
virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

    DECLARE_MESSAGE_MAP()
public:
    
virtual BOOL Create(CWnd* pParentWnd, UINT nIDTemplate, UINT nStyle, UINT nID);
    
int m_nData;
    afx_msg 
void OnBnClickedOk();
//    afx_msg void OnBnClickedButton1();
    afx_msg void OnBnClickedButton1();
    afx_msg LRESULT OnInitDialog(UINT wParam,LONG lParam);

    afx_msg 
void OnEnChangeEdit1();
}
;


//  CMyDlgBar dialog

IMPLEMENT_DYNAMIC(CMyDlgBar, CDialogBar)

CMyDlgBar::CMyDlgBar()
    : CDialogBar()
    , m_nData(
0 )
ExpandedBlockStart.gifContractedBlock.gif
{

}


CMyDlgBar::
~ CMyDlgBar()
ExpandedBlockStart.gifContractedBlock.gif
{
}


void  CMyDlgBar::DoDataExchange(CDataExchange *  pDX)
ExpandedBlockStart.gifContractedBlock.gif
{
    CDialogBar::DoDataExchange(pDX);
}



BEGIN_MESSAGE_MAP(CMyDlgBar, CDialogBar)
    ON_BN_CLICKED(IDOK, 
& CMyDlgBar::OnBnClickedOk)
//     ON_BN_CLICKED(IDC_BUTTON1, &CMyDlgBar::OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON1,  & CMyDlgBar::OnBnClickedButton1)
ON_EN_CHANGE(IDC_EDIT1, 
& CMyDlgBar::OnEnChangeEdit1)
ON_MESSAGE(WM_INITDIALOG,OnInitDialog)
END_MESSAGE_MAP()

LRESULT CMyDlgBar::OnInitDialog(UINT wParam,LONG lParam)

ExpandedBlockStart.gifContractedBlock.gif
{

    
// TODO: Add extra initialization here

    BOOL bRet 
= HandleInitDialog(wParam,lParam);

    
if (!UpdateData(FALSE))

ExpandedSubBlockStart.gifContractedSubBlock.gif    
{

        TRACE(
"InitCDataStatus Failed!");

    }


    
return TRUE; // return TRUE unless you set the focus to a control

    
// EXCEPTION: OCX Property Pages should return FALSE

}


//  CMyDlgBar message handlers

BOOL CMyDlgBar::Create(CWnd
*  pParentWnd, UINT nIDTemplate, UINT nStyle, UINT nID)
ExpandedBlockStart.gifContractedBlock.gif
{
    
// TODO: Add your specialized code here and/or call the base class

     CDialogBar::Create(pParentWnd, nIDTemplate, nStyle, nID);
     UpdateData(FALSE);
     
return TRUE;
}


void  CMyDlgBar::OnBnClickedOk()
ExpandedBlockStart.gifContractedBlock.gif
{
    
// TODO: Add your control notification handler code here
}


// void CMyDlgBar::OnBnClickedButton1()
// {
//      //  TODO: Add your control notification handler code here
// }

void  CMyDlgBar::OnBnClickedButton1()
ExpandedBlockStart.gifContractedBlock.gif
{
    
// TODO: Add your control notification handler code here
}



void  CMyDlgBar::OnEnChangeEdit1()
ExpandedBlockStart.gifContractedBlock.gif
{
    
// TODO:  If this is a RICHEDIT control, the control will not
    
// send this notification unless you override the CDialogBar::OnInitDialog()
    
// function and call CRichEditCtrl().SetEventMask()
    
// with the ENM_CHANGE flag ORed into the mask.
    MessageBox(L"Changed");
    
// TODO:  Add your control notification handler code here
}



在cmainframe里面定义两个变量
CMyDlgBar m_barAttrib;
    CReBar      m_wndReBar;

必须实现oncreate和oncmdmsg

int  CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
ExpandedBlockStart.gifContractedBlock.gif
{
    
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
        
return -1;
    
    
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
        
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
        
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        TRACE0(
"Failed to create toolbar\n");
        
return -1;      // fail to create
    }


    
if (!m_wndStatusBar.Create(this||
        
!m_wndStatusBar.SetIndicators(indicators,
          
sizeof(indicators)/sizeof(UINT)))
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        TRACE0(
"Failed to create status bar\n");
        
return -1;      // fail to create
    }


    
// TODO: Delete these three lines if you don't want the toolbar to be dockable
    if (!m_barAttrib.Create(this,m_barAttrib.IDD, CBRS_ALIGN_RIGHT|CBRS_GRIPPER, m_barAttrib.IDD))
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        TRACE0(
"Failed to create dialogbar\n");
        
return -1;
    }

    m_barAttrib.SetWindowText(L
"部件属性");
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//*XXX是一个资源id手工直接在资源的.h文件中添加一条,不会,这里就不教了。
        工具条的显示和隐藏代码如下,自己慢慢理解吧:
*/

    
//    ShowControlBar(&m_barAttrib, (m_barAttrib.GetStyle() & WS_VISIBLE) == 0, FALSE);

    
//m_wndReBar.Create(this);
    m_wndReBar.Create(this,   RBS_AUTOSIZE   |   RBS_BANDBORDERS,
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//*WS_CHILD   |   WS_VISIBLE   |  WS_CLIPSIBLINGS   |   WS_CLIPCHILDREN   | */  CBRS_RIGHT) ;
    m_wndReBar.AddBar(
&m_barAttrib,NULL,NULL, RBBS_GRIPPERALWAYS|RBBS_FIXEDBMP);
    
    
//m_wndReBar.AddBar(&m_wndToolBar,NULL,NULL, RBBS_GRIPPERALWAYS|RBBS_FIXEDBMP);
    m_barAttrib.EnableDocking(CBRS_ALIGN_ANY);
    
    m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
    EnableDocking(CBRS_ALIGN_ANY);
    DockControlBar(
&m_barAttrib);
    DockControlBar(
&m_wndToolBar);
    
    
    
return 0;
}

BOOL CMainFrame::OnCmdMsg(UINT nID, 
int  nCode,  void *  pExtra, AFX_CMDHANDLERINFO *  pHandlerInfo)
ExpandedBlockStart.gifContractedBlock.gif
{
    
// TODO: Add your specialized code here and/or call the base class

    
if(m_barAttrib.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
        
return TRUE;
    
return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值