在LISTCTRL中如何拖动多个ITEM!请指教!
我知道拖动一个的作法!
我知道拖动一个的作法!
解决方案 »
- vc有什么函数可以运行JavaScript没有?
- 如何实现双击一文本文件,不是打开而是删除它?
- 如何用c++实现线程
- 怎么知道我的VIDUAL STUDIO已经打上SP5的补丁
- 菜鸟问题,运行提示LIB文件打不开!如何办?
- 如何实现对一个网站上的文件自动下载更新?
- 如何将CSting类型的数据转换为double型的?
- 如何让VC 里可以使用ACCSEE 2000
- 我有视频会议系统/视频聊天系统,全国统一最低价每套4000元;
- 十万火急!高分送高手!如何在WIN32 application 中,调用ACTIVEX DLL
- 多語言支持程序的實現?
- 在LISTCTRL中如何拖动多个ITEM!请指教!
CImageList* ListView_CreateDragImageEx(HWND hWnd,
LPPOINT lpPoint)
{
CRect cSingleRect;
CRect cCompleteRect( 0,0,0,0 );
int nIdx = -1;
BOOL bFirst = TRUE;
// Determine the size of the drag image
for(;;)
{
nIdx = ListView_GetNextItem(hWnd, nIdx, LVIS_SELECTED);
if(nIdx == -1)
break;
ListView_GetItemRect(hWnd, nIdx, &cSingleRect, LVIR_BOUNDS);
if(bFirst)
{
// Initialize the CompleteRect
ListView_GetItemRect(hWnd, nIdx, &cCompleteRect, LVIR_BOUNDS);
bFirst = FALSE;
}
cCompleteRect.UnionRect(cCompleteRect, cSingleRect);
}
// Create bitmap in memory DC
CClientDC cDc(CWnd::FromHandle(hWnd));
CDC cMemDC;
CBitmap cBitmap;
if(!cMemDC.CreateCompatibleDC(&cDc))
return NULL;
if(!cBitmap.CreateCompatibleBitmap(&cDc, cCompleteRect.Width(), cCompleteRect.Height()))
return NULL;
CBitmap* pOldMemDCBitmap = cMemDC.SelectObject(&cBitmap);
// Here green is used as mask color
cMemDC.FillSolidRect(0, 0, cCompleteRect.Width(), cCompleteRect.Height(),
RGB(0, 255, 0));
// Paint each DragImage in the DC
CPoint cPt;
nIdx = -1;
for(;;)
{
nIdx = ListView_GetNextItem(hWnd, nIdx, LVIS_SELECTED);
if(nIdx == -1)
break;
ListView_GetItemRect(hWnd, nIdx, &cSingleRect, LVIR_BOUNDS);
HIMAGELIST hImageSingle = ListView_CreateDragImage(hWnd, nIdx, &cPt);
if(hImageSingle)
{
CImageList *pSingleImageList = CImageList::FromHandle(hImageSingle);
pSingleImageList->DrawIndirect( &cMemDC,
0,
CPoint(cSingleRect.left - cCompleteRect.left,
cSingleRect.top - cCompleteRect.top),
cSingleRect.Size(),
CPoint(0,0));
}
}
cMemDC.SelectObject(pOldMemDCBitmap);
// Create the imagelist with the merged drag images
CImageList* pCompleteImageList = new CImageList;
pCompleteImageList->Create( cCompleteRect.Width(),
cCompleteRect.Height(),
ILC_COLOR | ILC_MASK, 0, 1);
// Here green is used as mask color
pCompleteImageList->Add(&cBitmap, RGB(0, 255, 0));
cBitmap.DeleteObject(); // as an optional service:
// Find the offset of the current mouse cursor to the imagelist
// this we can use in BeginDrag() if(lpPoint)
{
CPoint cCursorPos;
GetCursorPos(&cCursorPos);
::ScreenToClient(hWnd, &cCursorPos);
lpPoint->x = cCursorPos.x - cCompleteRect.left;
lpPoint->y = cCursorPos.y - cCompleteRect.top;
}
return pCompleteImageList;
}