Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a derived class of CListCtrl and I must find the dimension of a cell. I tried to use GetItemRect but in this way, I have the dimension only of item and not of cell. How must I do it?

What I have tried:

I tried in this way:
C++
BOOL MyListCtrl::GetDimensionCell(INT_PTR &nRow, 
INT_PTR &nCol, RECT &cellRect, CPoint &point)
{
	INT_PTR		nC, nI, nSX, nDX, nDimX;
	LVCOLUMN	Column;
	RECT		rect;

	nRow = -1;
	nCol = -1;
	for (nI = 0; nI<GetItemCount(); nI++)
	{
		this->GetItemRect((int)nI, &rect, LVIR_LABEL);
		if ((rect.top <= point.y) && (rect.bottom >= point.y))	 
        // mi trovo in questo ITEM, trovo ora quale colonna.
		{
			nC = 0;
			nSX = 0;
			Column.mask = LVCF_WIDTH;
			while (GetColumn((int)nC, &Column))
			{
				nDimX = Column.cx;
				nDX = nSX + nDimX;	// dx e sx della cella.
				if ((point.x >= nSX) && (point.x <= nDX))
				{
					cellRect.top = (rect.top + rect.bottom) / 2 - 15;
					cellRect.bottom = (rect.top + rect.bottom) / 2 + 15;
					cellRect.left = (int)nSX;
					cellRect.right = (int)nDX;
					nRow = nI;
					nCol = nC;
					return TRUE;
				}
				nSX = nDX;
				nC++;
			}
		}
	}
	return FALSE;
}
Posted
Updated 2-Oct-23 2:45am
v2

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900