const CImageList* CDragDrogDialog::CreateDragImageEx(CListCtrl *pList, LPPOINT lpPoint)
{
//如果没有选择任何行
if (pList->GetSelectedCount() <= 0)
{
return NULL;
}
我选中多项, 进行拖动的时候. 只有鼠标拖动的那一个item有 效果.
如何构造拖动多个item拖动时候的cimagelist 实现类似资源管理器中拖动多项的效果
hyfang6673回复于24日22点18分 在BEGINDRAG是创建一个 CImageList,然后调用哪个BeginDrag就可以了,然后在拖动完毕是自己处理一下就可以了
CImageList* CAptFileZillaDlg::CreateDragImageEx(CListCtrl *pList, LPPOINT lpPoint)
{
if (pList->GetSelectedCount() <= 0)
return NULL; // no row selected
DWORD dwStyle = GetWindowLong(pList->m_hWnd, GWL_STYLE) & LVS_TYPEMASK;
CRect rectComplete(0, 0, 0, 0);
// Determine List Control Client width size
CRect rectClient;
pList->GetClientRect(rectClient);
int nWidth = rectClient.Width() + 50;
// Start and Stop index in view area
int nIndex = pList->GetTopIndex() - 1;
int nBottomIndex = pList->GetTopIndex() + pList->GetCountPerPage();
if (nBottomIndex > (pList->GetItemCount() - 1))
nBottomIndex = pList->GetItemCount() - 1;
// Determine the size of the drag image (limited for rows visibled and client width)
while ((nIndex = pList->GetNextItem(nIndex, LVNI_SELECTED)) != -1)
{
if (nIndex > nBottomIndex)
break;
CRect rectItem;
pList->GetItemRect(nIndex, rectItem, LVIR_BOUNDS);
if (rectItem.left < 0)
rectItem.left = 0;
if (rectItem.right > nWidth)
rectItem.right = nWidth;
rectComplete.UnionRect(rectComplete, rectItem);
}
// Create memory device context
CClientDC dcClient(this);
CDC dcMem;
CBitmap Bitmap;
if (!dcMem.CreateCompatibleDC(&dcClient))
return NULL;
if (!Bitmap.CreateCompatibleBitmap(&dcClient, rectComplete.Width(), rectComplete.Height()))
return NULL;
CBitmap *pOldMemDCBitmap = dcMem.SelectObject(&Bitmap);
// Use green as mask color
dcMem.FillSolidRect(0, 0, rectComplete.Width(), rectComplete.Height(), RGB(0,255,0));
// Don't use antialiased font for the dragimages
CFont *pFont = pList->GetFont();
LOGFONT lf;
pFont->GetLogFont(&lf);
lf.lfQuality = NONANTIALIASED_QUALITY;
CFont newFont;
newFont.CreateFontIndirect(&lf);
CFont *oldFont = dcMem.SelectObject(&newFont);
// Paint each DragImage in the DC
nIndex = pList->GetTopIndex() - 1;
while ((nIndex = pList->GetNextItem(nIndex, LVNI_SELECTED)) != -1)
{
if (nIndex > nBottomIndex)
break;
TCHAR buffer[1000];
LVITEM item = {0};
item.mask = LVIF_TEXT | LVIF_IMAGE;
item.iItem = nIndex;
item.pszText = buffer;
item.cchTextMax = 999;
pList->GetItem(&item);
// Draw the icon
CImageList* pSingleImageList = pList->GetImageList((dwStyle == LVS_ICON)?LVSIL_NORMAL:LVSIL_SMALL);
if (pSingleImageList)
{
CRect rectIcon;
pList->GetItemRect(nIndex, rectIcon, LVIR_ICON);
IMAGEINFO info;
pSingleImageList->GetImageInfo(item.iImage, &info);
CPoint p((rectIcon.left - rectComplete.left + rectIcon.right - rectComplete.left) / 2 - (info.rcImage.right - info.rcImage.left) / 2,
(rectIcon.top - rectComplete.top + rectIcon.bottom - rectComplete.top) / 2 - (info.rcImage.bottom - info.rcImage.top) / 2 + ((dwStyle == LVS_ICON)?2:0));
pSingleImageList->Draw( &dcMem, item.iImage,
p,
ILD_TRANSPARENT);
}
// Draw the text
CString text;
text = item.pszText;
CRect textRect;
pList->GetItemRect( nIndex, textRect, LVIR_LABEL );
textRect.top -= rectComplete.top - 2;
textRect.bottom -= rectComplete.top + 1;
textRect.left -= rectComplete.left - 2;
textRect.right -= rectComplete.left;
DWORD flags = DT_END_ELLIPSIS | DT_MODIFYSTRING;
if (dwStyle == LVS_ICON)
flags |= DT_CENTER | DT_WORDBREAK;
dcMem.DrawText(text, -1, textRect, flags);
}
dcMem.SelectObject(oldFont);
dcMem.SelectObject(pOldMemDCBitmap);
// Create drag image(list)
CImageList* pCompleteImageList = new CImageList;
pCompleteImageList->Create(rectComplete.Width(), rectComplete.Height(), ILC_COLOR32 | ILC_MASK, 0, 1);
pCompleteImageList->Add(&Bitmap, RGB(0, 255, 0)); // Green is used as mask color
Bitmap.DeleteObject();
if (lpPoint)
{
lpPoint->x = rectComplete.left;
lpPoint->y = rectComplete.top;
}
return pCompleteImageList;
}
| chenhua回复于24日22点30分 就是这个效果 ,,, |
| 南方-1996回复于24日22点44分 IDropSource IDropTarget 要继承这两个类来协助完成,详细的情况那么需要找相关的例子来完成。 |
(###)