我按着网上的文章做的。派生了CDialogBar类,自定义了Create函数
BOOL CMyDialogBar::Create(CWnd *pParentWnd, UINT nIDTemplate, UINT nStyle, UINT nID)
{
// TODO: Add your specialized code here and/or call the base class
BOOL bRes=CDialogBar::Create(pParentWnd,nIDTemplate,nStyle,nID );
InitDialogBar();//在类中添加一个成员函数就可以了
return bRes;}//定义
BOOL CMyDialogBar::InitDialogBar()
{
UpdateData(FALSE);//
return TRUE;
}//在框架类Create函数中创建
if(!m_dialogbar.Create(this,IDD_DIALOG1,CBRS_RIGHT|CBRS_GRIPPER,IDD_DIALOG1))
{
TRACE0("Failed to create dialogbar\n");
return -1;
} m_dialogbar.SetWindowText("对话框工具栏");
我在对话框面板上添加了一个按钮,但显示是灰色的。
为什么?
我已经更新了界面了?
BOOL CMyDialogBar::Create(CWnd *pParentWnd, UINT nIDTemplate, UINT nStyle, UINT nID)
{
// TODO: Add your specialized code here and/or call the base class
BOOL bRes=CDialogBar::Create(pParentWnd,nIDTemplate,nStyle,nID );
InitDialogBar();//在类中添加一个成员函数就可以了
return bRes;}//定义
BOOL CMyDialogBar::InitDialogBar()
{
UpdateData(FALSE);//
return TRUE;
}//在框架类Create函数中创建
if(!m_dialogbar.Create(this,IDD_DIALOG1,CBRS_RIGHT|CBRS_GRIPPER,IDD_DIALOG1))
{
TRACE0("Failed to create dialogbar\n");
return -1;
} m_dialogbar.SetWindowText("对话框工具栏");
我在对话框面板上添加了一个按钮,但显示是灰色的。
为什么?
我已经更新了界面了?
BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
// TODO: Add your specialized code here and/or call the base class
if(m_dialogbar.OnCmdMsg(nID,nCode,pExtra,pHandlerInfo)){
return TRUE;
} return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}这样就可以了
ON_UPDATE_COMMAND_UI(IDC_BUTTON1,OnUpdateButton1)
END_MESSAGE_MAP()
void CLeftDlgBar::OnUpdateButton1(CCmdUI* pCmdUI)
{
pCmdUI->Enable(TRUE); //using pCmdUI->SetText you can set the button text too
}
add your handler code there.
?
在主函数中添加OnCmdMsg这个虚函数就可以了,具体写法如下:
BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
// TODO: Add your specialized code here and/or call the base class
if(m_dialogbar.OnCmdMsg(nID,nCode,pExtra,pHandlerInfo)){
return TRUE;
}return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}