CListBox的彩色边框
我从CListBox继承了一个类叫CColorListBox,在对话框中有一个成员函数,作用是当选择某item时,这个item的边框就会变成红色。我写的代码如下,但是不知...
我从CListBox继承了一个类叫CColorListBox,在对话框中有一个成员函数,作用是当选择某item时,这个item的边框就会变成红色。
我写的代码如下,但是不知道该怎么写了!
DWORD dw;
dw = m_colorlist.GetCurSel();
CRect rect;
if(m_colorlist.GetItemRect(dw,&rect)!=LB_ERR)
{
rect.InflateRect(1,1,1,1);
}
CDC* pDC = this->GetDC();
HBRUSH brush = (HBRUSH)CreateSolidBrush(RGB(255,0,0));
CBrush* br = CBrush::FromHandle(brush);
pDC->FrameRect(&rect,br);
哪位大虾能帮帮我,谢谢! 展开
我写的代码如下,但是不知道该怎么写了!
DWORD dw;
dw = m_colorlist.GetCurSel();
CRect rect;
if(m_colorlist.GetItemRect(dw,&rect)!=LB_ERR)
{
rect.InflateRect(1,1,1,1);
}
CDC* pDC = this->GetDC();
HBRUSH brush = (HBRUSH)CreateSolidBrush(RGB(255,0,0));
CBrush* br = CBrush::FromHandle(brush);
pDC->FrameRect(&rect,br);
哪位大虾能帮帮我,谢谢! 展开
2个回答
展开全部
void CListBoxEx::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
// TODO: Add your code to draw the specified item
CDC *pDC = CDC::FromHandle( lpDIS->hDC );
pDC->SetBkMode( TRANSPARENT );
switch( lpDIS->itemAction )
{
case ODA_SELECT:
case ODA_DRAWENTIRE:
if( lpDIS->itemState & ODS_SELECTED )
{
CBrush br( RGB(153,153,153) );
pDC->FillRect( &lpDIS->rcItem, &br );
pDC->SetTextColor( RGB(255,255,255) );
}
else
{
CBrush br( ::GetSysColor( COLOR_WINDOW ) );
pDC->FillRect( &lpDIS->rcItem, &br );
pDC->SetTextColor( RGB(0,0,0) );
}
break;
}
if( ( lpDIS->itemState & ODS_SELECTED ) && ( lpDIS->itemAction & ( ODA_SELECT | ODA_DRAWENTIRE ) ) )
{
// item selected
CBrush br( RGB(153,153,153) );
pDC->FillRect( &lpDIS->rcItem, &br );
nIndex = GetCurSel();
}
else if( !( lpDIS->itemState & ODS_SELECTED ) && ( lpDIS->itemAction & ODA_SELECT ) )
{
// item deselected
CBrush br( ::GetSysColor( COLOR_WINDOW ) );
pDC->FillRect( &lpDIS->rcItem, &br );
}
// change the color of the selected item
if( lpDIS->itemState & ODS_SELECTED )
pDC->SetTextColor( RGB(255,255,255) );
else
pDC->SetTextColor( RGB(0,0,0) );
// draw the text
CString strTxt;
if( lpDIS->itemID != -1 )
{
GetText( lpDIS->itemID, strTxt );
pDC->DrawText( strTxt, &lpDIS->rcItem, DT_VCENTER | DT_SINGLELINE );
}
}
要重载DrawItem虚函数,我的这个颜色是灰底,你自己改下颜色吧
{
// TODO: Add your code to draw the specified item
CDC *pDC = CDC::FromHandle( lpDIS->hDC );
pDC->SetBkMode( TRANSPARENT );
switch( lpDIS->itemAction )
{
case ODA_SELECT:
case ODA_DRAWENTIRE:
if( lpDIS->itemState & ODS_SELECTED )
{
CBrush br( RGB(153,153,153) );
pDC->FillRect( &lpDIS->rcItem, &br );
pDC->SetTextColor( RGB(255,255,255) );
}
else
{
CBrush br( ::GetSysColor( COLOR_WINDOW ) );
pDC->FillRect( &lpDIS->rcItem, &br );
pDC->SetTextColor( RGB(0,0,0) );
}
break;
}
if( ( lpDIS->itemState & ODS_SELECTED ) && ( lpDIS->itemAction & ( ODA_SELECT | ODA_DRAWENTIRE ) ) )
{
// item selected
CBrush br( RGB(153,153,153) );
pDC->FillRect( &lpDIS->rcItem, &br );
nIndex = GetCurSel();
}
else if( !( lpDIS->itemState & ODS_SELECTED ) && ( lpDIS->itemAction & ODA_SELECT ) )
{
// item deselected
CBrush br( ::GetSysColor( COLOR_WINDOW ) );
pDC->FillRect( &lpDIS->rcItem, &br );
}
// change the color of the selected item
if( lpDIS->itemState & ODS_SELECTED )
pDC->SetTextColor( RGB(255,255,255) );
else
pDC->SetTextColor( RGB(0,0,0) );
// draw the text
CString strTxt;
if( lpDIS->itemID != -1 )
{
GetText( lpDIS->itemID, strTxt );
pDC->DrawText( strTxt, &lpDIS->rcItem, DT_VCENTER | DT_SINGLELINE );
}
}
要重载DrawItem虚函数,我的这个颜色是灰底,你自己改下颜色吧
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询