15,978
社区成员
发帖
与我相关
我的任务
分享
void CButtonListBox::AddItem(LPCTSTR ButtonText)
{
CLedButton* pAddedButton;
static int count = 0;
CRect rect;
CRect ButtonRect;
count++;
GetClientRect( rect );
pAddedButton = new CLedButton(ButtonText,this);
ButtonRect.SetRect( 0, 0, rect.Width(), (rect.Height() / NUMBER_OF_BUTTONS_IN_LIST_VIEW) );
pAddedButton->Create( "", WS_CHILD|BS_OWNERDRAW, ButtonRect, this, 1001+count );
int AddedAt = m_ButtonArray.Add( pAddedButton );
//Adds a string and assigns nIndex the index of the current item
int nIndex = AddString( "" );
// Set a hight for the data item
CListBox::SetItemHeight( nIndex, rect.Height() / NUMBER_OF_BUTTONS_IN_LIST_VIEW );
//If no error, associates the index with the button
if( nIndex!=LB_ERR && nIndex!=LB_ERRSPACE )
SetItemData( nIndex, (DWORD)m_ButtonArray.ElementAt(AddedAt) );
}