Click here to Skip to main content
16,016,489 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
The problem is the scroll, I created a derived class of CListCtrl,

void CListBut::CalculateCellRect(int iColumnIndex, int iRowIndex, CRect& robCellRect)
{
	GetItemRect(iRowIndex, &robCellRect, LVIR_BOUNDS);

	CRect rcClient;
	GetClientRect(&rcClient);

	if (robCellRect.right > rcClient.right)
	{
		robCellRect.right = rcClient.right;
	}

	ScrollToView(iColumnIndex, iRowIndex, robCellRect);

	INT_PTR			nRow, nCol;
	//BOOL			bRes;
	RECT			cellRect;

	CArray<double, double> a_Rdim;
	CArray<double, double> a_RdimApp;

	
	CButton * but = new CButton;

	but->Create(_T(""), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, robCellRect, this, 1);
}


<pre>
void CListBut::ScrollToView(int iColumnIndex, int iRowIndex, CRect& robCellRect)
{
	// Now scroll if we need to expose the column
	CRect rcClient;
	GetClientRect(&rcClient);

	int iColumnWidth = GetColumnWidth(iColumnIndex);

	int iOffSet = 0;
	int iOffSet1 = 0;

	for (int iIndex_ = 0; iIndex_ < iColumnIndex; iIndex_++)
	{
		iOffSet += GetColumnWidth(iIndex_);
	}

/*	for (int iIndex_1 = 0; iIndex_1 < iRowIndex; iIndex_1++)
	{
		iOffSet1 += GetColumnWidth(iIndex_1);
	}
*/

	CSize obScrollSize(0, 0);

	if (((iOffSet + robCellRect.left) < rcClient.left) ||
		((iOffSet + robCellRect.left) > rcClient.right))
	{
		obScrollSize.cx = iOffSet + robCellRect.left;
	}
	else if ((iOffSet + robCellRect.left + iColumnWidth) > rcClient.right)
	{
		obScrollSize.cx = iOffSet + robCellRect.left + iColumnWidth - rcClient.right;
	}


/*	if (((iOffSet1 + robCellRect.top) < rcClient.top) ||
		((iOffSet1 + robCellRect.top) > rcClient.bottom))
	{
		obScrollSize.cy = iOffSet + robCellRect.top;
	}
	else if ((iOffSet1 + robCellRect.top + iRowWidth) > rcClient.bottom)
	{
		obScrollSize.cy = iOffSet1 + robCellRect.top + iColumnWidth - rcClient.bottom;
	}

	*/
	//Scroll(obScrollSize);
	robCellRect.left -= obScrollSize.cx;

	// Set the width to the column width
	robCellRect.left += iOffSet;
	robCellRect.right = robCellRect.left + iColumnWidth;


}


What I have tried:

I tried code that I wrote..When I scroll button's position changes..
Posted
Updated 18-Jul-22 4:00am
v2

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