ProgJ 2016-02-14 03:52 采纳率: 50%
浏览 1343
已结题

MFC 做的CTreeView根项不能打开的问题

相关代码如下:
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
if (!m_wndSplitter.CreateStatic(this, 1, 2))
{
return FALSE;
}
CRect rect;
GetClientRect(&rect);

m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(TreeView), CSize(rect.Width() / 3 - 170, rect.Height()), pContext);

if (!m_wndSplitter2.CreateStatic(&m_wndSplitter, 1, 2, WS_CHILD | WS_VISIBLE, m_wndSplitter.IdFromRowCol(0, 1))
    || !m_wndSplitter2.CreateView(0, 0, RUNTIME_CLASS(EditView), CSize(rect.Width() / 3 - 50, rect.Height()), pContext)
    || !m_wndSplitter2.CreateView(0, 1, RUNTIME_CLASS(EditView), CSize(rect.Width() / 3, rect.Height()), pContext))
{
    return FALSE;
}
return TRUE;
//return CFrameWnd::OnCreateClient(lpcs, pContext);

}

void TreeView::OnInitialUpdate()
{
CTreeView::OnInitialUpdate();

ptheTree = &GetTreeCtrl();
ptheTree->ModifyStyle(0, TVS_HASLINES | TVS_EDITLABELS | TVS_HASBUTTONS | TVS_EDITLABELS | TVS_LINESATROOT);
TVINSERTSTRUCT tvInsert;
HTREEITEM hTreeItem;
tvInsert.hInsertAfter = TVI_LAST;//TVI_LAST;
tvInsert.hParent = TVI_ROOT;
tvInsert.item.mask = TVIF_TEXT;
tvInsert.item.pszText = "搜索引擎";
hTreeItem = ptheTree->InsertItem(&tvInsert);
tvInsert.hParent = hTreeItem;
tvInsert.item.pszText = "Google";
ptheTree->InsertItem(&tvInsert);
tvInsert.item.pszText = "Baidu";
ptheTree->InsertItem(&tvInsert);
ptheTree->Expand(hTreeItem, TVE_EXPAND); //默认为合上的TVE_COLLAPSE,打开的TVE_EXPAND

}

做出来后效果这样图片说明

但是当我点根项时并没有展开(况且我类型设置了TVE_EXPAND,应该直接是打开的啊。。),而且单击根项应该选中高亮的也没有(实际效果是高亮一下后立刻恢复了,就跟刷新了似得)。

大家帮我看看问题可能出在哪。。

  • 写回答

2条回答

  • threenewbee 2016-02-14 22:04
    关注

    ptheTree->Expand.Expand(hTreeItem, TVE_TOGGLE);
    试试看这样

    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能