VOID CEasySkinTreeCtrl::DrawListImage( CDC * pDC, CRect rcRect, HTREEITEM hTreeItem, bool bSelected ) { CMapItemInfo::iterator iter= m_MapItemInfo.find(hTreeItem); if( iter == m_MapItemInfo.end() ) { CImageList *pImageList = GetImageList(TVSIL_NORMAL); if( pImageList == NULL ) return; //获取属性 INT nImage,nSelectedImage; GetItemImage(hTreeItem,nImage,nSelectedImage); //获取信息 IMAGEINFO ImageInfo; pImageList->GetImageInfo(bSelected?nSelectedImage:nImage,&ImageInfo); //绘画图标 INT nImageWidth=ImageInfo.rcImage.right-ImageInfo.rcImage.left; INT nImageHeight=ImageInfo.rcImage.bottom-ImageInfo.rcImage.top; pImageList->Draw(pDC,bSelected?nSelectedImage:nImage,CPoint(rcRect.left-nImageWidth-3,rcRect.top+(rcRect.Height()-nImageHeight)/2+1),ILD_TRANSPARENT); } else { CImageEx *pImage = iter->second.pImage; pImage->DrawImage(pDC,rcRect.left-pImage->GetWidth()-3,rcRect.top+(rcRect.Height()-pImage->GetHeight())/2+1); } }
//绘画数据 VOID CEasySkinListCtrl::DrawReportItem(CDC * pDC, INT nItem, CRect & rcSubItem, INT nColumnIndex) { //获取文字 TCHAR szString[256]=TEXT(""); GetItemText(nItem,nColumnIndex,szString,CountArray(szString)); //绘画文字 rcSubItem.left+=5; //绘制CheckButton if( nColumnIndex == 0 ) { if ((m_pCheckImg != NULL && !m_pCheckImg->IsNull()) && (m_pUnCheckImg != NULL && !m_pUnCheckImg->IsNull())) { if( GetCheck(nItem) ) m_pCheckImg->DrawImage(pDC,rcSubItem.left+2,rcSubItem.top+(rcSubItem.Height()-m_pCheckImg->GetHeight())/2); else m_pUnCheckImg->DrawImage(pDC,rcSubItem.left+2,rcSubItem.top+(rcSubItem.Height()-m_pUnCheckImg->GetHeight())/2); rcSubItem.left+=(8+m_pCheckImg->GetWidth()); } CItemImgArray::iterator iter = m_ItemImgArray.begin(); for (;iter != m_ItemImgArray.end(); ++iter ) { if ( iter->nItem == nItem ) { CImageEx *pImage = iter->pImage; if (pImage != NULL && !pImage->IsNull()) { pImage->DrawImage(pDC,rcSubItem.left+2,rcSubItem.top+(rcSubItem.Height()-pImage->GetHeight())/2); rcSubItem.left+=(8+pImage->GetWidth()); } break; } } } pDC->DrawText(szString,lstrlen(szString),&rcSubItem,DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS); return; }
//设置区域 VOID CLayeredWindow::InitLayeredArea(CImageEx & Image, BYTE cbAlpha, CRect & rcUnLayered, CPoint & PointRound, bool bUnLayeredChild) { //创建缓冲 CImage ImageBuffer; ImageBuffer.Create(Image.GetWidth(),Image.GetHeight(),32); //绘画界面 CImageDC ImageDC(ImageBuffer); CDC * pBufferDC=CDC::FromHandle(ImageDC); //绘画界面 ASSERT(pBufferDC!=NULL); if (pBufferDC!=NULL) Image.DrawImage(pBufferDC,0,0); //创建分层 InitLayeredArea(pBufferDC,cbAlpha,rcUnLayered,PointRound,bUnLayeredChild); return; }
void CSkinTabCtrl::DrawItem(CDC*pDC, int nIndex) { CSkinTabCtrlItem * lpItem = GetItemByIndex(nIndex); if (NULL == lpItem) return; CRect rcItem; GetItemRectByIndex(nIndex, rcItem); if (m_nSelIndex == nIndex) { if (lpItem->m_lpBgImgD != NULL && !lpItem->m_lpBgImgD->IsNull()) lpItem->m_lpBgImgD->Draw(pDC, rcItem); else if (m_lpItemBgImgD != NULL && !m_lpItemBgImgD->IsNull()) m_lpItemBgImgD->Draw(pDC, rcItem); } else if (m_nHoverIndex == nIndex) { if (lpItem->m_lpBgImgH != NULL && !lpItem->m_lpBgImgH->IsNull()) lpItem->m_lpBgImgH->Draw(pDC, rcItem); else if (m_lpItemBgImgH != NULL && !m_lpItemBgImgH->IsNull()) m_lpItemBgImgH->Draw(pDC, rcItem); } else { if (lpItem->m_lpBgImgN != NULL && !lpItem->m_lpBgImgN->IsNull()) lpItem->m_lpBgImgN->Draw(pDC, rcItem); else if (m_lpItemBgImgN != NULL && !m_lpItemBgImgN->IsNull()) m_lpItemBgImgN->Draw(pDC, rcItem); } CImageEx * lpIconImg = NULL; if (m_nSelIndex == nIndex) lpIconImg = lpItem->m_lpSelIconImg; else lpIconImg = lpItem->m_lpIconImg; BOOL bHasText = FALSE; if (lpItem->m_strText.GetLength() > 0) bHasText = TRUE; BOOL bHasIcon = FALSE; if (lpIconImg != NULL && !lpIconImg->IsNull()) bHasIcon = TRUE; if (bHasIcon && bHasText) // 带图标和文字 { int cxIcon = lpIconImg->GetWidth(); int cyIcon = lpIconImg->GetHeight(); int nMode = pDC->SetBkMode(TRANSPARENT); pDC->SelectObject(GetCtrlFont()); pDC->SetTextColor(m_colNormalText); CRect rcText(0,0,0,0); // 计算文字宽高 pDC->DrawText(lpItem->m_strText, lpItem->m_strText.GetLength(), &rcText, DT_SINGLELINE | DT_CALCRECT); int cx = cxIcon+1+rcText.Width(); int cy = cyIcon; CRect rcCenter; CalcCenterRect(rcItem, cx, cy, rcCenter); CRect rcIcon(rcCenter.left, rcCenter.top, rcCenter.left+cxIcon, rcCenter.bottom); lpIconImg->Draw(pDC, rcIcon); UINT nFormat = DT_LEFT | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS; rcText = CRect(rcIcon.right+1, rcItem.top, rcIcon.right+1+rcText.Width(), rcItem.bottom); pDC->DrawText(lpItem->m_strText, lpItem->m_strText.GetLength(), &rcText, nFormat); pDC->SetBkMode(nMode); } else if (bHasIcon) // 仅图标 { int cxIcon = lpIconImg->GetWidth(); int cyIcon = lpIconImg->GetHeight(); CRect rcIcon; CalcCenterRect(rcItem, cxIcon, cyIcon, rcIcon); lpIconImg->Draw(pDC, rcIcon); } else if (bHasText) // 仅文字 { UINT nFormat = DT_CENTER | DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS; int nMode = pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(m_colNormalText); pDC->SelectObject(GetCtrlFont()); pDC->DrawText(lpItem->m_strText, lpItem->m_strText.GetLength(), &rcItem, nFormat); pDC->SetBkMode(nMode); } if (m_nSelIndex == nIndex) { if (lpItem->m_dwStyle & STCI_STYLE_DROPDOWN) { CRect rcArrow; rcArrow.left = rcItem.left+lpItem->m_nLeftWidth; rcArrow.top = rcItem.top; rcArrow.bottom = rcItem.bottom; rcArrow.right = rcArrow.left + lpItem->m_nRightWidth; if (m_bPressArrow) { if (lpItem->m_lpArrowImgD != NULL && !lpItem->m_lpArrowImgD->IsNull()) lpItem->m_lpArrowImgD->Draw(pDC, rcArrow); else if (m_lpArrowImgD != NULL && !m_lpArrowImgD->IsNull()) m_lpArrowImgD->Draw(pDC, rcArrow); } else if (m_nHoverIndex == nIndex) { if (lpItem->m_lpArrowImgH != NULL && !lpItem->m_lpArrowImgH->IsNull()) lpItem->m_lpArrowImgH->Draw(pDC, rcArrow); else if (m_lpArrowImgH != NULL && !m_lpArrowImgH->IsNull()) m_lpArrowImgH->Draw(pDC, rcArrow); } } } }