天天看點

CTreeCtrl 右鍵剪切,粘貼

HTREEITEM COa2BusinessModel::CopyItem(HTREEITEM hItem, HTREEITEM htiNewParent, HTREEITEM htiAfter)    //拷貝節點

{

    TVINSERTSTRUCT tvstruct;

    //得到源條目的資訊

    tvstruct.item.hItem = hItem;

    tvstruct.item.mask = TVIF_CHILDREN|TVIF_HANDLE|TVIF_IMAGE|TVIF_SELECTEDIMAGE;

    GetItem(&tvstruct.item);

    CString sText = GetItemText(hItem);

    tvstruct.item.cchTextMax = sText.GetLength();

    tvstruct.item.pszText=sText.LockBuffer();

    //将條目插入到合适的位置

    tvstruct.hParent = htiNewParent;

    tvstruct.hInsertAfter = htiAfter;

    tvstruct.item.mask = TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_TEXT;

    HTREEITEM hNewItem = InsertItem(&tvstruct);

    //sText.ReleaseBuffer();

    sText.UnlockBuffer();

    //限制拷貝條目資料和條目狀态

    SetItemData(hNewItem, GetItemData(hItem));

    SetItemState(hNewItem, GetItemState(hItem, TVIS_STATEIMAGEMASK), TVIS_STATEIMAGEMASK);

    return hNewItem;

}

HTREEITEM COa2BusinessModel::CopyBranch(HTREEITEM htiBranch, HTREEITEM htiNewParent, HTREEITEM htiAfter)//拷貝分支

{

    HTREEITEM hChild;

    HTREEITEM hNewItem = CopyItem( htiBranch,htiNewParent,htiAfter );

    hChild = GetChildItem( htiBranch );

    while( hChild != NULL )

    {

        CopyBranch( hChild,hNewItem,htiAfter );

        hChild = GetNextSiblingItem( hChild );

    }

    return hNewItem;

}

繼續閱讀