MFC中,重载CListCtrl类,响应其双击消息,函数为OnDblclk(NMHDR* pNMHDR, LRESULT* pResult),如何得知用户点击的是哪一行的哪一列呢?
解决方案 »
- 弱弱的问一下,现在学MFC意义大吗?
- missing storage-class or type specifiers,error C2653: 'std' : is not a class or namespace name
- pDC->TextOut(x,y,str)中的y值怎么越小越在下面输出?
- 关于ATL服务的调用?
- 郑重警告:手机通讯录忌用“老公”、“老婆”!!
- 传给进程内组件二进制数组数据除了用SafeArray的方法以为还有别的吗?
- 一个很弱的问题,请大家帮忙,多谢!!!
- VC2010中怎么调试自己写的DLL?大神们帮帮小弟啊.......
- vc++ 图像显示
- 如何显示网页的缩略图,就向在资源管理器中看到的那样
- !@@@什么是makefile?@@@
- 能解释一下这种现象吗,怪????
CListCtrl.HitTest(LVHITTESTINFO* pHitTestInfo)
LVHITTESTINFO
Has been extended to accommodate subitem hit-testing. The LVHITTESTINFO structure contains information about a hit test. It is used in association with the LVM_HITTEST and LVM_SUBITEMHITTEST messages and their related macros. This structure supersedes the LV_HITTESTINFO structure. typedef struct _LVHITTESTINFO {
POINT pt;
UINT flags;
int iItem;
int iSubItem;
} LVHITTESTINFO, FAR *LPLVHITTESTINFO;Members
pt
Position to hit test, in client coordinates.
flags
Variable that receives information about the results of a hit test. This member can be one or more of the following values: LVHT_ABOVE The position is above the control's client area.
LVHT_BELOW The position is below the control's client area.
LVHT_NOWHERE The position is inside the list view control's client window, but it is not over a list item.
LVHT_ONITEMICON The position is over a list view item's icon.
LVHT_ONITEMLABEL The position is over a list view item's text.
LVHT_ONITEMSTATEICON The position is over the state image of a list view item.
LVHT_TOLEFT The position is to the left of the list view control's client area.
LVHT_TORIGHT The position is to the right of the list view control's client area. You can use LVHT_ABOVE, LVHT_BELOW, LVHT_TOLEFT, and LVHT_TORIGHT to determine whether to scroll the contents of a list view control. Two of these values may be combined. For example, if the position is above and to the left of the client area, you could use both LVHT_ABOVE and LVHT_TOLEFT. You can test for LVHT_ONITEM to determine whether a specified position is over a list view item. This value is a bitwise-OR operation on LVHT_ONITEMICON, LVHT_ONITEMLABEL, and LVHT_ONITEMSTATEICON. iItem
Receives the index of the matching item. Or if hit-testing a subitem, this value represents the subitem's parent item.
iSubItem
Version 4.70. Receives the index of the matching subitem. When hit-testing an item, this member will be zero.
{
....
}列,可能你自己要处理
if (!EnsureVisible (Item, TRUE))
{
InsertItemEx (Item);
if (!EnsureVisible (Item, TRUE))
return NULL;
} // Make sure that nCol is valid
CHeaderCtrl* pHeader = (CHeaderCtrl*) GetDlgItem(0);
int nColumnCount = pHeader->GetItemCount();
if (Column >= nColumnCount || GetColumnWidth (Column) < 5)
return NULL; // Get the column offset
int Offset = 0;
for (int iColumn = 0; iColumn < Column; iColumn++)
Offset += GetColumnWidth (iColumn); CRect Rect;
GetItemRect (Item, &Rect, LVIR_BOUNDS); // Now scroll if we need to expose the column
CRect ClientRect;
GetClientRect (&ClientRect);
if (Offset + Rect.left < 0 || Offset + Rect.left > ClientRect.right)
{
CSize Size;
if (Offset + Rect.left > 0)
Size.cx = -(Offset - Rect.left);
else
Size.cx = Offset - Rect.left;
Size.cy = 0;
Scroll (Size);
Rect.left -= Size.cx;
}
{
HD_NOTIFY *phdn = (HD_NOTIFY*)pNMHDR;
phdn->iButton就是当前双击的列的编号,0为第一列
*pResult = 0;
}
//get the row number
int nItem = temp->iItem;
//get the column number
int nSubItem = temp->iSubItem;
m_ListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT |LVS_EX_FLATSB |LVS_EX_GRIDLINES );
//用下面的函数可以得到点击的列
int
gxListCtrl::HitTestEx (CPoint& Point, int* pColumn)//返回所点击的列数
{
int ColumnNum = 0;
int Row = HitTest (Point, NULL);
if (pColumn)
*pColumn = 0; // Make sure that the ListView is in LVS_REPORT
if ((GetWindowLong (m_hWnd, GWL_STYLE) & LVS_TYPEMASK) != LVS_REPORT)
return Row; // Get the top and bottom row visible
Row = GetTopIndex();
int Bottom = Row + GetCountPerPage();//得到总页数
if (Bottom > GetItemCount())
Bottom = GetItemCount();//得到总行数
// Get the number of columns
CHeaderCtrl* pHeader = (CHeaderCtrl*) GetDlgItem(0);
int nColumnCount = pHeader->GetItemCount();//得到总列数
// Loop through the visible rows
for(; Row <= Bottom; Row++)
{
// Get bounding rect of item and check whether point falls in it.
CRect Rect;
GetItemRect (Row, &Rect, LVIR_BOUNDS);//得到第一个框的区域
if (Rect.PtInRect (Point))
{
// Now find the column
for (ColumnNum = 0; ColumnNum < nColumnCount; ColumnNum++)
{
int ColWidth = GetColumnWidth (ColumnNum);
if (Point.x >= Rect.left && Point.x <= (Rect.left + ColWidth))
{
if (pColumn)
*pColumn = ColumnNum;
return Row;
}
Rect.left += ColWidth;
}
}
}
return -1;
}
只是 flyelf(空谷清音)老兄的代码虽可运行(win2000)但MSDN说需winCE.