请问:在程序中,用什么方法可以使树控件某项被打开(同在运行时双击一样),谢谢

luckyker 2002-03-11 08:35:58
是资源管理器中的

左边点击树的文件夹项,右边显示其中的内容,若右边有子文件夹,双击它,应该可以把它打开,且左边的树中对应的项也呈打开的样子。

现在只可以在左边树中选择要打开的文件夹,其内容显示在右边。还不能双击右边的文件夹,请问:怎样可以双击文件夹并可以打开它,而且在左边树中的项也被打开?

多谢了,帮帮忙吧。
...全文
50 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
luckyker 2002-03-11
  • 打赏
  • 举报
回复
谢谢,真的可以打开呀!:)

不过,可能还有一些问题。
请你继续关注,多谢了!!
liu_feng_fly 2002-03-11
  • 打赏
  • 举报
回复
CTreeCtrl::Expand
BOOL Expand( HTREEITEM hItem, UINT nCode );

Return Value

Nonzero if successful; otherwise 0.

Parameters

hItem

Handle of the tree item being expanded.

nCode

A flag indicating the type of action to be taken. This flag can have one of the following values:

TVE_COLLAPSE Collapses the list.


TVE_COLLAPSERESET Collapses the list and removes the child items.


TVE_EXPAND Expands the list.


TVE_TOGGLE Collapses the list if it is currently expanded or expands it if it is currently collapsed.
Remarks

Call this function to expand or collapse the list of child items, if any, associated with the given parent item.

Example

// The pointer to my tree control.
extern CTreeCtrl* pmyTreeCtrl;
// The item that I want to ensure is visible.
extern HTREEITEM hmyItem;

// Expand the parent, if possible.
HTREEITEM hParent = pmyTreeCtrl->GetParentItem(hmyItem);
if (hParent != NULL)
pmyTreeCtrl->Expand(hParent, TVE_EXPAND);

// Ensure the item is visible.
pmyTreeCtrl->EnsureVisible(hmyItem);

试试这个函数
luckyker 2002-03-11
  • 打赏
  • 举报
回复
多谢了
我初学VC,连MSDN也不太会用

刚才找了几乎一下午,都没有找到你给的这个函数

其实也许你都不信,我就一直在看上半页,哪个函数也不行,
下半页不知道怎么就是没有看。以后,一定要仔细些。

不过,真的非常感谢,你帮了我大忙了。
liu_feng_fly 2002-03-11
  • 打赏
  • 举报
回复
不知道为什么,看上面我回的帖子被csdn弄的那么乱,在MSDN中查下面的函数
CTreeCtrl::Select BOOL Select( HTREEITEM hItem, UINT nCode );
liu_feng_fly 2002-03-11
  • 打赏
  • 举报
回复
CTreeCtrl::Select
BOOL Select( HTREEITEM hItem, UINT nCode );

Return Value

Nonzero if successful; otherwise 0.

Parameters

hItem

Handle of a tree item.

nCode

The type of action to take. This parameter can be one of the following values:

TVGN_CARET Sets the selection to the given item.


TVGN_DROPHILITE Redraws the given item in the style used to indicate the target of a drag-and-drop operation.


TVGN_FIRSTVISIBLE Scrolls the tree view vertically so that the given item is the first visible item.
Remarks

Call this function to select the given tree view item, scroll the item into view, or redraw the item in the style used to indicate the target of a drag-and-drop operation.

If nCode contains the value TVGN_CARET, the parent window receives the TVN_SELCHANGING and TVN_SELCHANGED notification messages. In addition, if the specified item is the child of a collapsed parent item, the parent’s list of child items is expanded to reveal the specified item. In this case, the parent window receives the TVN_ITEMEXPANDING and TVN_ITEMEXPANDED notification messages.

Example

// The pointer to my tree control.
extern CTreeCtrl* pmyTreeCtrl;
// The point to test.
extern CPoint myPoint;

// Select the item that is at the point myPoint.
UINT uFlags;
HTREEITEM hItem = pmyTreeCtrl->HitTest(myPoint, &uFlags);

if ((hItem != NULL) && (TVHT_ONITEM & uFlags))
{
pmyTreeCtrl->Select(hItem, TVGN_CARET);
}

多查查MSDN,你自己其实也可以找到答案的
luckyker 2002-03-11
  • 打赏
  • 举报
回复
可是有没有什么方法可以在程序中设置所选择的项呢?
请帮助,谢谢!!!

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧