listcontrol控件

归途醉染 2019-05-11 06:53:05
MFC 我想在一个 listcontrol控件中一行 嵌入button控件和combobox 一起使用
请问有什么解决办法 谢谢了
要是提供demo 就更加好了!!!
...全文
195 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
归途醉染 2019-05-12
  • 打赏
  • 举报
回复
引用 2 楼 schlafenhamster 的回复:

void CListCtrlEx::createItemButton( int nItem, int nSubItem, HWND hMain )
{
	CRect rect;
	int offset = 0;

	// Make sure that the item is visible
	if( !EnsureVisible(nItem, TRUE)) return ;

	GetSubItemRect(nItem, nSubItem, LVIR_BOUNDS, rect);
	
// Now scroll if we need to expose the column
	CRect rcClient;
	GetClientRect(rcClient);
	if( offset + rect.left < 0 || offset + rect.left > rcClient.right )
	{
		CSize size;
		size.cx = offset + rect.left;
		size.cy = 0;
		Scroll(size);
		rect.left -= size.cx;
	}

	rect.left += offset;	
	rect.right = rect.left + GetColumnWidth(nSubItem);
	if(rect.right > rcClient.right) 
		rect.right = rcClient.right;
	//basic code end

	rect.bottom = rect.top + rect.Height();

	int iPageCout = GetCountPerPage();
	if ( nItem >= iPageCout )
	{
		rect.top += rect.Height();
		rect.bottom += rect.Height();
	}

	DWORD dwStyle =  WS_CHILD | WS_VISIBLE;
	CButtonEx *pButton = new CButtonEx(nItem,nSubItem,rect,hMain);
	m_uID++;
	CString cap;
	cap.Format("%d",nItem);
	afxDump << cap << "\n";// "0"
	pButton->Create(cap,dwStyle, rect, this, m_uID);
	m_mButton.insert( make_pair( nItem, pButton ) );

	int iTopIndex = GetTopIndex();
	if ( iTopIndex > 0 )
	{
		updateListCtrlButtonPos();
	}
	
	return;
}

void CListCtrlEx::updateListCtrlButtonPos()
{
	int iTopIndex = GetTopIndex();
	int nItem = iTopIndex;
	btMap::iterator iter;
	btMap::iterator iterUp;
	int iLine = 0;
#ifdef USE_TOPINDEX_BUTTON
	iter = m_mButton.find( iTopIndex );
	iterUp = m_mButton.begin();
	while ( iter != m_mButton.end() )
	{
		iterUp->second->EnableWindow( iter->second->bEnable );
		iter ++;
		iterUp++;
	}
#else
	for ( ; nItem < GetItemCount(); nItem++ )
	{
		iter = m_mButton.find(nItem);
		if( iter!= m_mButton.end() )
		{
			CRect rect;
			iterUp = m_mButton.find(iLine);
			rect = iterUp->second->m_rect;
			iter->second->MoveWindow( &rect );
			iter->second->ShowWindow( SW_SHOW );
			if( iLine < iTopIndex )
			{
				iterUp->second->ShowWindow( SW_HIDE );
			}
			iLine++;
		}
	}
#endif

}
// "Insert New Item"
void CListCtrlButtonDlg::OnButton1()
{
	int iLine = m_list.GetItemCount();
	CString szItemText;
	szItemText.Format( _T("Name%02d"),iLine );
	m_list.InsertItem( iLine, szItemText );

	szItemText.Format(_T("%d"),(iLine+1)*2 );
	m_list.SetItemText( iLine, 1,szItemText );

	m_list.createItemButton( iLine, 2, this->GetSafeHwnd());
}

我已知道了 你不要发完整的了 多谢
归途醉染 2019-05-12
  • 打赏
  • 举报
回复
引用 2 楼 schlafenhamster 的回复:

void CListCtrlEx::createItemButton( int nItem, int nSubItem, HWND hMain )
{
	CRect rect;
	int offset = 0;

	// Make sure that the item is visible
	if( !EnsureVisible(nItem, TRUE)) return ;

	GetSubItemRect(nItem, nSubItem, LVIR_BOUNDS, rect);
	
// Now scroll if we need to expose the column
	CRect rcClient;
	GetClientRect(rcClient);
	if( offset + rect.left < 0 || offset + rect.left > rcClient.right )
	{
		CSize size;
		size.cx = offset + rect.left;
		size.cy = 0;
		Scroll(size);
		rect.left -= size.cx;
	}

	rect.left += offset;	
	rect.right = rect.left + GetColumnWidth(nSubItem);
	if(rect.right > rcClient.right) 
		rect.right = rcClient.right;
	//basic code end

	rect.bottom = rect.top + rect.Height();

	int iPageCout = GetCountPerPage();
	if ( nItem >= iPageCout )
	{
		rect.top += rect.Height();
		rect.bottom += rect.Height();
	}

	DWORD dwStyle =  WS_CHILD | WS_VISIBLE;
	CButtonEx *pButton = new CButtonEx(nItem,nSubItem,rect,hMain);
	m_uID++;
	CString cap;
	cap.Format("%d",nItem);
	afxDump << cap << "\n";// "0"
	pButton->Create(cap,dwStyle, rect, this, m_uID);
	m_mButton.insert( make_pair( nItem, pButton ) );

	int iTopIndex = GetTopIndex();
	if ( iTopIndex > 0 )
	{
		updateListCtrlButtonPos();
	}
	
	return;
}

void CListCtrlEx::updateListCtrlButtonPos()
{
	int iTopIndex = GetTopIndex();
	int nItem = iTopIndex;
	btMap::iterator iter;
	btMap::iterator iterUp;
	int iLine = 0;
#ifdef USE_TOPINDEX_BUTTON
	iter = m_mButton.find( iTopIndex );
	iterUp = m_mButton.begin();
	while ( iter != m_mButton.end() )
	{
		iterUp->second->EnableWindow( iter->second->bEnable );
		iter ++;
		iterUp++;
	}
#else
	for ( ; nItem < GetItemCount(); nItem++ )
	{
		iter = m_mButton.find(nItem);
		if( iter!= m_mButton.end() )
		{
			CRect rect;
			iterUp = m_mButton.find(iLine);
			rect = iterUp->second->m_rect;
			iter->second->MoveWindow( &rect );
			iter->second->ShowWindow( SW_SHOW );
			if( iLine < iTopIndex )
			{
				iterUp->second->ShowWindow( SW_HIDE );
			}
			iLine++;
		}
	}
#endif

}
// "Insert New Item"
void CListCtrlButtonDlg::OnButton1()
{
	int iLine = m_list.GetItemCount();
	CString szItemText;
	szItemText.Format( _T("Name%02d"),iLine );
	m_list.InsertItem( iLine, szItemText );

	szItemText.Format(_T("%d"),(iLine+1)*2 );
	m_list.SetItemText( iLine, 1,szItemText );

	m_list.createItemButton( iLine, 2, this->GetSafeHwnd());
}

可以给一个完整的吗?
schlafenhamster 2019-05-12
  • 打赏
  • 举报
回复

void CListCtrlEx::createItemButton( int nItem, int nSubItem, HWND hMain )
{
CRect rect;
int offset = 0;

// Make sure that the item is visible
if( !EnsureVisible(nItem, TRUE)) return ;

GetSubItemRect(nItem, nSubItem, LVIR_BOUNDS, rect);

// Now scroll if we need to expose the column
CRect rcClient;
GetClientRect(rcClient);
if( offset + rect.left < 0 || offset + rect.left > rcClient.right )
{
CSize size;
size.cx = offset + rect.left;
size.cy = 0;
Scroll(size);
rect.left -= size.cx;
}

rect.left += offset;
rect.right = rect.left + GetColumnWidth(nSubItem);
if(rect.right > rcClient.right)
rect.right = rcClient.right;
//basic code end

rect.bottom = rect.top + rect.Height();

int iPageCout = GetCountPerPage();
if ( nItem >= iPageCout )
{
rect.top += rect.Height();
rect.bottom += rect.Height();
}

DWORD dwStyle = WS_CHILD | WS_VISIBLE;
CButtonEx *pButton = new CButtonEx(nItem,nSubItem,rect,hMain);
m_uID++;
CString cap;
cap.Format("%d",nItem);
afxDump << cap << "\n";// "0"
pButton->Create(cap,dwStyle, rect, this, m_uID);
m_mButton.insert( make_pair( nItem, pButton ) );

int iTopIndex = GetTopIndex();
if ( iTopIndex > 0 )
{
updateListCtrlButtonPos();
}

return;
}

void CListCtrlEx::updateListCtrlButtonPos()
{
int iTopIndex = GetTopIndex();
int nItem = iTopIndex;
btMap::iterator iter;
btMap::iterator iterUp;
int iLine = 0;
#ifdef USE_TOPINDEX_BUTTON
iter = m_mButton.find( iTopIndex );
iterUp = m_mButton.begin();
while ( iter != m_mButton.end() )
{
iterUp->second->EnableWindow( iter->second->bEnable );
iter ++;
iterUp++;
}
#else
for ( ; nItem < GetItemCount(); nItem++ )
{
iter = m_mButton.find(nItem);
if( iter!= m_mButton.end() )
{
CRect rect;
iterUp = m_mButton.find(iLine);
rect = iterUp->second->m_rect;
iter->second->MoveWindow( &rect );
iter->second->ShowWindow( SW_SHOW );
if( iLine < iTopIndex )
{
iterUp->second->ShowWindow( SW_HIDE );
}
iLine++;
}
}
#endif

}
// "Insert New Item"
void CListCtrlButtonDlg::OnButton1()
{
int iLine = m_list.GetItemCount();
CString szItemText;
szItemText.Format( _T("Name%02d"),iLine );
m_list.InsertItem( iLine, szItemText );

szItemText.Format(_T("%d"),(iLine+1)*2 );
m_list.SetItemText( iLine, 1,szItemText );

m_list.createItemButton( iLine, 2, this->GetSafeHwnd());
}

liups 2019-05-12
  • 打赏
  • 举报
回复
引用 1 楼 zgl7903 的回复:
可能没有现成的, 但是可以参考 https://www.codeproject.com/Articles/7370/CGridCtrl-1-5
谢谢分享
zgl7903 2019-05-11
  • 打赏
  • 举报
回复
可能没有现成的, 但是可以参考 https://www.codeproject.com/Articles/7370/CGridCtrl-1-5

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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