---如何从CContolBar派生自己的CMyControlBar?
俺的CMyControlBar重载了三个函数:
CMyControlBar:Public CControlBar
{
...
//
BOOL Create( CWnd* pParentWnd, DWORD dwStyle, UINT nID );
BOOL CreateEx(CWnd* pParentWnd, DWORD dwCtrlStyle, DWORD dwStyle, UINT nID);
void OnUpdateCmdUI(CFrameWnd *wnd,int n);
...
}
CMyControlBar.cpp里面:
BOOL CMyControlBar::CreateEx(CWnd* pParentWnd, DWORD dwCtrlStyle, DWORD dwStyle, UINT nID)
{
ASSERT_VALID(pParentWnd);
m_dwStyle = (dwStyle & CBRS_ALL);
// translate MFC style bits to windows style bits
dwStyle &= ~CBRS_ALL;
dwStyle |= CCS_NOPARENTALIGN|CCS_NOMOVEY|CCS_NODIVIDER|CCS_NORESIZE;
if (pParentWnd->GetStyle() & WS_THICKFRAME)
dwStyle |= SBARS_SIZEGRIP;
dwStyle |= dwCtrlStyle;
CString str=AfxRegisterWndClass(CS_DBLCLKS,
NULL,(HBRUSH)(COLOR_3DFACE+1),NULL);
CRect rect;
rect.SetRectEmpty ();
return CWnd::Create(str, NULL, dwStyle, rect, pParentWnd, nID);
}
BOOL CMyControlBar::Create( CWnd* pParentWnd, DWORD dwStyle, UINT nID )
{
m_dwStyle = dwStyle;
return CreateEx (pParentWnd,0,m_dwStyle,nID);
}
然后,我在框架窗体中:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
......
//m_Bar是CMainFrame里面的一个成员:
//CMyControlBar m_Bar;
....
m_Bar.Create(this,WS_CHILD | WS_VISIBLE | CBRS_RIGHT
| CBRS_GRIPPER | CBRS_FLYBY | CBRS_SIZE_DYNAMIC,AFX_IDW_CONTROLBAR_LAST );
.....
}
预想的效果是Frame右边会出现一个MyControlBar,结果什么都没有:(