VC 界面控件开发问题,老大门!!
   VC中CTreeCtrl控件的SetItemData函数,怎么样才能把,cstring类型的值设置进去
不知道怎么转换
   谢谢!!!

解决方案 »

  1.   

    要将字符串设置到ItemData中,就需要将指针设置进去,而不是简单的转换就可以的。因此要分配内存,将字符串拷贝到内存,然后调用SetItemData设置指针。
      

  2.   

    extern CTreeCtrl* pmyTreeCtrl;
    CString   str;
    HTREEITEM hItem;// Insert 20 items into the tree control making the data of every item
    // be the handle of the item.
    for (int i=0;i < 20;i++)
    {
      str.Format(TEXT("item %d"), i);
      hItem = pmyTreeCtrl->InsertItem(str);  if (hItem != NULL)
      {
        pmyTreeCtrl->SetItemData(hItem, (DWORD) hItem);
      }
    }MSDN上的例子,不知道是不是你想要的
      

  3.   

    存入指针,指向 CString 对象。
    CString str("Hello World!");DWORD dwData = (DWORD)&str;  // 取出地址SetItemData( dwData ); // 存入地址MessageBox( *((CString*)dwData) );
      

  4.   

    楼主应该试试2楼的说法,那个MSDN上面说的应该没有问题
      

  5.   

    setitemdata要设置指针,所以指向的地址不能被释放,不能是局部变量