有两个问题:1:使用CTreeCtrl函数的时候,Create不是必须的?
MSDN里有这样一句话:“If you specify the tree control in a dialog box template, or if you are using CTreeView, your tree control is created automatically when the dialog box or view is created. If you want to create the tree control as a child window of some other window, use the Create member function.”我现在是把一个CTreeCtrl控件放到一个dialog里面使用的。这个dialog算是一个“dialog box template”吗?我发现如果不使用create函数,而直接用InsertItem是可以的。
HTREEITEM root1 = m_treeids.InsertItem("Dialog1",TVI_ROOT,TVI_LAST);
HTREEITEM root2 = m_treeids.InsertItem("Dialog1",TVI_ROOT,TVI_LAST);
HTREEITEM subnode0 = m_treeids.InsertItem("Pittsburgh",root1,TVI_LAST);
HTREEITEM subnode1 = m_treeids.InsertItem("hello3",root1,TVI_LAST);
m_treeids.Expand(root1,TVE_EXPAND);
2: 如果我这样使用Create函数,编译没问题,运行就报错。请问我错在什么地方?
         m_treeids.Create((WS_VISIBLE|TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS),CRect(0,0,200,200),this,10000);  
我想用Create函数是因为我想让父项和子项之间有线相连,这样好看些。就是说想要TVS_HASLINES功能。谢谢!

解决方案 »

  1.   

    你引的文章里面说的很清楚了,你放在Dialog上的,因为已经自动的Create了,所以就不能再create了。
    你要想改变style,可以用
    BOOL ModifyStyle(
       DWORD dwRemove,
       DWORD dwAdd,
       UINT nFlags = 0 
    );
      

  2.   

    谢谢 Wjkgz. 我发现ModifyStyle这样更改整个dialog的style啊,好像没办法修改这个
    CTreeCtrl控件的style. 我是这么用的,结果控件本身毫无变化。ModifyStyle(NULL, TVS_HASBUTTONS | TVS_LINESATROOT | TVS_HASLINES | TVS_DISABLEDRAGDROP,0);
      

  3.   

    打错了。我发现ModifyStyle只能更改整个dialog的style啊,好像没办法修改这个CTreeCtrl控件的style.
      

  4.   

    你直接调用的ModifyStyle,那当然是Dialog的了,
    你应该调用TreeCtrl的。
      

  5.   

    搞定。谢谢大侠。我是新手,开帖的时候忘记给分了,现在似乎无法加分,提示不到5天。sorry,结贴了。