• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1169
  • Last Modified:

CreateDragImage is returning NULL

I have a control that inherites from CTreeCtrl.

I've setup a message handler like so:
ON_NOTIFY_REFLECT(TVN_BEGINDRAG, OnBeginDrag)

Declare my members
CImageList*      m_pDragImage;
BOOL               m_bLDragging;
HTREEITEM      m_hitemDrag,m_hitemDrop;


My handler gets the item being dragged (which appears to be valid because itemText is correct), then calls CreateDragImage() on the item and m_pDragImage is set to NULL.

//Handler
void CAgUiImagesTree::OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult)
{
        NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
       *pResult = 0;

        m_hitemDrag = pNMTreeView->itemNew.hItem;
        m_hitemDrop = NULL;

        CString itemText = GetItemText(m_hitemDrag);
        m_pDragImage = CreateDragImage(m_hitemDrag);  // get the image list for dragging

        if( !m_pDragImage )
                return;

        m_bLDragging = TRUE;
        ....
}

Is there something else I need to do in order to get a Drag Image for a Tree Item?

UPDATE:
This how the control is in the resource file, in case one of the options is having an effect

CONTROL      "Tree1",IDC_EX_RCP_RASTER_LIST,"SysTreeView32",
                    TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT |
                    TVS_EDITLABELS | TVS_SHOWSELALWAYS | TVS_CHECKBOXES |
                    WS_BORDER | WS_TABSTOP,10,15,140,135
0
tcf22
Asked:
tcf22
  • 2
1 Solution
 
AndyAinscowCommented:
Have you created images for the tree AND set the images when you add items to the tree?
0
 
tcf22Author Commented:
No...I was under the impression that a image was generated from the text of the entry. How would I do this?
0
 
AndyAinscowCommented:
Unless you supply images then there aren't any images with the item.

Example

// The pointer to my tree control.
extern CTreeCtrl* pmyTreeCtrl;
// The new image list of the tree control.
extern CImageList* pmyImageList;

ASSERT(pmyTreeCtrl->GetImageList(TVSIL_NORMAL) == NULL);

pmyTreeCtrl->SetImageList(pmyImageList, TVSIL_NORMAL);
ASSERT(pmyTreeCtrl->GetImageList(TVSIL_NORMAL) == pmyImageList);




and
Example

// The pointer to my image list.
extern CImageList* pmyImageList;

// Add my icons.
pmyImageList->Add(AfxGetApp()->LoadIcon(IDI_ICON1));
pmyImageList->Add(AfxGetApp()->LoadIcon(IDI_ICON2));

// Add my bitmap, make all black pixels transparent.
CBitmap bm;
bm.LoadBitmap(IDB_BITMAP1);
pmyImageList->Add(&bm, RGB(0, 0, 0));




and
CTreeCtrl::InsertItem
HTREEITEM InsertItem( LPTVINSERTSTRUCT lpInsertStruct );

HTREEITEM InsertItem(UINT nMask, LPCTSTR lpszItem, int nImage, int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam, HTREEITEM hParent, HTREEITEM hInsertAfter );

HTREEITEM InsertItem( LPCTSTR lpszItem, HTREEITEM hParent = TVI_ROOT, HTREEITEM hInsertAfter = TVI_LAST );

HTREEITEM InsertItem( LPCTSTR lpszItem, int nImage, int nSelectedImage, HTREEITEM hParent = TVI_ROOT, HTREEITEM hInsertAfter = TVI_LAST);

Return Value

Handle of the new item if successful; otherwise NULL.

Parameters

lpInsertStruct

A pointer to aTVINSERTSTRUCT that specifies the attributes of the tree view item to be inserted.

nMask

Integer specifying which attributes to set. See theTVITEM structure in the Platform SDK.

lpszItem

Address of a string containing the item’s text.

nImage

Index of the item’s image in the tree view control’s image list.

nSelectedImage

Index of the item’s selected image in the tree view control’s image list.


0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now