[英]MFC: Adding CListView tab to a CTabView (CBCGPTabView) on request doesn't call CMyListView::OnInitialUpdate()
I have a CMyTabView
derived from CBCGPTabView
( CTabView
) that I want to add tabs to on the fly.我有一个从
CMyTabView
( CTabView
) 派生的CBCGPTabView
,我想动态添加选项卡。 The tab being added will be a CMyListView
derived from CListView
.添加的选项卡将是从
CListView
派生的CMyListView
。 If I add the tab during CMyTabView::OnCreate()
it works fine.如果我在
CMyTabView::OnCreate()
期间添加选项卡,它工作正常。 If I try to do it via a custom message, it adds the tab, but it's blank ( CMyListView::OnInitialUpdate()
is never called).如果我尝试通过自定义消息执行此操作,它会添加选项卡,但它是空白的(
CMyListView::OnInitialUpdate()
永远不会被调用)。
What do I need to do for it to work?我需要做什么才能让它工作?
Here's what works (the test tab):这是有效的(测试选项卡):
int CMyTabView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (__super::OnCreate(lpCreateStruct) == -1)
return -1;
CBCGPTabWnd &tabctrl=GetTabControl();
int index=AddView(RUNTIME_CLASS(CMyForm), _T("My Form"));
if (index!=-1) {
m_IDTabMyForm=tabctrl.GetTabID(index);
}
AddView(RUNTIME_CLASS(CMyListView), _T("Test"));
tabctrl.HideNoTabs();
return 0;
}
This doesn't (other than adding the tab with a blank window).这不会(除了添加带有空白窗口的选项卡)。
afx_msg LRESULT CMyTabView::OnUwmAddMyListViewTab(WPARAM wparam, LPARAM lparam)
{
CString mytabname;
mytabname=_T("My ListView");
// check if tab already exists - if so select it
CBCGPTabWnd &tabcontrol=GetTabControl();
for (int i=0; i<tabcontrol.GetTabsNum(); i++) {
CString tablabel;
if (tabcontrol.GetTabLabel(i, tablabel)) {
if (tablabel==mytabname) {
tabcontrol.SetActiveTab(i);
return 0;
}
}
}
// new tab so add it
int index=AddView(RUNTIME_CLASS(CMyListView), mytabname);
if (index!=-1) {
tabcontrol.SetActiveTab(index);
}
return 0;
}
It turns out you have to call it yourself, version below works:事实证明,您必须自己调用它,以下版本有效:
afx_msg LRESULT CMyTabView::OnUwmAddMyListViewTab(WPARAM wparam, LPARAM lparam)
{
CString mytabname;
mytabname=_T("My ListView");
// check if tab already exists - if so select it
CBCGPTabWnd &tabcontrol=GetTabControl();
for (int i=0; i<tabcontrol.GetTabsNum(); i++) {
CString tablabel;
if (tabcontrol.GetTabLabel(i, tablabel)) {
if (tablabel==mytabname) {
tabcontrol.SetActiveTab(i);
return 0;
}
}
}
// new tab so add it
int index=AddView(RUNTIME_CLASS(CMyListView), mytabname);
if (index!=-1) {
CView* thetabview=GetView(index);
if (thetabview) {
// we need to call OnInitUpdate ourself
thetabview->SendMessage(WM_INITIALUPDATE);
//make sure any child windows of the view get the message too
thetabview->SendMessageToDescendants(WM_INITIALUPDATE, 0, 0, TRUE, TRUE);
}
tabcontrol.SetActiveTab(index);
}
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.