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
tcf22Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
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
AndyAinscowFreelance programmer / ConsultantCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.