1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
| void CImageTextButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct )
{
if( lpDrawItemStruct->CtlType != ODT_BUTTON)
return;
//To keep the text color
COLORREF clrText;
int nImgCount =0;
//Keeps the index of the image(based on 0) to be drawn
int nPosImg=0;
CDC *pDC = CDC::FromHandle( lpDrawItemStruct->hDC );
if(!m_bLoaded)
{
m_rectBtn = lpDrawItemStruct->rcItem;
}
else
{
//Gets the number of image in the image list
nImgCount = m_ImageList.GetImageCount();
::SetWindowPos(lpDrawItemStruct->hwndItem,NULL,m_rectBtn.left,m_rectBtn.top,m_bitmap.bmWidth,m_bitmap.bmHeight,SWP_NOMOVE);
}
pDC->DrawFrameControl( &m_rectBtn ,DFC_BUTTON , DFCS_BUTTONPUSH|DFCS_PUSHED);
//if( m_bLoaded )
{
if(ODS_DISABLED & lpDrawItemStruct->itemState)
{
if( m_bLoaded )
{
if(3== nImgCount)
nPosImg = 2;
else
nPosImg =0;
}
clrText = m_clrCptnDisabled;
}
else if(ODS_SELECTED & lpDrawItemStruct->itemState)
{
if( m_bLoaded )
{
if(2 <= nImgCount )
nPosImg = 1;
else
nPosImg =0;
}
clrText = m_clrCptnUpDwn;
}
else
{
if( m_bLoaded )
{
nPosImg =0;
}
clrText = m_clrCptnUpDwn;
}
if( m_bLoaded )
{
//Draw the image in to the DC
m_ImageList.DrawIndirect(
pDC ,
nPosImg ,
CPoint( m_rectBtn.left,m_rectBtn.top ),
CSize( m_bitmap.bmWidth , m_bitmap.bmHeight ),
CPoint( 0 , 0 ) ,
ILD_NORMAL,
SRCCOPY,
CLR_DEFAULT,
CLR_DEFAULT
);
}
}
if(!m_strText.IsEmpty())
{
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor( clrText);
HFONT hOldFont=NULL;
//Sets the font
if(m_Font.GetSafeHandle() != NULL)
{
hOldFont =(HFONT) pDC->SelectObject(m_Font.GetSafeHandle());
}
if(m_nYpos!=-1 && m_nXpos!=-1)
{
// pDC->TextOut(m_nXpos,m_nYpos,m_strText);
}
else
{
pDC->DrawText( m_strText, m_rectBtn , m_uiPos);
}
//Reset the old font
if(hOldFont != NULL)
{
pDC->SelectObject(hOldFont);
}
}
} |