Creating Drag Image for a CTreeCtrl without images

Wednesday Aug 4th 1999 by Pål K Tønder
Share:

Removes the image from treeview drag and drop operations

This article was contributed by Pål K Tønder.

The method CreateDragImage is used during drag'n drop to create a drag image. The problem is that it only works for a CTreeCtrl with images. The following method, CreateDragImageEx, checks whether the CTreeCtrl has a valid normal CImageList. If so, it just calls the standard CreateDragImage method and returns.

If, on the other hand, no valid CImageList is found, a bitmap is created based on the size of item rect, and the item text is drawn into it. Then a CImageList is created and the bitmap is added to it. " + t + "

"; } document.write(t); } else if (IS_TABLET!=1 && isSlideshow!=1) { var t=displayDFPTag("ic_imu"); if (t){ t = "
" + t + "
"; } document.write(t); } Sample Image

-->
CImageList* CTreeCtrlEx::CreateDragImageEx(HTREEITEM hItem){if(GetImageList(TVSIL_NORMAL) != NULL)return CreateDragImage(hItem);CRect rect;GetItemRect(hItem, rect, TRUE);rect.top = rect.left = 0;// Create bitmapCClientDCdc (this);CDC memDC;if(!memDC.CreateCompatibleDC(&dc))return NULL;CBitmap bitmap;if(!bitmap.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height()))return NULL;CBitmap* pOldMemDCBitmap = memDC.SelectObject( &bitmap );CFont* pOldFont = memDC.SelectObject(GetFont());memDC.FillSolidRect(&rect, RGB(0, 255, 0)); // Here green is used as mask colormemDC.SetTextColor(GetSysColor(COLOR_GRAYTEXT));memDC.TextOut(rect.left, rect.top, GetItemText(hItem));memDC.SelectObject( pOldFont );memDC.SelectObject( pOldMemDCBitmap );// Create imagelistCImageList* pImageList = new CImageList;pImageList->Create(rect.Width(), rect.Height(),  ILC_COLOR | ILC_MASK, 0, 1);pImageList->Add(&bitmap, RGB(0, 255, 0)); // Here green is used as mask colorreturn pImageList;}

History

Date Posted: August 4, 1999

Share:
Home
Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved