16,472
社区成员
发帖
与我相关
我的任务
分享
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());
}