如何在listctrl中多项拖动时显示图标

onlynight 2002-10-22 10:33:59
在listctrl中多选 然后拖动
请问如何使光标能显示所有选项
并且在不可放开鼠标时 光标上有所提示
如资源管理器一样
谢谢!
...全文
109 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yoyo2002 2002-10-25
  • 打赏
  • 举报
回复
CImageList* CSelectionDlg::CreateDragImageEx(CListCtrl *pList, LPPOINT lpPoint)
{
if (pList->GetSelectedCount() <= 0)
return NULL; // no row selected

CRect rectSingle;
CRect rectComplete(0,0,0,0);

// Determine List Control Client width size
pList->GetClientRect(rectSingle);
int nWidth = rectSingle.Width();

// Start and Stop index in view area
int nIndex = pList->GetTopIndex() - 1;
int nBottomIndex = pList->GetTopIndex() + pList->GetCountPerPage() - 1;
if (nBottomIndex > (pList->GetItemCount() - 1))
nBottomIndex = pList->GetItemCount() - 1;

// Determine the size of the drag image (limite for rows visibled and Client width)
while ((nIndex = pList->GetNextItem(nIndex, LVNI_SELECTED)) != -1)
{
if (nIndex > nBottomIndex)
break;

pList->GetItemRect(nIndex, rectSingle, LVIR_BOUNDS);

if (rectSingle.left < 0)
rectSingle.left = 0;

if (rectSingle.right > nWidth)
rectSingle.right = nWidth;

rectComplete.UnionRect(rectComplete, rectSingle);
}

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));

// Paint each DragImage in the DC
nIndex = pList->GetTopIndex() - 1;
while ((nIndex = pList->GetNextItem(nIndex, LVNI_SELECTED)) != -1)
{
if (nIndex > nBottomIndex)
break;

CPoint pt;
CImageList* pSingleImageList = pList->CreateDragImage(nIndex, &pt);

if (pSingleImageList)
{
pList->GetItemRect(nIndex, rectSingle, LVIR_BOUNDS);
pSingleImageList->Draw( &dcMem,
0,
CPoint(rectSingle.left - rectComplete.left,
rectSingle.top - rectComplete.top),
ILD_MASK);
pSingleImageList->DeleteImageList();
delete pSingleImageList;
}
}

dcMem.SelectObject(pOldMemDCBitmap);
CImageList* pCompleteImageList = new CImageList;
pCompleteImageList->Create(rectComplete.Width(), rectComplete.Height(), ILC_COLOR | 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;
}
onlynight 2002-10-24
  • 打赏
  • 举报
回复
自己up
nevergrief 2002-10-23
  • 打赏
  • 举报
回复
其中IDC_CURSOR1到9都是你从资源里倒入到.cur文件的资源名称。
nevergrief 2002-10-23
  • 打赏
  • 举报
回复
自己更改鼠标cur啊!!!

//例8 更换鼠标形状
class CMyCursorView : public CView
{
public:
HCURSOR CUR; // 创建光标
protected:
void LoadCursorID(UINT Cur);
UINT CurName;
void CapPoint(CPoint MousePos);
}
void CMyCursorView::LoadCursorID(UINT Cur)
{
CurName=Cur;
}
void CMyCursorView::CapPoint(CPoint MousePos)
{
CRect r;
GetClientRect(&r);
int Width,Height;
Width=MousePos.x/(r.right/3);
Height=MousePos.y/(r.bottom/3);
switch(Width)
{
case 0:
switch(Height)
{
case 0:LoadCursorID(IDC_CURSOR1);break;
case 1:LoadCursorID(IDC_CURSOR2);break;
case 2:LoadCursorID(IDC_CURSOR3);break;
}break;
case 1:
switch(Height)
{
case 0:LoadCursorID(IDC_CURSOR4);break;
case 1:LoadCursorID(IDC_CURSOR5);break;
case 2:LoadCursorID(IDC_CURSOR6);break;
}break;
case 2:
switch(Height)
{
case 0:LoadCursorID(IDC_CURSOR7);break;
case 1:LoadCursorID(IDC_CURSOR8);break;
case 2:LoadCursorID(IDC_CURSOR9);break;
}break;
}
CUR=AfxGetApp()->LoadCursor(CurName);
Invalidate(); // 刷新窗口
}
void CMyCursorView::OnMouseMove(UINT nFlags, CPoint point)
{
CapPoint(point);
::SetCursor(CUR);
Invalidate();
CView::OnMouseMove(nFlags, point);
}
onlynight 2002-10-23
  • 打赏
  • 举报
回复
可能是我没有说清楚 楼上的朋友误解了
我是要在光标下面显示当前所选中进行drag的所有选项

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧