情况是这样的,将一个页面作为Tab控件的其中一页,为了代码不窝在一起,就没有在CreateControl函数中使用CDialogBuilder,而是直接new一个页面,在构造函数中使用CDialogBuilder,大致如下
CControlUI * CMainView::CreateControl(LPCTSTR pstrClass) {
if (0 == _tcscmp(pstrClass, _T("RealTimeInfoPage"))) {
return new CRealTimeInfoPage();
}
return NULL;
}
class CRealTimeInfoPage : public CContainerUI {
public:
CRealTimeInfoPage();
~CRealTimeInfoPage();
};
CRealTimeInfoPage::CRealTimeInfoPage() {
CDialogBuilder builder;
this->Add(builder.Create(_T("xml\RealTimeInfoPage.xml")));
}
就这么个搞法,以前也这么用,不过没用到滚动条,没发现这个问题。页面创建,显示都没有问题,滚动条死活不出来。
没办法,跟踪源码吧,跟到这里,原来m_pManager为NULL。。。当然略过了xml中配置的Default
void CContainerUI::EnableScrollBar(bool bEnableVertical, bool bEnableHorizontal) {
if( bEnableVertical && !m_pVerticalScrollBar ) {
m_pVerticalScrollBar = new CScrollBarUI;
m_pVerticalScrollBar->SetScrollRange(0);
m_pVerticalScrollBar->SetOwner(this);
m_pVerticalScrollBar->SetManager(m_pManager, NULL, false);
if ( m_pManager ) {
LPCTSTR pDefaultAttributes = m_pManager->GetDefaultAttributeList(_T("VScrollBar"));
if( pDefaultAttributes ) {
m_pVerticalScrollBar->SetAttributeList(pDefaultAttributes);
}
}
} else if( !bEnableVertical && m_pVerticalScrollBar ) {
m_pVerticalScrollBar->Delete();
m_pVerticalScrollBar = NULL;
}
if( bEnableHorizontal && !m_pHorizontalScrollBar ) {
m_pHorizontalScrollBar = new CScrollBarUI;
m_pHorizontalScrollBar->SetScrollRange(0);
m_pHorizontalScrollBar->SetHorizontal(true);
m_pHorizontalScrollBar->SetOwner(this);
m_pHorizontalScrollBar->SetManager(m_pManager, NULL, false);
if ( m_pManager ) {
LPCTSTR pDefaultAttributes = m_pManager->GetDefaultAttributeList(_T("HScrollBar"));
if( pDefaultAttributes ) {
m_pHorizontalScrollBar->SetAttributeList(pDefaultAttributes);
}
}
} else if( !bEnableHorizontal && m_pHorizontalScrollBar ) {
m_pHorizontalScrollBar->Delete();
m_pHorizontalScrollBar = NULL;
}
NeedUpdate();
}
得想办法把PaintManager传进来,找了下CPaintManagerUI看能不能找到获取paintmanager对象的方法,结果是不好用的
CPaintManagerUI* CPaintManagerUI::GetPaintManager(LPCTSTR pstrName) {
if( pstrName == NULL ) return NULL;
CString sName = pstrName;
if( sName.IsEmpty() ) return NULL;
for( int i = 0; i < m_aPreMessages.GetSize(); i++ ) {
CPaintManagerUI* pManager = static_cast<CPaintManagerUI*>(m_aPreMessages[i]);
if( pManager != NULL && sName == pManager->GetName() ) return pManager;
}
return NULL;
}
CDuiPtrArray* CPaintManagerUI::GetPaintManagers() {
return &m_aPreMessages;
}
有这么两个,明明CMainView继承自WindowImplBase,拥有成员变量m_PaintManager的Name为“”,却不能通过""获取,不说了,找到原因还是去改一下CRealTimeInfoPage的构造函数,把paintmanager传进来把,虽然很丑陋,但是能用啊!
CRealTimeInfoPage::CRealTimeInfoPage(CPaintManagerUI *pManager) {
CDialogBuilder builder;
this->Add(builder.Create(_T("xml\RealTimeInfoPage.xml"), NULL, NULL, pManager));
}
CControlUI * CMainView::CreateControl(LPCTSTR pstrClass) {
if (0 == _tcscmp(pstrClass, _T("RealTimeInfoPage"))) {
return new CRealTimeInfoPage(&m_PaintManager);
}
return NULL;
}
至此终于把滚动条显示出来了。