Esempio n. 1
0
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);
	}
}
Esempio n. 2
0
      /// <summary>Custom draws a single sub-item</summary>
      /// <param name="dc">Device context</param>
      /// <param name="item">Item data.</param>
      void  ListViewCustomDraw::onDrawSubItem(CDC* dc, ItemData& item)
      {
         // Get item data
         LVItem data(item.Index, item.SubItem, 512, LVIF_IMAGE | LVIF_TEXT);
         ListView.GetItem(&data);

         // Draw Icon:
         CImageList* imgList = ListView.GetImageList(LVSIL_SMALL);
         if (item.SubItem == 0 && imgList)
         {
            CRect icon;

            // Get icon rectangle
            ListView.GetSubItemRect(item.Index, 0, LVIR_ICON, icon);
            
            // Draw transparent
            if (!imgList->Draw(dc, data.iImage, icon.TopLeft(), ILD_TRANSPARENT))
               throw Win32Exception(HERE, VString(L"Unable to draw icon for item %d", item.Index));

            // Create gap betwen icon/label
            item.Rect.left += 3;
         }

         // Draw Text:
         dc->DrawText(data.pszText, item.Rect, DT_VCENTER|DT_LEFT|DT_END_ELLIPSIS|DT_SINGLELINE);
      }
void CClosableTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	CRect rect = lpDrawItemStruct->rcItem;
	int nTabIndex = lpDrawItemStruct->itemID;
	if (nTabIndex < 0)
		return;
	BOOL bSelected = (nTabIndex == GetCurSel());

	TCHAR szLabel[256];
	TC_ITEM tci;
	tci.mask = TCIF_TEXT | TCIF_IMAGE | TCIF_STATE;
	tci.pszText = szLabel;
	tci.cchTextMax = ARRSIZE(szLabel);
	tci.dwStateMask = TCIS_HIGHLIGHTED;
	if (!GetItem(nTabIndex, &tci))
		return;

	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	if (!pDC)
		return;

	int iOldBkMode = pDC->SetBkMode(TRANSPARENT);

	// Draw image on left side
	CImageList* piml = GetImageList();
	if (tci.iImage >= 0 && piml && piml->m_hImageList)
	{
		IMAGEINFO ii;
		piml->GetImageInfo(0, &ii);
		rect.left += bSelected ? 8 : 4;
		piml->Draw(pDC, tci.iImage, CPoint(rect.left, rect.top + 2), ILD_TRANSPARENT);
		rect.left += (ii.rcImage.right - ii.rcImage.left);
		if (!bSelected)
			rect.left += 4;
	}

	bool bCloseable = m_bCloseable;
	if (bCloseable && GetParent()->SendMessage(UM_QUERYTAB, nTabIndex))
		bCloseable = false;

	// Draw 'Close button' at right side
	if (bCloseable && m_ImgLstCloseButton.m_hImageList)
	{
		CRect rcCloseButton;
		GetCloseButtonRect(rect, rcCloseButton);
		m_ImgLstCloseButton.Draw(pDC, 0, rcCloseButton.TopLeft(), ILD_TRANSPARENT);
		rect.right = rcCloseButton.left - 2;
	}

	COLORREF crOldColor = RGB(0, 0, 0);
	if (tci.dwState & TCIS_HIGHLIGHTED)
		crOldColor = pDC->SetTextColor(RGB(192, 0, 0));

	rect.top += 4;
	pDC->DrawText(szLabel, rect, DT_SINGLELINE | DT_TOP | DT_CENTER | DT_NOPREFIX);

	if (tci.dwState & TCIS_HIGHLIGHTED)
		pDC->SetTextColor(crOldColor);
	pDC->SetBkMode(iOldBkMode);
}
Esempio n. 4
0
void CXTPSkinObjectTab::DrawTabIcon(CDC* pDC, CRect& rcItem, int iItem)
{
	CTabCtrl* pTabCtrl = (CTabCtrl*)this;

	TC_ITEM tci;
	tci.mask = TCIF_IMAGE;

	BOOL bResult = pTabCtrl->GetItem(iItem, &tci);

#ifdef _UNICODE
	if (!bResult)
	{
		TC_ITEMA tcia;
		::ZeroMemory(&tcia, sizeof(TC_ITEMA));

		tcia.mask = TCIF_IMAGE;

		bResult = (BOOL)::SendMessage(pTabCtrl->m_hWnd, TCM_GETITEMA, iItem, (LPARAM)&tcia);
		tci.iImage = tcia.iImage;
	}
#endif
	if (!bResult)
		return;

	CImageList* pImageList = pTabCtrl->GetImageList();
	if (!pImageList || tci.iImage < 0)
		return;

	CPoint point = rcItem.TopLeft();

	DWORD dwStyle = GetStyle();

	if (IsHorz(dwStyle))
	{
		point.Offset(GetMetrics()->m_cxEdge * 2, IsTop(dwStyle) ? GetMetrics()->m_cyEdge : 1);
	}
	else
	{
		point.Offset(IsLeft(dwStyle) ? GetMetrics()->m_cxEdge : 1, GetMetrics()->m_cyEdge * 2);
	}

	// Draw any associated icons.
	pImageList->Draw(pDC, tci.iImage, point, ILD_TRANSPARENT);

	IMAGEINFO info;
	::ZeroMemory(&info, sizeof(info));

	pImageList->GetImageInfo(tci.iImage, &info);
	CRect rcImage(info.rcImage);

	if (IsHorz(dwStyle))
	{
		rcItem.left += rcImage.Width() + GetMetrics()->m_cxEdge;
	}
	else
	{
		rcItem.top += rcImage.Height() + GetMetrics()->m_cyEdge;
	}
}
Esempio n. 5
0
void CNineShowView::SetSortArrow(CDC *pDC,NineShowData *l_NineShowDat)
{

	int iddd = IDB_1;
	if(!(l_NineShowDat->bAscending)) iddd = IDB_2;
	CImageList list;
	list.Create (iddd,17,1,RGB(255,255,255));
	CPoint p;
	 p.y =(l_NineShowDat->rcTitle.bottom+l_NineShowDat->rcTitle.top)/2-8;
     p.x =l_NineShowDat->rcTitle.right -35;
	list.Draw(pDC,0,p,ILD_TRANSPARENT);
	return;

     CPen *poldpen;
	 CRect rect;

	 CPen pen_white(PS_SOLID,1,RGB(255,255,255));  
	 CPen pen_black(PS_SOLID,1,RGB(0,0,0));     
	 int nBackMode;
     nBackMode=pDC->GetBkMode();
     if(nBackMode==TRANSPARENT) pDC->SetBkMode(OPAQUE);


	 rect.top =(l_NineShowDat->rcTitle.bottom+l_NineShowDat->rcTitle.top)/2-8;
     rect.bottom =(l_NineShowDat->rcTitle.bottom+l_NineShowDat->rcTitle.top)/2+4;
     rect.left =l_NineShowDat->rcTitle.right -17+2;
	 rect.right =l_NineShowDat->rcTitle.right-8+2;


	 poldpen = pDC->SelectObject(&pen_white);
	 if(l_NineShowDat->bAscending)
	 {
		 pDC->MoveTo(rect.left,rect.bottom);
		 pDC->LineTo(rect.right,rect.bottom);
		 pDC->MoveTo(rect.right,rect.bottom);
		 pDC->LineTo((rect.left+rect.right)/2,rect.top);
	 }
	 else
	 {
		 pDC->MoveTo(rect.right,rect.top+4);
		 pDC->LineTo((rect.left+rect.right)/2,rect.bottom+4);
	 }
	 pDC->SelectObject(&pen_black);
     if(l_NineShowDat->bAscending)
	 {
		 pDC->MoveTo(rect.left,rect.bottom);
		 pDC->LineTo((rect.left+rect.right)/2,rect.top);
	 }
	 else
	 {
		 pDC->MoveTo(rect.left,rect.top+4);
		 pDC->LineTo(rect.right,rect.top+4);
		 pDC->MoveTo(rect.left,rect.top+4);
		 pDC->LineTo((rect.left+rect.right)/2,rect.bottom+4);
	 }	 
	 pDC->SelectObject(poldpen);
	 if(nBackMode==TRANSPARENT) pDC->SetBkMode(TRANSPARENT);
} 
Esempio n. 6
0
void CTabCtrlDoc::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{	
	CRect rect = lpDrawItemStruct->rcItem;
	int nTabIndex = lpDrawItemStruct->itemID;
	if (nTabIndex < 0) return;
	BOOL bSelected = (nTabIndex == GetCurSel());

	WCHAR label[64];
	TC_ITEM tci;
	tci.mask = TCIF_TEXT|TCIF_IMAGE;
	tci.pszText = label;     
	tci.cchTextMax = 63;    	
	if (!GetItem(nTabIndex, &tci)) return;

	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	if (!pDC) return;
	int nSavedDC = pDC->SaveDC();

	// For some bizarre reason the rcItem you get extends above the actual
	// drawing area. We have to workaround this "feature".
	rect.top += ::GetSystemMetrics(SM_CYEDGE);

	pDC->SetBkMode(TRANSPARENT);
	pDC->FillSolidRect(rect, ::GetSysColor(COLOR_BTNFACE));

	// Draw image
	CImageList* pImageList = GetImageList();
	if (pImageList && tci.iImage >= 0) 
	{

		rect.left += pDC->GetTextExtent(_T(" ")).cx;		// Margin

		// Get height of image so we 
		IMAGEINFO info;
		pImageList->GetImageInfo(tci.iImage, &info);
		CRect ImageRect(info.rcImage);
		int nYpos = rect.top;

		pImageList->Draw(pDC, tci.iImage, CPoint(rect.left, nYpos), ILD_TRANSPARENT);
		rect.left += ImageRect.Width();
	}

	if (bSelected) 
	{
		pDC->SetTextColor(m_crSelColour);
		pDC->SelectObject(&m_SelFont);
		rect.top -= ::GetSystemMetrics(SM_CYEDGE);
		pDC->DrawText(label, rect, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
	}
	else 
	{
		pDC->SetTextColor(m_crUnselColour);
		pDC->SelectObject(&m_UnselFont);
		pDC->DrawText(label, rect, DT_SINGLELINE|DT_BOTTOM|DT_CENTER);
	}

	pDC->RestoreDC(nSavedDC);
}
Esempio n. 7
0
//显示条目,显示在前部显示驱动其的特征图标
//在其后显示该驱动器的名称
void CDriverBox::DrawItem(LPDRAWITEMSTRUCT lpDS) 
{
	// TODO: Add your code to draw the specified item
	if(lpDS->itemID==LB_ERR) return;
	CDC* pDC=CDC::FromHandle(lpDS->hDC);
	//
	CRect r(lpDS->rcItem);	
	BOOL bEnable=(GetStyle()&WS_DISABLED)==0;
	CImageList list;
	//得到驱动器图标并显示
	list.Create("IDB_DIRBROWNS",16,0,0xffffff);
	r.left+=4;
	list.Draw(pDC,0,r.TopLeft(),bEnable?ILD_TRANSPARENT:ILD_BLEND);	
	r.left+=20;
	CBrush br;
	//绘制字符背景
	if( bEnable&&(/*(lpDS->itemAction & (ODA_SELECT |ODA_SELECT|ODA_FOCUS))
		&&*/(lpDS->itemState & ODS_SELECTED))|
		((lpDS->itemState&ODS_COMBOBOXEDIT)&&(lpDS->itemState&ODS_FOCUS)))
	{   //该条目被选中并被允许
		br.CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));		
		pDC->FillRect(&r, &br);		
		pDC->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT));
		pDC->SetBkMode(TRANSPARENT);		
		if(lpDS->itemState&ODS_COMBOBOXEDIT)
			pDC->DrawFocusRect(r);
	}		
	else 
	{	br.CreateSolidBrush(GetSysColor(COLOR_WINDOW));
		if(bEnable)pDC->FillRect(&r, &br); 		
		pDC->SetTextColor(GetSysColor(bEnable?COLOR_WINDOWTEXT:COLOR_GRAYTEXT)); 
		pDC->SetBkMode(TRANSPARENT);		
	}
	CString text=m_drvList.GetAt(m_drvList.FindIndex(lpDS->itemID));
	//this->GetItemDataPtr(0);
	//GetLBText(lpDS->itemID,text);

	pDC->TextOut(r.left,r.top,text);
}
Esempio n. 8
0
HBITMAP CEmoticonRichEditCtrl::GetImage(CImageList& list, int num)
{
	CBitmap dist; 
	CClientDC dc(NULL);

	IMAGEINFO ii;
	list.GetImageInfo(num, &ii);

	int nWidth = ii.rcImage.right - ii.rcImage.left;
	int nHeight = ii.rcImage.bottom - ii.rcImage.top;

	dist.CreateCompatibleBitmap(&dc, nWidth, nHeight);
	CDC memDC;
	memDC.CreateCompatibleDC(&dc);
	CBitmap* pOldBitmap = memDC.SelectObject(&dist);
	
	memDC.FillSolidRect(0, 0, nWidth, nHeight, SetBackgroundColor(TRUE, 0));
	list.Draw(&memDC, num, CPoint(0, 0), ILD_NORMAL);

	memDC.SelectObject(pOldBitmap);

	return (HBITMAP)dist.Detach(); 
}
Esempio n. 9
0
void CXTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{	
	CRect rect = lpDrawItemStruct->rcItem;
	rect.bottom+=2;
	rect.top += ::GetSystemMetrics(SM_CYEDGE);

	int nTabIndex = lpDrawItemStruct->itemID;
	
	if (nTabIndex < 0) return;

	BOOL bSelected = (nTabIndex == GetCurSel());

	COLORREF crSelected = m_bColorSelected ? m_crSelected : GetSysColor(COLOR_BTNTEXT);
	COLORREF crNormal  = m_bColorNormal   ? m_crNormal   : GetSysColor(COLOR_BTNTEXT);
	COLORREF crDisabled = m_bColorDisabled ? m_crDisabled : GetSysColor(COLOR_GRAYTEXT);


	TCHAR label[64];
	TC_ITEM item;
	item.mask = TCIF_TEXT|TCIF_IMAGE;
	item.pszText = label;     
	item.cchTextMax = 63;    	
	if (!GetItem(nTabIndex, &item))
		return;

	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	if (!pDC)
		return;

	int nSavedDC = pDC->SaveDC();

	CRect rectItem;
	POINT pt;

	GetItemRect(nTabIndex, &rectItem);
	GetCursorPos(&pt);
	ScreenToClient(&pt);

	if (rectItem.PtInRect(pt))
		m_iIndexMouseOver = nTabIndex;



	pDC->SetBkMode(TRANSPARENT);
	pDC->FillSolidRect(rect, ::GetSysColor(COLOR_BTNFACE));

	//**  Draw the image
	CImageList* pImageList = GetImageList();
	if (pImageList && item.iImage >= 0) 
	{

		rect.left += pDC->GetTextExtent(_T(" ")).cx;

		IMAGEINFO info;
		pImageList->GetImageInfo(item.iImage, &info);
		CRect ImageRect(info.rcImage);
		int nYpos = rect.top;

		pImageList->Draw(pDC, item.iImage, CPoint(rect.left, nYpos), ILD_TRANSPARENT);
		rect.left += ImageRect.Width();
	}

	if (!IsTabEnabled(nTabIndex))
	{
		pDC->SetTextColor(crDisabled);
		rect.top -= ::GetSystemMetrics(SM_CYEDGE);
		pDC->DrawText(label, rect, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
	}
	else
	{
		//** selected item -----
		if (bSelected)
			pDC->SetTextColor(crSelected);
		else //** other item ---
		{
			if (m_bColorMouseOver && nTabIndex == m_iIndexMouseOver) 
			{
				pDC->SetTextColor(m_crMouseOver);	
			}
			else
			{
				pDC->SetTextColor(crNormal);
			}
		}

		rect.top -= ::GetSystemMetrics(SM_CYEDGE);
		pDC->DrawText(label, rect, DT_SINGLELINE|DT_VCENTER|DT_CENTER);

	}

	pDC->RestoreDC(nSavedDC);
}
void CXTPSkinObjectHeader::DrawItemEntry(CDC* pDC, int nIndex, CRect rcItem, int nState)
{
	CXTPSkinManagerClass* pClass = GetSkinClass();

	CHeaderCtrl* pHeaderCtrl = (CHeaderCtrl*)this;
	CImageList* pImageList = CImageList::FromHandle((HIMAGELIST)
		::SendMessage(pHeaderCtrl->m_hWnd, HDM_GETIMAGELIST, 0, 0L));

	// Set up the header item order array.
	HD_ITEM hdi;
	::ZeroMemory(&hdi, sizeof(HD_ITEM));

	hdi.fmt = HDF_STRING | HDF_IMAGE;
	hdi.mask = HDI_TEXT | HDI_FORMAT | HDI_IMAGE | HDI_LPARAM;

	// Get the header item text and format
	CString strCaption;
	LPTSTR pszText = strCaption.GetBuffer(256);
	pszText[0] = 0;
	hdi.pszText = pszText;
	hdi.cchTextMax = 255;

	BOOL bResult = pHeaderCtrl->GetItem(nIndex, &hdi);

	strCaption.ReleaseBuffer();

#ifdef _UNICODE
	if (!bResult)
	{
		char tText[256];
		tText[0] = 0;

		HD_ITEMA hdia;
		::ZeroMemory(&hdia, sizeof(HD_ITEMA));

		hdia.fmt = HDF_STRING | HDF_IMAGE;
		hdia.mask = HDI_TEXT | HDI_FORMAT | HDI_IMAGE | HDI_LPARAM;

		// Get the header item text and format
		hdia.pszText = tText;
		hdia.cchTextMax = 255;

		::SendMessage(pHeaderCtrl->m_hWnd, HDM_GETITEMA, nIndex, (LPARAM)&hdia);

		strCaption = tText;
		hdi.fmt = hdia.fmt;
		hdi.iImage = hdia.iImage;
		hdi.lParam = hdia.lParam;
	}
#else
	bResult;
#endif

	if (hdi.fmt & HDF_OWNERDRAW)
	{
		DRAWITEMSTRUCT dis;

		dis.CtlType = ODT_HEADER;
		dis.CtlID = (UINT)GetDlgCtrlID();
		dis.itemID = nIndex;
		dis.itemAction = ODA_DRAWENTIRE;
		dis.itemState = (nState == HIS_PRESSED) ? ODS_SELECTED : 0;
		dis.hwndItem = m_hWnd;
		dis.hDC = pDC->GetSafeHdc();
		dis.rcItem = rcItem;
		dis.itemData = hdi.lParam;

		// Now send it off to my parent...
		if (GetParent()->SendMessage(WM_DRAWITEM, dis.CtlID,
			(LPARAM)(DRAWITEMSTRUCT*)&dis))
		{
			return;
		}
	}

	CRect rcText(rcItem);

	if (pImageList && (hdi.fmt & HDF_IMAGE) && hdi.iImage >= 0 && hdi.iImage < pImageList->GetImageCount())
	{
		int iBitmapMargin = (int)SendMessage(HDM_GETBITMAPMARGIN);
		if (iBitmapMargin == 0)
			iBitmapMargin = GetMetrics()->m_cxEdge * 3;
		int cxBitmap = 16, cyBitmap = 16;
		ImageList_GetIconSize(pImageList->GetSafeHandle(), &cxBitmap, &cyBitmap);

		CPoint pt(rcItem.left + iBitmapMargin, (rcItem.bottom + rcItem.top - cyBitmap) / 2);

		if (hdi.fmt & HDF_BITMAP_ON_RIGHT)
		{
			CSize sz = pDC->GetTextExtent(strCaption);

			pt.x += sz.cx + iBitmapMargin + 9;
			if (pt.x + cxBitmap > rcItem.right - 3)
				pt.x = max(rcItem.left + 6, rcItem.right - 3 - cxBitmap);
			if (nState == HIS_PRESSED)
				pt.x ++;

			pImageList->Draw(pDC, hdi.iImage, pt, ILD_TRANSPARENT);
			rcText.right = pt.x + 6;
		}
		else
		{
			if (nState == HIS_PRESSED)
				pt.x ++;
			pImageList->Draw(pDC, hdi.iImage, pt, ILD_TRANSPARENT);

			rcText.left += cxBitmap + iBitmapMargin;
		}
	}

	if (((hdi.fmt & HDF_IMAGE) == 0) && ((hdi.fmt & HDF_SORTUP) || (hdi.fmt & HDF_SORTDOWN)))
	{
		int iBitmapMargin = GetMetrics()->m_cxEdge * 3;
		CSize sz = pDC->GetTextExtent(strCaption);

		CPoint pt(rcItem.left + iBitmapMargin, (rcItem.bottom + rcItem.top - 2) / 2);

		pt.x += sz.cx + iBitmapMargin + 9;
		if (pt.x + 9 > rcItem.right - 3)
			pt.x = max(rcItem.left + 6, rcItem.right - 3 - 9);

		if (hdi.fmt & HDF_SORTUP)
		{
			XTPDrawHelpers()->Triangle(pDC, CPoint(pt.x - 4, pt.y + 2),
				CPoint(pt.x, pt.y - 2), CPoint(pt.x + 4, pt.y + 2), GetColor(COLOR_3DSHADOW));
		}
		else
		{
			XTPDrawHelpers()->Triangle(pDC, CPoint(pt.x - 4, pt.y - 2),
				CPoint(pt.x, pt.y + 2), CPoint(pt.x + 4, pt.y - 2), GetColor(COLOR_3DSHADOW));
		}
		rcText.right = pt.x;
	}

	UINT nFormat = DT_SINGLELINE | DT_VCENTER | DT_END_ELLIPSIS | DT_NOPREFIX;

	// determine justification for text.
	switch (hdi.fmt & HDF_JUSTIFYMASK)
	{
	case HDF_LEFT:
		nFormat |= DT_LEFT;
		rcText.DeflateRect(9, 0, 6, 0);
		break;

	case HDF_CENTER:
		nFormat |= DT_CENTER;
		rcText.DeflateRect(6, 0, 6, 0);
		break;

	case HDF_RIGHT:
		nFormat |= DT_RIGHT;
		rcText.DeflateRect(6, 0, 9, 0);
		break;
	}

	if (rcText.Width() > 0)
	{
		if (nState == HIS_PRESSED)
			rcText.OffsetRect(1, 1);

		// draw text.
		pDC->SetTextColor(GetColor(COLOR_BTNTEXT));
		pClass->DrawThemeText(pDC, HP_HEADERITEM, nState, strCaption, nFormat, &rcText);
	}
}
Esempio n. 11
0
void CEnListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
	CDC* pDC;
	CRect rText, rItem, rClient, rHeader;
	COLORREF crOldText, crOldBack;
	CSize sizeText;
	LV_COLUMN lvc = { 0 };
//	CPen* pOldPen;
	CImageList* pImageList;
	CImageList* pStateList;
	int nImage = -1;
	BOOL bItemFocused, bListFocused, bSelected, bDropHighlighted, bSelAlways;
	UINT uStyle, uState;
	CSize sizeState(0, 0), sizeImage(0, 0);
	int nIndent = 0;

	// get and prepare device context
	pDC = CDC::FromHandle(lpDrawItemStruct->hDC);//GetDC(); 
	pDC->SelectObject(GetFont());
	pDC->SetROP2(R2_COPYPEN);

	// init helper variables
	int nItem = lpDrawItemStruct->itemID;
	GetItemRect(nItem, rItem, LVIR_BOUNDS);//lpDrawItemStruct->rcItem;
	GetClientRect(&rClient);

	// some problems with drophiliting items during drag and drop
	// so we need to make sure drawing is clipped to client area
	// this fixes it admirably!
	if (GetHeader())
	{
		GetHeader()->GetWindowRect(rHeader);
		ScreenToClient(rHeader);
		rClient.top = max(0, rHeader.bottom);
		pDC->IntersectClipRect(rClient);
	}

	rText = rItem;

	uStyle = GetStyle();
	uState = GetItemState(nItem, LVIS_DROPHILITED | LVIS_SELECTED);
	bDropHighlighted = (uState & LVIS_DROPHILITED);
	bItemFocused = (GetFocusedItem() == nItem);
	bListFocused = (GetFocus() == this);
	bSelected = (uState & LVIS_SELECTED);
	bSelAlways = ((uStyle & LVS_SHOWSELALWAYS) == LVS_SHOWSELALWAYS);
	bSelected = bSelected && (bListFocused || bSelAlways);

	crOldText = pDC->SetTextColor(COLORREF(0)); // this will be overwritten on a per subitem basis
	crOldBack = pDC->SetBkColor(GetItemBackColor(nItem, bSelected, bDropHighlighted, bListFocused));

	// images and indentation
	pImageList = GetImageList(LVSIL_SMALL);

	if (pImageList)
	{
		nImage = GetImageIndex(nItem, 0); 
		ImageList_GetIconSize(pImageList->m_hImageList, (int*)&sizeImage.cx, (int*)&sizeImage.cy);

		nIndent = GetItemIndent(nItem) * sizeImage.cx;

		rText.left += nIndent;
		rItem.left += nIndent;

//		if (pImageList == &s_ilIndent)
//			pImageList = NULL;
	}

	// state
	pStateList = GetImageList(LVSIL_STATE);

	if (pStateList)
		ImageList_GetIconSize(pStateList->m_hImageList, (int*)&sizeState.cx, (int*)&sizeState.cy);

	if (lpDrawItemStruct->itemAction & (ODA_DRAWENTIRE | ODA_SELECT))
	{
		// setup colors and pens
		int nImageStyle = GetImageStyle(bSelected, bDropHighlighted, bListFocused);

		// draw item images if required
		int nImageWidth = 0;

		// make sure there is enough space
		lvc.mask = LVCF_WIDTH | LVCF_FMT;
		int nCol = 0;
		BOOL bRes = GetColumn(nCol, &lvc);
		
		// must paint the background of column 0 before the icons
		if (bRes && (pStateList || pImageList))
			pDC->ExtTextOut(0, rItem.top, ETO_CLIPPED | ETO_OPAQUE, CRect(0, rItem.top, lvc.cx, rItem.bottom), _T(""), NULL);

		// state
		if (pStateList && bRes)
		{
			int nState = (GetItemState(nItem, LVIS_STATEIMAGEMASK) & LVIS_STATEIMAGEMASK);
			nState = nState >> 12;

			if (lvc.cx > sizeState.cx)
				pStateList->Draw(pDC, nState, CPoint(rText.left + 1, rText.top), ILD_TRANSPARENT); 

			nImageWidth = sizeState.cx + 2; // 1 pixel border either side
		}
void CListCtrlEx::DrawItem(LPDRAWITEMSTRUCT lpDraw)
{try{
	int cCols = GetHeaderCtrl ()->GetItemCount ();
	CDC *dc = CDC::FromHandle (lpDraw->hDC);
	int xStart = lpDraw->rcItem.left;	
	CImageList *pImages = GetImageList (LVSIL_SMALL);
	BOOL bNeedBorder = FALSE;	

	

	CHeaderCtrl* pHdr = GetHeaderCtrl ();

	
	for (int i = 0; i < cCols; i++)
	{
		LVITEM item;
		TCHAR szItem [10000];
		int colWidth = GetColumnWidth (pHdr->OrderToIndex (i));

		xStart += 5;
		colWidth -= 5;

		item.iItem = lpDraw->itemID;
		item.iSubItem = i;
		item.pszText = szItem;
		item.cchTextMax = sizeof (szItem);
		item.mask = LVIF_IMAGE | LVIF_TEXT;

		GetItem (&item);

		
		if (i == 0)
		{
			item.state = GetItemState (lpDraw->itemID, LVIS_SELECTED|LVIS_FOCUSED);

			COLORREF clrBg = m_vInfo [lpDraw->itemID].clrBg;
			COLORREF clrText = m_vInfo [lpDraw->itemID].clrText;
	
			
			
			if (item.state & LVIS_FOCUSED)
				bNeedBorder = TRUE;

			if (item.state & LVIS_SELECTED)
			{
				clrBg = GetSysColor (COLOR_HIGHLIGHT);
				clrText = GetSysColor (COLOR_HIGHLIGHTTEXT);
				if (bNeedBorder == FALSE)
				{
					if (GetSelectionMark () == (int)lpDraw->itemID)
						bNeedBorder = TRUE;
				}
			}
		
			CBrush br;
			CPen pen;
			CBrush *oldBr;
			CPen *oldPen;

			if (RGBIsEqual (clrBg, clrText))
				clrText = (~clrText) & 0x00FFFFFF;

			dc->SetTextColor (clrText);

			br.CreateSolidBrush (clrBg);
			pen.CreatePen (PS_SOLID, 1, clrBg);

			oldBr = dc->SelectObject (&br);
			oldPen = dc->SelectObject (&pen);
			
			dc->Rectangle (&lpDraw->rcItem);

			
			if (m_bGrid)
			{
				CPen pen1 (PS_SOLID, 1, m_clrGrid);
				dc->SelectObject (&pen1);
				dc->MoveTo (lpDraw->rcItem.left, lpDraw->rcItem.bottom-1);
				dc->LineTo (lpDraw->rcItem.right, lpDraw->rcItem.bottom-1);
				dc->SelectObject (oldPen);
			}

			dc->SelectObject (oldBr);
			dc->SelectObject (oldPen);

			if (pImages)
			{
				

				CPoint pt;
				pt.x = xStart;
				pt.y = lpDraw->rcItem.top;
				if (m_pSelImages && (item.state & LVIS_SELECTED))
					m_pSelImages->Draw (dc, item.iImage, pt, ILD_TRANSPARENT);
				else
					pImages->Draw (dc, item.iImage, pt, ILD_TRANSPARENT);

				IMAGEINFO inf;
				pImages->GetImageInfo (item.iImage, &inf);

				xStart += inf.rcImage.right - inf.rcImage.left + 5;
				colWidth -= inf.rcImage.right - inf.rcImage.left + 5;
			}
		}

		if (*item.pszText)
		{
			

			int needX = GetStringWidth (item.pszText);
			BOOL bDrawText = TRUE;

			RECT rcText = lpDraw->rcItem;
			rcText.left = xStart;
			rcText.right = xStart + colWidth - 5;

			
			if (needX > colWidth-5)
			{
				RECT rc = rcText;
				int dx = GetStringWidth ("...");
				if (dx <= colWidth-5)
				{
					rc.left = rc.right - dx;
					dc->DrawText ("...", &rc, DT_SINGLELINE | DT_LEFT | DT_VCENTER);
					rcText.right = rc.left - 5;
				}
				else
					bDrawText = FALSE;
			}

			if (bDrawText)
				dc->DrawText (szItem, &rcText, DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_NOPREFIX);
		}

		xStart += colWidth;

		
		if (m_bGrid)
		{
			
			CPen pen (PS_SOLID, 1, m_clrGrid);
			CPen *oldPen = dc->SelectObject (&pen);
			dc->MoveTo (xStart-1, lpDraw->rcItem.top);
			dc->LineTo (xStart-1, lpDraw->rcItem.bottom);
			dc->SelectObject (oldPen);
		}
	}

	if (bNeedBorder)
	{
		

		dc->SetTextColor (m_vInfo [lpDraw->itemID].clrText);
		RECT rc = lpDraw->rcItem;
		rc.bottom--; rc.right--;
		dc->DrawFocusRect (&rc);
	}

}catch (...){}
}
Esempio n. 13
0
CImageList* CPlayerListCtrl::CreateDragImageEx(LPPOINT lpPoint)
{
    if (GetSelectedCount() <= 0) {
        return nullptr;
    }

    CRect cSingleRect, cCompleteRect(0, 0, 0, 0);
    GetClientRect(cSingleRect);
    int nWidth = cSingleRect.Width();

    // Start and Stop index in view area
    int nIndex = GetTopIndex() - 1;
    int nBottomIndex = GetBottomIndex();

    // Determine the size of the drag image (limited for
    // rows visible and Client width)
    while ((nIndex = GetNextItem(nIndex, LVNI_SELECTED)) != -1 && nIndex <= nBottomIndex) {
        GetItemRect(nIndex, cSingleRect, LVIR_BOUNDS);
        /*
        CRect r;
        GetItemRect(nIndex, r, LVIR_LABEL);
        cSingleRect.left = r.left;
        */
        if (cSingleRect.left < 0) {
            cSingleRect.left = 0;
        }
        if (cSingleRect.right > nWidth) {
            cSingleRect.right = nWidth;
        }

        cCompleteRect |= cSingleRect;
    }

    //
    // Create bitmap in memory DC
    //
    CClientDC cDc(this);
    CDC cMemDC;
    CBitmap cBitmap;

    if (!cMemDC.CreateCompatibleDC(&cDc)) {
        return nullptr;
    }

    if (!cBitmap.CreateCompatibleBitmap(&cDc, cCompleteRect.Width(), cCompleteRect.Height())) {
        return nullptr;
    }

    CBitmap* pOldMemDCBitmap = cMemDC.SelectObject(&cBitmap);
    // Here green is used as mask color
    cMemDC.FillSolidRect(0, 0, cCompleteRect.Width(), cCompleteRect.Height(), RGB(0, 255, 0));

    // Paint each DragImage in the DC
    nIndex = GetTopIndex() - 1;
    while ((nIndex = GetNextItem(nIndex, LVNI_SELECTED)) != -1 && nIndex <= nBottomIndex) {
        CPoint pt;
        CImageList* pSingleImageList = CreateDragImage(nIndex, &pt);

        if (pSingleImageList) {
            GetItemRect(nIndex, cSingleRect, LVIR_BOUNDS);

            pSingleImageList->Draw(&cMemDC,
                                   0,
                                   CPoint(cSingleRect.left - cCompleteRect.left, cSingleRect.top - cCompleteRect.top),
                                   ILD_MASK);

            pSingleImageList->DeleteImageList();
            delete pSingleImageList;
        }
    }

    cMemDC.SelectObject(pOldMemDCBitmap);

    //
    // Create the image list with the merged drag images
    //
    CImageList* pCompleteImageList = DEBUG_NEW CImageList;

    pCompleteImageList->Create(cCompleteRect.Width(),
                               cCompleteRect.Height(),
                               ILC_COLOR | ILC_MASK, 0, 1);

    // Here green is used as mask color
    pCompleteImageList->Add(&cBitmap, RGB(0, 255, 0));

    //
    // as an optional service:
    // Find the offset of the current mouse cursor to the image list
    // this we can use in BeginDrag()
    //
    if (lpPoint) {
        lpPoint->x = cCompleteRect.left;
        lpPoint->y = cCompleteRect.top;
    }

    return pCompleteImageList;
}
Esempio n. 14
0
void CNOutBarCtrl::drawItemImage(CDC *pDC, int i, CRect &rc)
{
	int img = folders[selFolder]->items[i]->image;
	CImageList *imageList = (largeIconView ? largeIcons : smallIcons);
	imageList->Draw(pDC, img, rc.TopLeft(), ILD_TRANSPARENT);
}
Esempio n. 15
0
void CListCtrlEx::DrawItem(_In_ LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); 

	LVITEM lvi = {0}; 
	lvi.mask = LVIF_STATE|LVIF_IMAGE; 
	lvi.stateMask = LVIS_FOCUSED | LVIS_SELECTED ; 
	lvi.iItem = lpDrawItemStruct->itemID; 
	BOOL bGet = GetItem(&lvi); 

	BOOL bHighlight =((lvi.state & LVIS_DROPHILITED)||((lvi.state & LVIS_SELECTED) && 
		((GetFocus() == this)|| (GetStyle() & LVS_SHOWSELALWAYS)))); 

	// 画文本背景 
	CRect rcBack = lpDrawItemStruct->rcItem; 
	pDC->SetBkMode(TRANSPARENT); 
	if( lpDrawItemStruct->itemState&ODS_SELECTED && lvi.state & LVIS_SELECTED) //如果被选择
	{ 
		COLORREF ref=RGB(0,0,0);
		pDC->SetTextColor(ref); 
		pDC->SetBkColor(ref); 

		pDC->FillRect(rcBack, &CBrush(RGB( 0xff, 0xe4, 0x91 )/*0xEEDED4*/));
	} 
	else 
	{ 

		pDC->SetTextColor(RGB(0,0,0)); 
		pDC->FillRect(rcBack, &CBrush(0xFFFFFF/*0xEEF1E3*/));
	} 

	//设置字体颜色 
	CString str; 

	//得到焦点大小 
	CRect rcFocus = lpDrawItemStruct->rcItem; 
	rcFocus.DeflateRect(1,1,1,1); 

	INT nColumnCount = GetHeaderCtrl()->GetItemCount();

	if (lpDrawItemStruct->itemAction & ODA_DRAWENTIRE) 
	{ 
		LOGFONT lf;
		pDC->GetCurrentFont()->GetLogFont(&lf);

		lf.lfCharSet = GB2312_CHARSET;
		lf.lfHeight = 12;
		lf.lfWidth  = 0;
		lf.lfWeight = FW_NORMAL;
		strcpy_s(lf.lfFaceName,"宋体");

		CFont font;
		font.CreateFontIndirect(&lf);
		CFont *pOldFont = pDC->SelectObject(&font);

		//写文本 
		CString szText; 
		CSize si;
		for (int i = 0; i <nColumnCount; i++) 
		{ //循环得到文本 
			CRect rcItem; 
			if ( !GetSubItemRect(lpDrawItemStruct->itemID, i, LVIR_LABEL, rcItem )) 
				continue; 
			szText = GetItemText( lpDrawItemStruct->itemID, i ); 

			si = pDC->GetTextExtent(szText);
			rcItem.left += 5; rcItem.right -= 1;
			rcItem.top = (rcItem.bottom  + rcItem.top - si.cy)/2;
			pDC->DrawText(szText/*szText*/, lstrlen(szText), &rcItem, DT_NOPREFIX|DT_SINGLELINE); 
		}

		pDC->SelectObject(pOldFont);

		CImageList * pImageList = GetImageList(LVSIL_SMALL);
		if (pImageList)
		{
			CRect rcItem; 
			if (GetSubItemRect(lpDrawItemStruct->itemID,0, LVIR_ICON, rcItem ))
			{
				rcItem.top += 3;
				pImageList->Draw(pDC,lvi.iImage,rcItem.TopLeft(),TVSIL_NORMAL); // 在行首绘制图标
			}
		}
	} 
}
Esempio n. 16
0
void CTabCtrlEx::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
    if(lpDrawItemStruct->CtlType == ODT_TAB)
    {
        CRect rect = lpDrawItemStruct->rcItem;
        INT nTabIndex = lpDrawItemStruct->itemID;
        if (nTabIndex < 0) return;

        TCHAR label[64];
        TC_ITEM tci;
        tci.mask = TCIF_TEXT|TCIF_IMAGE;
        tci.pszText = label;
        tci.cchTextMax = 63;
        GetItem(nTabIndex, &tci );

        CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
        if (!pDC) return;
        int nSavedDC = pDC->SaveDC();

        //填充背景色
        COLORREF rcBack;
        if (lpDrawItemStruct->itemState & CDIS_SELECTED  )
            rcBack = RGB(255, 255,255);
        else if(lpDrawItemStruct->itemState & (CDIS_DISABLED | CDIS_GRAYED) )
            rcBack = RGB(0, 255, 0);
        else
            rcBack = GetSysColor(COLOR_BTNFACE);
        pDC->FillSolidRect(rect, rcBack);

        rect.top += ::GetSystemMetrics(SM_CYEDGE);

        pDC->SetBkMode(TRANSPARENT);

        //绘制图片
        CImageList *pImageList = GetImageList();
        if (pImageList && tci.iImage >= 0)
        {
            rect.left += pDC->GetTextExtent(_T(" ")).cx;       // Margin

            // Get height of image so we
            IMAGEINFO info;
            pImageList->GetImageInfo(tci.iImage, &info);
            CRect ImageRect(info.rcImage);
            INT nYpos = rect.top;

            pImageList->Draw(pDC, tci.iImage, CPoint(rect.left, nYpos), ILD_TRANSPARENT);
            rect.left += ImageRect.Width();
        }

        //绘制字体
        COLORREF txtColor;
        if (lpDrawItemStruct->itemState & CDIS_SELECTED  )
        {
            rect.top -= ::GetSystemMetrics(SM_CYEDGE);

            txtColor = RGB(0,0,255);
        }
        else if(lpDrawItemStruct->itemState & (CDIS_DISABLED | CDIS_GRAYED) )
            txtColor = RGB(128, 128, 128);
        else
            txtColor = GetSysColor(COLOR_WINDOWTEXT);
        pDC->SetTextColor(txtColor);
		int r=rect.right;
		rect.right-=15;
        pDC->DrawText(label, rect, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
		rect.right=r;
		rect.left=rect.right-17;
		rect.top+=3;
		rect.bottom-=6;
		pDC->DrawFrameControl(&rect,DFCS_CAPTIONCLOSE,DFCS_BUTTONPUSH);
        pDC->RestoreDC(nSavedDC);

    }
}
Esempio n. 17
0
void CClosableTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
	CRect rect(lpDIS->rcItem);
	int nTabIndex = lpDIS->itemID;
	if (nTabIndex < 0)
		return;

	TCHAR szLabel[256];
	TC_ITEM tci;
	tci.mask = TCIF_TEXT | TCIF_IMAGE | TCIF_STATE;
	tci.pszText = szLabel;
	tci.cchTextMax = _countof(szLabel);
	tci.dwStateMask = TCIS_HIGHLIGHTED;
	if (!GetItem(nTabIndex, &tci))
		return;
	//TRACE("CClosableTabCtrl::DrawItem: item=%u, state=%08x, color=%08x, rc=%3d,%3d,%3dx%3d\n", nTabIndex, tci.dwState, GetTextColor(lpDIS->hDC), lpDIS->rcItem.left, lpDIS->rcItem.top, lpDIS->rcItem.right - lpDIS->rcItem.left, lpDIS->rcItem.bottom - lpDIS->rcItem.top);

	CDC* pDC = CDC::FromHandle(lpDIS->hDC);
	if (!pDC)
		return;

	CRect rcFullItem(lpDIS->rcItem);
	bool bSelected = (lpDIS->itemState & ODS_SELECTED) != 0;

	///////////////////////////////////////////////////////////////////////////////////////
	// Adding support for XP Styles (Vista Themes) for owner drawn tab controls simply
	// does *not* work under Vista. Maybe it works under XP (did not try), but that is
	// meaningless because under XP a owner drawn tab control is already rendered *with*
	// the proper XP Styles. So, for XP there is no need to care about the theme API at all.
	//
	// However, under Vista, a tab control which has the TCS_OWNERDRAWFIXED
	// style gets additional 3D-borders which are applied by Vista *after* WM_DRAWITEM
	// was processed. Thus, there is no known workaround available to prevent Vista from
	// adding those old fashioned 3D-borders. We can render the tab control items within
	// the WM_DRAWITEM handler in whatever style we want, but Vista will in each case
	// overwrite the borders of each tab control item with old fashioned 3D-borders...
	//
	// To complete this experience, tab controls also do not support NMCUSTOMDRAW. So, the
	// only known way to customize a tab control is by using TCS_OWNERDRAWFIXED which does
	// however not work properly under Vista.
	//
	// The "solution" which is currently implemented to prevent Vista from drawing those
	// 3D-borders is by using "ExcludeClipRect" to reduce the drawing area which is used
	// by Windows after WM_DRAWITEM was processed. This "solution" is very sensitive to
	// the used rectangles and offsets in general. Incrementing/Decrementing one of the
	// "rcItem", "rcFullItem", etc. rectangles makes the entire "solution" flawed again
	// because some borders would become visible again.
	//
	HTHEME hTheme = NULL;
	int iPartId = TABP_TABITEM;
	int iStateId = TIS_NORMAL;
	bool bVistaHotTracked = false;
	bool bVistaThemeActive = theApp.IsVistaThemeActive();
	if (bVistaThemeActive)
	{
		// To determine if the current item is in 'hot tracking' mode, we need to evaluate
		// the current foreground color - there is no flag which would indicate this state 
		// more safely. This applies only for Vista and for tab controls which have the
		// TCS_OWNERDRAWFIXED style.
		bVistaHotTracked = pDC->GetTextColor() == GetSysColor(COLOR_HOTLIGHT);

		hTheme = g_xpStyle.OpenThemeData(m_hWnd, L"TAB");
		if (hTheme)
		{
			if (bSelected) {
				// get the real tab item rect
				rcFullItem.left += 1;
				rcFullItem.right -= 1;
				rcFullItem.bottom -= 1;
			}
			else
				rcFullItem.InflateRect(2, 2); // get the real tab item rect

			CRect rcBk(rcFullItem);
			if (bSelected)
			{
				iStateId = TTIS_SELECTED;
				if (nTabIndex == 0) {
					// First item
					if (nTabIndex == GetItemCount() - 1)
						iPartId = TABP_TOPTABITEMBOTHEDGE; // First & Last item
					else
						iPartId = TABP_TOPTABITEMLEFTEDGE;
				}
				else if (nTabIndex == GetItemCount() - 1) {
					// Last item
					iPartId = TABP_TOPTABITEMRIGHTEDGE;
				}
				else {
					iPartId = TABP_TOPTABITEM;
				}
			}
			else
			{
				rcBk.top += 2;
				iStateId = bVistaHotTracked ? TIS_HOT : TIS_NORMAL;
				if (nTabIndex == 0) {
					// First item
					if (nTabIndex == GetItemCount() - 1)
						iPartId = TABP_TABITEMBOTHEDGE; // First & Last item
					else
						iPartId = TABP_TABITEMLEFTEDGE;
				}
				else if (nTabIndex == GetItemCount() - 1) {
					// Last item
					iPartId = TABP_TABITEMRIGHTEDGE;
				}
				else {
					iPartId = TABP_TABITEM;
				}
			}
			if (g_xpStyle.IsThemeBackgroundPartiallyTransparent(hTheme, iPartId, iStateId))
				g_xpStyle.DrawThemeParentBackground(m_hWnd, *pDC, &rcFullItem);
			g_xpStyle.DrawThemeBackground(hTheme, *pDC, iPartId, iStateId, &rcBk, NULL);
		}
	}

	// Following background clearing is needed for:
	//	WinXP/Vista (when used without an application theme)
	//	Vista (when used with an application theme but without a theme for the tab control)
	if (   (!g_xpStyle.IsThemeActive() || !g_xpStyle.IsAppThemed())
		|| (hTheme == NULL && bVistaThemeActive) )
		pDC->FillSolidRect(&lpDIS->rcItem, GetSysColor(COLOR_BTNFACE));

	int iOldBkMode = pDC->SetBkMode(TRANSPARENT);

	// Draw image on left side
	CImageList *piml = GetImageList();
	if (tci.iImage >= 0 && piml && piml->m_hImageList)
	{
		IMAGEINFO ii;
		piml->GetImageInfo(0, &ii);
		rect.left += bSelected ? 8 : 4;
		piml->Draw(pDC, tci.iImage, CPoint(rect.left, rect.top + 2), ILD_TRANSPARENT);
		rect.left += (ii.rcImage.right - ii.rcImage.left);
		if (!bSelected)
			rect.left += 4;
	}

	bool bCloseable = m_bCloseable;
	if (bCloseable && GetParent()->SendMessage(UM_QUERYTAB, nTabIndex))
		bCloseable = false;

	// Draw 'Close button' at right side
	if (bCloseable && m_ImgLstCloseButton.m_hImageList)
	{
		CRect rcCloseButton;
		GetCloseButtonRect(nTabIndex, rect, rcCloseButton, bSelected, bVistaThemeActive);

		HTHEME hThemeNC = bVistaThemeActive ? g_xpStyle.OpenThemeData(m_hWnd, _T("WINDOW")) : NULL;
		if (hThemeNC) {
			// Possible "Close" parts: WP_CLOSEBUTTON, WP_SMALLCLOSEBUTTON, WP_MDICLOSEBUTTON
			int iPartId = WP_SMALLCLOSEBUTTON;
			int iStateId = (bSelected || bVistaHotTracked) ? CBS_NORMAL : CBS_DISABLED;
			if (g_xpStyle.IsThemeBackgroundPartiallyTransparent(hTheme, iPartId, iStateId))
				g_xpStyle.DrawThemeParentBackground(m_hWnd, *pDC, &rcCloseButton);
			g_xpStyle.DrawThemeBackground(hThemeNC, *pDC, iPartId, iStateId, rcCloseButton, NULL);
			g_xpStyle.CloseThemeData(hThemeNC);
		}
		else {
			m_ImgLstCloseButton.Draw(pDC, (bSelected || bVistaHotTracked) ? 0 : 1, rcCloseButton.TopLeft(), ILD_TRANSPARENT);
		}

		rect.right = rcCloseButton.left - 2;
		if (bSelected)
			rect.left += hTheme ? 4 : 2;
	}

	COLORREF crOldColor = CLR_NONE;
	if (tci.dwState & TCIS_HIGHLIGHTED)
		crOldColor = pDC->SetTextColor(RGB(192, 0, 0));
	else if (bVistaHotTracked)
		crOldColor = pDC->SetTextColor(GetSysColor(COLOR_BTNTEXT));

	rect.top += bSelected ? 4 : 3;
	// Vista: Tab control has troubles with determining the width of a tab if the
	// label contains one '&' character. To get around this, we use the old code which
	// replaces one '&' character with two '&' characters and we do not specify DT_NOPREFIX
	// here when drawing the text.
	//
	// Vista: "DrawThemeText" can not be used in case we need a certain foreground color. Thus we always us
	// "DrawText" to always get the same font and metrics (just for safety).
	pDC->DrawText(szLabel, rect, DT_SINGLELINE | DT_TOP | DT_CENTER /*| DT_NOPREFIX*/);

	if (crOldColor != CLR_NONE)
		pDC->SetTextColor(crOldColor);
	pDC->SetBkMode(iOldBkMode);

	if (hTheme)
	{
		CRect rcClip(rcFullItem);
		if (bSelected) {
			rcClip.left -= 2 + 1;
			rcClip.right += 2 + 1;
		}
		else {
			rcClip.top += 2;
		}
		pDC->ExcludeClipRect(&rcClip);
		g_xpStyle.CloseThemeData(hTheme);
	}
}
void CBCGPHeaderCtrl::OnDrawItem (CDC* pDC, int iItem, CRect rect, BOOL bIsPressed,
                                  BOOL bIsHighlighted)
{
    ASSERT_VALID (this);
    ASSERT_VALID (pDC);

    const int nTextMargin = 5;

    //-------------
    // Draw border:
    //-------------
    CBCGPVisualManager::GetInstance ()->OnDrawHeaderCtrlBorder (this, pDC,
            rect, bIsPressed, bIsHighlighted);

    if (iItem < 0)
    {
        return;
    }

    int nSortVal = 0;
    if (m_mapColumnsStatus.Lookup (iItem, nSortVal) &&
            nSortVal != 0)
    {
        //-----------------
        // Draw sort arrow:
        //-----------------
        CRect rectArrow = rect;
        rectArrow.DeflateRect (5, 5);
        rectArrow.left = rectArrow.right - rectArrow.Height ();

        if (bIsPressed)
        {
            rectArrow.right++;
            rectArrow.bottom++;
        }

        rect.right = rectArrow.left - 1;

        int dy2 = (int) (.134 * rectArrow.Width ());
        rectArrow.DeflateRect (0, dy2);

        m_bAscending = nSortVal > 0;
        OnDrawSortArrow (pDC, rectArrow);
    }

    HD_ITEM hdItem;
    memset (&hdItem, 0, sizeof (hdItem));
    hdItem.mask = HDI_FORMAT | HDI_BITMAP | HDI_TEXT | HDI_IMAGE;

    TCHAR szText [256];
    hdItem.pszText = szText;
    hdItem.cchTextMax = 255;

    if (!GetItem (iItem, &hdItem))
    {
        return;
    }

    //-----------------------
    // Draw bitmap and image:
    //-----------------------
    if ((hdItem.fmt & HDF_IMAGE) && hdItem.iImage >= 0)
    {
        // By Max Khiszinsky:

        //---------------------------------------
        // The column has a image from imagelist:
        //---------------------------------------
        CImageList* pImageList = GetImageList ();
        if (pImageList != NULL)
        {
            int cx = 0;
            int cy = 0;

            VERIFY (::ImageList_GetIconSize (*pImageList, &cx, &cy));

            CPoint pt = rect.TopLeft ();
            pt.x ++;
            pt.y = (rect.top + rect.bottom - cy) / 2;

            VERIFY (pImageList->Draw (pDC, hdItem.iImage, pt, ILD_NORMAL));

            rect.left += cx;
        }
    }

    if ((hdItem.fmt & (HDF_BITMAP | HDF_BITMAP_ON_RIGHT)) && hdItem.hbm != NULL)
    {
        CBitmap* pBmp = CBitmap::FromHandle (hdItem.hbm);
        ASSERT_VALID (pBmp);

        BITMAP bmp;
        pBmp->GetBitmap (&bmp);

        CRect rectBitmap = rect;
        if (hdItem.fmt & HDF_BITMAP_ON_RIGHT)
        {
            rectBitmap.right--;
            rect.right = rectBitmap.left = rectBitmap.right - bmp.bmWidth;
        }
        else
        {
            rectBitmap.left++;
            rect.left = rectBitmap.right = rectBitmap.left + bmp.bmWidth;
        }

        rectBitmap.top += max (0, (rectBitmap.Height () - bmp.bmHeight) / 2);
        rectBitmap.bottom = rectBitmap.top + bmp.bmHeight;

        pDC->DrawState (rectBitmap.TopLeft (), rectBitmap.Size (), pBmp, DSS_NORMAL);
    }

    //-----------
    // Draw text:
    //-----------
    if (hdItem.fmt & HDF_STRING)
    {
        COLORREF clrText = 	CBCGPVisualManager::GetInstance ()->GetHeaderCtrlTextColor (this, bIsPressed, bIsHighlighted);
        COLORREF clrTextOld = (COLORREF)-1;
        if (clrText != (COLORREF)-1)
        {
            clrTextOld = pDC->SetTextColor (clrText);
        }

        CRect rectLabel = rect;
        rectLabel.DeflateRect (nTextMargin, 0);

        CString strLabel = hdItem.pszText;

        UINT uiTextFlags = DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX;
        if (hdItem.fmt & HDF_CENTER)
        {
            uiTextFlags |= DT_CENTER;
        }
        else if (hdItem.fmt & HDF_RIGHT)
        {
            uiTextFlags |= DT_RIGHT;
        }

        pDC->DrawText (strLabel, rectLabel, uiTextFlags);

        if (clrText != (COLORREF)-1)
        {
            pDC->SetTextColor (clrTextOld);
        }
    }
}
//------------------------------------------------------------------------
//! Appends the checkbox state images to the list control image list
//!
//! @param owner The list control adding column
//! @param imagelist The image list assigned to the list control
//! @return Image index where the two state images (unchecked/checked) was inserted
//------------------------------------------------------------------------
int CGridColumnTraitImage::AppendStateImages(CGridListCtrlEx& owner, CImageList& imagelist)
{
	if (!(owner.GetExtendedStyle() & LVS_EX_SUBITEMIMAGES))
		owner.SetExtendedStyle(owner.GetExtendedStyle() | LVS_EX_SUBITEMIMAGES);

	if (!imagelist)
		imagelist.Create(16, 16, ILC_COLOR16 | ILC_MASK, 1, 0);

	if (!owner.GetImageList(LVSIL_SMALL))
		owner.SetImageList(&imagelist, LVSIL_SMALL);

	VERIFY(owner.GetImageList(LVSIL_SMALL) == &imagelist);

	bool createdStateImages = false;
	CImageList* pStateList = owner.GetImageList(LVSIL_STATE);
	if (pStateList == NULL)
	{
		if (!(owner.GetExtendedStyle() & LVS_EX_CHECKBOXES))
		{
			createdStateImages = true;
			owner.SetExtendedStyle(owner.GetExtendedStyle() | LVS_EX_CHECKBOXES);
			pStateList = owner.GetImageList(LVSIL_STATE);
		}
	}
	int imageCount = -1;
	ASSERT(pStateList != NULL);
	if (pStateList != NULL && pStateList->GetImageCount() >= 2)
	{
		imageCount = imagelist.GetImageCount();

		// Get the icon size of current imagelist
		CSize iconSize(16, 16);
		if (imageCount > 0)
		{
			IMAGEINFO iconSizeInfo = { 0 };
			VERIFY(imagelist.GetImageInfo(0, &iconSizeInfo));
			iconSize =
				CSize(iconSizeInfo.rcImage.right - iconSizeInfo.rcImage.left,
					iconSizeInfo.rcImage.bottom - iconSizeInfo.rcImage.top);
		}

		// Scale the icon-position if necessary
		CPoint iconPos(1, 0); // +1 pixel to avoid overlap with left-grid-line
		{
			IMAGEINFO stateSizeInfo = { 0 };
			VERIFY(pStateList->GetImageInfo(0, &stateSizeInfo));
			int stateIconHeight = stateSizeInfo.rcImage.bottom - stateSizeInfo.rcImage.top;
			if (iconSize.cy > stateIconHeight)
				iconPos.y = (iconSize.cy - stateIconHeight) / 2;
		}

		// Redraw the state-icon to match the icon size of the current imagelist (without scaling image)
		CClientDC clienDC(&owner);
		CDC memDC;
		VERIFY(memDC.CreateCompatibleDC(&clienDC));
		CBitmap dstBmp;
		VERIFY(dstBmp.CreateCompatibleBitmap(&clienDC, iconSize.cx, iconSize.cy));

		CBitmap* pBmpOld = memDC.SelectObject(&dstBmp);
		COLORREF oldBkColor = pStateList->SetBkColor(imagelist.GetBkColor());
		CBrush brush(imagelist.GetBkColor());
		memDC.FillRect(CRect(0, 0, iconSize.cx, iconSize.cy), &brush);
		VERIFY(pStateList->Draw(&memDC, 0, iconPos, ILD_NORMAL));
		memDC.SelectObject(pBmpOld);
		VERIFY(imagelist.Add(&dstBmp, oldBkColor) != -1);
		pBmpOld = memDC.SelectObject(&dstBmp);
		memDC.FillRect(CRect(0, 0, iconSize.cx, iconSize.cy), &brush);
		VERIFY(pStateList->Draw(&memDC, 1, iconPos, ILD_NORMAL));
		memDC.SelectObject(pBmpOld);
		VERIFY(imagelist.Add(&dstBmp, oldBkColor) != -1);
		pStateList->SetBkColor(oldBkColor);
	}
	if (createdStateImages)
		owner.SetExtendedStyle(owner.GetExtendedStyle() & ~LVS_EX_CHECKBOXES);

	return imageCount;
}
Esempio n. 20
0
void
MFCSimpleTypeView::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	int			m_bClientWidthSel = TRUE;
	int			m_cxClient = 0;
	int			m_cxStateImageOffset = 0;
	COLORREF	m_clrText = ::GetSysColor(COLOR_WINDOWTEXT);
	COLORREF	m_clrTextBk = ::GetSysColor(COLOR_WINDOW);
	COLORREF	m_clrBkgnd = ::GetSysColor(COLOR_WINDOW);

	CListCtrl& listCtrl=GetListCtrl();
	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	CRect rcItem(lpDrawItemStruct->rcItem);
	UINT uiFlags = ILD_TRANSPARENT;
	CImageList* pImageList;
	int nItem = lpDrawItemStruct->itemID;
	BOOL bFocus = (GetFocus() == this);
	COLORREF clrTextSave, clrBkSave;
	COLORREF clrImage = m_clrBkgnd;
	static _TCHAR szBuff[MAX_PATH];
	LPCTSTR pszText;

	StabEnt			*itemSym = SymForItem(nItem);
// get item data

	LV_ITEM lvi;
	lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
	lvi.iItem = nItem;
	lvi.iSubItem = 0;
	lvi.pszText = szBuff;
	lvi.cchTextMax = sizeof(szBuff);
	lvi.stateMask = 0xFFFF;     // get all state flags
	listCtrl.GetItem(&lvi);

	BOOL bSelected = (bFocus || (GetStyle() & LVS_SHOWSELALWAYS)) && lvi.state & LVIS_SELECTED;
	bSelected = bSelected || (lvi.state & LVIS_DROPHILITED);

// set colors if item is selected

	CRect rcAllLabels;
	listCtrl.GetItemRect(nItem, rcAllLabels, LVIR_BOUNDS);

	CRect rcLabel;
	listCtrl.GetItemRect(nItem, rcLabel, LVIR_BOUNDS);
//	listCtrl.GetItemRect(nItem, rcLabel, LVIR_LABEL);

	rcAllLabels.left = rcLabel.left;
	if (m_bClientWidthSel && rcAllLabels.right<m_cxClient)
		rcAllLabels.right = m_cxClient;

	if (bSelected)	{
		clrTextSave = pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
		clrBkSave = pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));

		pDC->FillRect(rcAllLabels, &CBrush(::GetSysColor(COLOR_HIGHLIGHT)));
	}
	else
		pDC->FillRect(rcAllLabels, &CBrush(m_clrTextBk));

// set color and mask for the icon

	if (lvi.state & LVIS_CUT)	{
		clrImage = m_clrBkgnd;
		uiFlags |= ILD_BLEND50;
	}	else if (bSelected) {
		clrImage = ::GetSysColor(COLOR_HIGHLIGHT);
		uiFlags |= ILD_BLEND50;
	}

// draw state icon

	UINT nStateImageMask = lvi.state & LVIS_STATEIMAGEMASK;
	if (nStateImageMask)	{
		int nImage = (nStateImageMask>>12) - 1;
		pImageList = listCtrl.GetImageList(LVSIL_STATE);
		if (pImageList)		{
			pImageList->Draw(pDC, nImage,
				CPoint(rcItem.left, rcItem.top), ILD_TRANSPARENT);
		}
	}

// draw normal and overlay icon

/*
	CRect rcIcon;
	ListCtrl.GetItemRect(nItem, rcIcon, LVIR_ICON);

	pImageList = listCtrl.GetImageList(LVSIL_SMALL);
	if (pImageList)	{
		UINT nOvlImageMask=lvi.state & LVIS_OVERLAYMASK;
		if (rcItem.left<rcItem.right-1)		{
			ImageList_DrawEx(pImageList->m_hImageList, lvi.iImage,
					pDC->m_hDC,rcIcon.left,rcIcon.top, 16, 16,
					m_clrBkgnd, clrImage, uiFlags | nOvlImageMask);
		}
	}
*/

// draw item label

//	listCtrl.GetItemRect(nItem, rcItem, LVIR_LABEL);
	LV_COLUMN lvc;
	lvc.mask = LVCF_FMT | LVCF_WIDTH;

	listCtrl.GetItemRect(nItem, rcItem, LVIR_BOUNDS);
	listCtrl.GetColumn(0, &lvc); 

	rcItem.right = lvc.cx;

//	pszText = MakeShortString(pDC, szBuff,
//				rcItem.right-rcItem.left, 2*OFFSET_FIRST);
	pszText = szBuff;

	rcLabel = rcItem;
	rcLabel.left += OFFSET_FIRST;
	rcLabel.right -= OFFSET_FIRST;


	pDC->SetTextColor(rgb_black);
	pDC->DrawText(pszText,-1,rcLabel,DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);

// draw labels for extra columns
	if (itemSym) {
		UINT nOvlImageMask=lvi.state & LVIS_OVERLAYMASK;
// type
		listCtrl.GetColumn(1, &lvc); 
		rcItem.left = rcItem.right;
		rcItem.right += lvc.cx;

		rcLabel = rcItem;
		rcLabel.left += OFFSET_OTHER;
		rcLabel.right -= OFFSET_OTHER;

		string tnm = findTypeName(itemSym->type);
		if (tnm.size()) {
			pDC->SetTextColor(rgb_blue);
			long h = pDC->DrawText(tnm.c_str() , -1, rcLabel, DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);
		}
// length
		listCtrl.GetColumn(2, &lvc); 
		rcItem.left = rcItem.right;
		rcItem.right += lvc.cx;
//		fprintf(stderr, "%d %d %d\n", pszText, itemSym->type, lvc.cx);

		rcLabel = rcItem;
		rcLabel.left += OFFSET_OTHER;
		rcLabel.right -= OFFSET_OTHER;

		if (itemSym->indirection > 0) {
			char	buf[120];
			buf[0] = 0;
			for (short i=1; i<itemSym->indirection; i++) {
				char	nbuf[10];
				sprintf(nbuf, "%s%d", i>1?",":"",itemSym->size[i]);
				strcat(buf, nbuf);
			}
			pDC->SetTextColor(rgb_blue);
			pDC->DrawText(buf, -1, rcLabel,
				DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);
		}
// controller
		listCtrl.GetColumn(3, &lvc); 
		rcItem.left = rcItem.right;
		rcItem.right += lvc.cx;
		if (itemSym->controlMode != StabEnt::DISPLAY_NOT) {
			ImageList_DrawEx(images,
					itemSym->controlMode == StabEnt::DISPLAY_CTL ? 0 :
						itemSym->controlMode == StabEnt::DISPLAY_DISP? 2 : 0,
					pDC->m_hDC,rcItem.left,rcItem.top, 16, 16,
					m_clrBkgnd, clrImage, uiFlags | nOvlImageMask);
		}
// envelope
		listCtrl.GetColumn(4, &lvc); 
		rcItem.left = rcItem.right;
		rcItem.right += lvc.cx;
		if (itemSym->isEnveloped) {
			ImageList_DrawEx(images, 1 /* which one */,
					pDC->m_hDC,rcItem.left,rcItem.top, 16, 16,
					m_clrBkgnd, clrImage, uiFlags | nOvlImageMask);
		}
	}
/*
	for(int nColumn = 1; listCtrl.GetColumn(nColumn, &lvc); nColumn++)	{
		rcItem.left = rcItem.right;
		rcItem.right += lvc.cx;

		int nRetLen = listCtrl.GetItemText(nItem, nColumn,	szBuff, sizeof(szBuff));
		if (nRetLen == 0)
			continue;

//		pszText = MakeShortString(pDC, szBuff,
//			rcItem.right - rcItem.left, 2*OFFSET_OTHER);

		pszText = szBuff;

		UINT nJustify = DT_LEFT;

		if(pszText == szBuff) {
			switch(lvc.fmt & LVCFMT_JUSTIFYMASK) {
			case LVCFMT_RIGHT:
				nJustify = DT_RIGHT;
				break;
			case LVCFMT_CENTER:
				nJustify = DT_CENTER;
				break;
			default:
				break;
			}
		}

		rcLabel = rcItem;
		rcLabel.left += OFFSET_OTHER;
		rcLabel.right -= OFFSET_OTHER;

		pDC->DrawText(pszText, -1, rcLabel,
			nJustify | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);
	}*/

// draw focus rectangle if item has focus

	if (lvi.state & LVIS_FOCUSED && bFocus)
		pDC->DrawFocusRect(rcAllLabels);

// set original colors if item was selected

	if (bSelected) {
		pDC->SetTextColor(clrTextSave);
		pDC->SetBkColor(clrBkSave);
	}
}
Esempio n. 21
0
void CListCtrlEx::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	CRect rcItem(lpDrawItemStruct->rcItem);
	UINT uiFlags = ILD_TRANSPARENT;
	CImageList* pImageList;
	int nItem = lpDrawItemStruct->itemID;
	BOOL bFocus = (GetFocus() == this);
	COLORREF clrTextSave, clrBkSave;
	COLORREF clrImage = m_clrBkgnd;
	static _TCHAR szBuff[MAX_PATH];
	LPCTSTR pszText;

// get item data

	LV_ITEM lvi;
	lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
	lvi.iItem = nItem;
	lvi.iSubItem = 0;
	lvi.pszText = szBuff;
	lvi.cchTextMax = sizeof(szBuff);
	lvi.stateMask = 0xFFFF;     // get all state flags
	GetItem(&lvi);

	BOOL bSelected = (bFocus || (GetStyle() & LVS_SHOWSELALWAYS)) && lvi.state & LVIS_SELECTED;
	bSelected = bSelected || (lvi.state & LVIS_DROPHILITED);

// set colors if item is selected

	CRect rcAllLabels;
	GetItemRect(nItem, rcAllLabels, LVIR_BOUNDS);

	CRect rcLabel;
	GetItemRect(nItem, rcLabel, LVIR_LABEL);

	rcAllLabels.left = rcLabel.left;
	if (m_bClientWidthSel && rcAllLabels.right<m_cxClient)
		rcAllLabels.right = m_cxClient;

	// @@
	clrTextSave = pDC->SetTextColor(colTextColor[0]);	
	
	if (bSelected)
	{
		//@@
		//clrTextSave = pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
		clrBkSave = pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));

		pDC->FillRect(rcAllLabels, &CBrush(::GetSysColor(COLOR_HIGHLIGHT)));
	}
	else
		pDC->FillRect(rcAllLabels, &CBrush(m_clrTextBk));

// set color and mask for the icon

	if (lvi.state & LVIS_CUT)
	{
		clrImage = m_clrBkgnd;
		uiFlags |= ILD_BLEND50;
	}
	else if (bSelected)
	{
		clrImage = ::GetSysColor(COLOR_HIGHLIGHT);
		uiFlags |= ILD_BLEND50;
	}

// draw state icon

	UINT nStateImageMask = lvi.state & LVIS_STATEIMAGEMASK;
	if (nStateImageMask)
	{
		int nImage = (nStateImageMask>>12) - 1;
		pImageList = GetImageList(LVSIL_STATE);
		if (pImageList)
		{
			pImageList->Draw(pDC, nImage,
				CPoint(rcItem.left, rcItem.top), ILD_TRANSPARENT);
		}
	}

// draw normal and overlay icon

	CRect rcIcon;
	GetItemRect(nItem, rcIcon, LVIR_ICON);

	pImageList = GetImageList(LVSIL_SMALL);
	if (pImageList)
	{
		UINT nOvlImageMask=lvi.state & LVIS_OVERLAYMASK;
		if (rcItem.left<rcItem.right-1)
		{
			ImageList_DrawEx(pImageList->m_hImageList, lvi.iImage,
					pDC->m_hDC,rcIcon.left,rcIcon.top, 16, 16,
					m_clrBkgnd, clrImage, uiFlags | nOvlImageMask);
		}
	}

// draw item label

	GetItemRect(nItem, rcItem, LVIR_LABEL);
	rcItem.right -= m_cxStateImageOffset;

	pszText = MakeShortString(pDC, szBuff,
				rcItem.right-rcItem.left, 2*OFFSET_FIRST);

	rcLabel = rcItem;
	rcLabel.left += OFFSET_FIRST;
	rcLabel.right -= OFFSET_FIRST;

	pDC->DrawText(pszText,-1,rcLabel,DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);

// draw labels for extra columns

	LV_COLUMN lvc;
	lvc.mask = LVCF_FMT | LVCF_WIDTH;

	for(int nColumn = 1; GetColumn(nColumn, &lvc); nColumn++)
	{
		rcItem.left = rcItem.right;
		rcItem.right += lvc.cx;

		int nRetLen = GetItemText(nItem, nColumn,
						szBuff, sizeof(szBuff));
		if (nRetLen == 0)
			continue;

		pszText = MakeShortString(pDC, szBuff,
			rcItem.right - rcItem.left, 2*OFFSET_OTHER);

		UINT nJustify = DT_LEFT;

		if(pszText == szBuff)
		{
			switch(lvc.fmt & LVCFMT_JUSTIFYMASK)
			{
			case LVCFMT_RIGHT:
				nJustify = DT_RIGHT;
				break;
			case LVCFMT_CENTER:
				nJustify = DT_CENTER;
				break;
			default:
				break;
			}
		}

		rcLabel = rcItem;
		rcLabel.left += OFFSET_OTHER;
		rcLabel.right -= OFFSET_OTHER;

		if (nColumn < NR_COL_COLORS)
			pDC->SetTextColor(colTextColor[nColumn]);

		pDC->DrawText(pszText, -1, rcLabel,
			nJustify | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);
	}

// draw focus rectangle if item has focus

	if (lvi.state & LVIS_FOCUSED && bFocus)
		pDC->DrawFocusRect(rcAllLabels);

// set original colors if item was selected

	if (bSelected)
	{
		pDC->SetTextColor(clrTextSave);
		pDC->SetBkColor(clrBkSave);
	}
}
Esempio n. 22
0
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Behandlungsroutinen für Nachrichten CListCtrlEx 
void CListCtrlEx::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
   CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);

   CRect rcItem(lpDrawItemStruct->rcItem);

   BOOL bFocus = (GetFocus() == this);
   COLORREF clrTextSave = 0;
   COLORREF clrBkSave = 0;
   static _TCHAR szBuff[MAX_PATH];
   
   // get item data
   
   int nItem = lpDrawItemStruct->itemID;
   LV_ITEM lvi;
   lvi.mask = LVIF_IMAGE | LVIF_STATE;
   lvi.iItem = nItem;
   lvi.iSubItem = 1;
   lvi.pszText = szBuff;
   lvi.cchTextMax = sizeof(szBuff);
   lvi.stateMask = 0xFFFF;     // get all state flags
   GetItem(&lvi);
   
   BOOL bSelected = (bFocus || (GetStyle() & LVS_SHOWSELALWAYS)) && lvi.state & LVIS_SELECTED;
   bSelected = bSelected || (lvi.state & LVIS_DROPHILITED);
   
   // set colors if item is selected
   
   CRect rcAllLabels;
   GetItemRect(nItem, rcAllLabels, LVIR_BOUNDS);
   
   if (bSelected)
   {
      clrTextSave = pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
      clrBkSave = pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
      CBrush cbr(::GetSysColor(COLOR_HIGHLIGHT));
      pDC->FillRect(rcAllLabels, &cbr);
   }
   else
   {
      CBrush cbr(RGB(255, 255, 255));
      pDC->FillRect(rcAllLabels, &cbr);
   }
   
   // draw state icon///////////////////////////////////////////////////////////////////////
   LV_COLUMN lvc;
   lvc.mask = LVCF_FMT | LVCF_WIDTH;
   
   GetColumn(0, &lvc);
   
   UINT nStateImageMask = lvi.state & LVIS_STATEIMAGEMASK;
   if (nStateImageMask)
   {
      int nImage = (nStateImageMask>>12) - 1;

      CImageList* pImageList = GetImageList(LVSIL_STATE);
      if (pImageList)
      {
         rcItem.left += lvc.cx;
         pImageList->Draw(pDC, nImage,
            CPoint(rcItem.left+8, rcItem.top), ILD_TRANSPARENT);
      }
   }
   
   int nColumn = 0; 
   GetColumn(nColumn, &lvc);
   
   GetItemRect(nItem, rcAllLabels, LVIR_BOUNDS);
   
   int nRetLen = GetItemText(nItem, nColumn,szBuff, sizeof(szBuff));
   if (nRetLen == 0)
      return;
   
   UINT nJustify = DT_LEFT;
   
   CRect rcText;
   rcText = rcAllLabels;
   rcText.left += OFFSET_OTHER;
   rcText.right -= OFFSET_OTHER;
   
   pDC->DrawText(szBuff, -1, rcText,
      nJustify | DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER);
   
   // draw focus rectangle if item has focus
   
   if (lvi.state & LVIS_FOCUSED && bFocus)
   {
      pDC->DrawFocusRect(rcAllLabels);
   }
   
   // set original colors if item was selected
   
   if (bSelected)
   {
      pDC->SetTextColor(clrTextSave);
      pDC->SetBkColor(clrBkSave);
   }
   
}
Esempio n. 23
0
void CMyListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
    int     nItem = lpDrawItemStruct->itemID, nOffset;
    CDC     *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
    CRect   rcItem(lpDrawItemStruct->rcItem), rcHighlight;
    CRect   rcBounds, rcLabel, rcIcon, rcSub, rcColumn;
    BOOL    bHighlight;
    CString strLabel;
    CImageList* pImageList;

    // DC 상태 저장
    int     nSavedDC = pDC->SaveDC();
    UINT    nJustify;
    CBrush  brush;

    LV_ITEM lvi;
    lvi.mask      = LVIF_IMAGE | LVIF_STATE;
    lvi.iItem     = nItem;
    lvi.iSubItem  = 0;
    lvi.stateMask = 0xFFFF;
    GetItem(&lvi);

    // 아이템의 선택여부 조사
    bHighlight =((lvi.state & LVIS_DROPHILITED) ||
                 ((lvi.state & LVIS_SELECTED) &&
                 ((GetFocus() == this) ||
                 (GetStyle() & LVS_SHOWSELALWAYS))));

    // 그릴 영역을 구함
    GetItemRect(nItem, rcBounds, LVIR_BOUNDS);
    GetItemRect(nItem, rcLabel,  LVIR_LABEL);
    GetItemRect(nItem, rcIcon,   LVIR_ICON);
    rcColumn = rcBounds;

    strLabel = GetItemText(nItem, 0);
    nOffset  = (pDC->GetTextExtent(_T(" "), 1).cx) << 1;
    rcHighlight      = rcBounds;
    rcHighlight.left = rcLabel.left;

    // Background를 그린다
    pDC->SetBkMode(TRANSPARENT);
    if(bHighlight)
    {
        brush.CreateSolidBrush(m_colorBackHighlight);
        pDC->SetTextColor(m_colorTextHighlight);
        pDC->FillRect(rcHighlight, &brush);
    }
    else
    {
        brush.CreateSolidBrush(nItem % 2 ? m_colorBackOdd : m_colorBackEven);
        pDC->FillRect(rcBounds, &brush);
    }
    if(brush.m_hObject)
        brush.DeleteObject();

    rcColumn.right = rcColumn.left + GetColumnWidth(0);

    // State Icon을 그린다
    if(lvi.state & LVIS_STATEIMAGEMASK)
    {
        int nImage = ((lvi.state & LVIS_STATEIMAGEMASK) >> 12) - 1;
        pImageList = GetImageList(LVSIL_STATE);
        if(pImageList)
        {
            pImageList->Draw(pDC, nImage, CPoint(rcColumn.left, rcColumn.top), 
                             ILD_TRANSPARENT);
        }
    }
Esempio n. 24
0
//------------------------------------------------------------------------
//! Overrides the custom draw handler, to allow custom coloring of rows.
//!		- Fix white background for icon images
//!		- Fix white background between icon and cell text
//!
//! @param owner The list control drawing
//! @param pLVCD Pointer to NMLVCUSTOMDRAW structure
//! @param pResult Modification to the drawing stage (CDRF_NEWFONT, etc.)
//------------------------------------------------------------------------
void CGridRowTraitXP::OnCustomDraw(CGridListCtrlEx& owner, NMLVCUSTOMDRAW* pLVCD, LRESULT* pResult)
{
	if (owner.UsingVisualStyle())
	{
		// Perform standard drawing
		CGridRowTraitText::OnCustomDraw(owner, pLVCD, pResult);
		return;
	}
	
	// We are using classic- or XP-style
	int nRow = (int)pLVCD->nmcd.dwItemSpec;

	// Repair the standard drawing
	switch (pLVCD->nmcd.dwDrawStage)
	{
		case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
		{
			// We want to fix cell images
			*pResult |= CDRF_NOTIFYPOSTPAINT;
		} break;

		case CDDS_ITEMPOSTPAINT | CDDS_SUBITEM:
		{
			// Fix CListCtrl selection drawing bug with white background for icon image
			// Fix CListCtrl selection drawing bug with white margin between icon and text
			int nCol = pLVCD->iSubItem;

			if (CRect(pLVCD->nmcd.rc)==CRect(0,0,0,0))
				break;

			int nImage = owner.GetCellImage(nRow, nCol);
			if (nImage == I_IMAGECALLBACK)
				break;
				
			CImageList* pImageList = owner.GetImageList(LVSIL_SMALL);
			if (pImageList==NULL)
				break;

			COLORREF backColor = COLORREF(-1);
			if (owner.GetExtendedStyle() & LVS_EX_TRACKSELECT && owner.GetHotItem()==nRow)
			{
#if(WINVER >= 0x0500)
				backColor = ::GetSysColor(COLOR_HOTLIGHT);
#else
				if (owner.IsRowSelected(nRow))
					backColor = ::GetSysColor(COLOR_HIGHLIGHT);
				else
					break;
#endif
			}
			else
			if (owner.IsRowSelected(nRow))
			{
				if (!(owner.GetExtendedStyle() & LVS_EX_FULLROWSELECT))
					break;	// No drawing of selection color without full-row-select

				if (m_InvertCellSelection && owner.GetFocusRow()==nRow && owner.GetFocusCell()==nCol)
				{
					// No drawing of selection color for focus cell
					if (pLVCD->clrTextBk > RGB(255,255,255))
						break;

					backColor = pLVCD->clrTextBk;
				}
				else
				{
					if (owner.GetFocus()!=&owner && !owner.IsCellEditorOpen())
					{
						// Selection color is different when not having focus
						if (owner.GetStyle() & LVS_SHOWSELALWAYS)
							backColor = ::GetSysColor(COLOR_BTNFACE);
						else
							break;	// no drawing of selection color when not in focus
					}
					else
					{
						backColor = ::GetSysColor(COLOR_HIGHLIGHT);
					}
				}
			}
			else
			{
				// Redraw with the given background color
				if (pLVCD->clrTextBk > RGB(255,255,255))
					break;	// If a color is more than white, then it is invalid

				backColor = pLVCD->clrTextBk;
			}

			CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc);

			CRect rcIcon, rcCell;
			VERIFY( owner.GetCellRect(nRow, nCol, LVIR_ICON, rcIcon) );
			VERIFY( owner.GetCellRect(nRow, nCol, LVIR_BOUNDS, rcCell) );
			// When the label column is placed first it has a left-margin 
			if (nCol==0 && nCol==owner.GetFirstVisibleColumn())
			{
				int cxborder = ::GetSystemMetrics(SM_CXBORDER);
				rcCell.left += cxborder*2;
			}

			// Remove white margin between cell-image and cell-text
			rcCell.right = rcIcon.right + 2;
			CBrush brush(backColor);
			pDC->FillRect(&rcCell, &brush);

			// Draw icon
			COLORREF oldBkColor = pImageList->SetBkColor(backColor);
			pImageList->Draw (	pDC,  
								nImage,  
								rcIcon.TopLeft(),
								ILD_NORMAL );
			pImageList->SetBkColor(oldBkColor);

			if (nCol==0 && owner.GetExtendedStyle() & LVS_EX_CHECKBOXES)
			{
				CImageList* pStateImageList = owner.GetImageList(LVSIL_STATE);
				if (pImageList==NULL)
					break;

				int checkState = owner.GetCheck(nRow);
				COLORREF oldStateBkColor = pStateImageList->SetBkColor(backColor);
				pStateImageList->Draw (	pDC,  
									checkState,  
									rcCell.TopLeft(),
									ILD_NORMAL );
				pStateImageList->SetBkColor(oldStateBkColor);
			}

		} break;
	}

	// Perform standard drawing
	CGridRowTraitText::OnCustomDraw(owner, pLVCD, pResult);
}
Esempio n. 25
0
void CClickList::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	static const COLORREF 
		COLOR_1 = RGB(239, 246, 249),
		COLOR_2 = RGB(209, 226, 239);

	ASSERT(NULL != lpDrawItemStruct);
	ASSERT(NULL != lpDrawItemStruct->hDC);

	CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	ASSERT_VALID(pDC);
	// The CWinApp idle-time handler will automatically call
	// CDC::DeleteTempMap to delete any temporary CDC objects
	// created by FromHandle

	CRect rcItem(lpDrawItemStruct->rcItem);	
	int nItem = lpDrawItemStruct->itemID;
	int nSavedDC = pDC->SaveDC();

	// Get item image and state info
	LV_ITEM lvi;
	lvi.mask      = LVIF_IMAGE | LVIF_STATE;	
	lvi.iItem     = nItem;	
	lvi.iSubItem  = 0;
	lvi.stateMask = -1;
	GetItem(&lvi);

	// Should the item be highlighted
	bool bHighlight = LVIS_DROPHILITED == (lvi.state & LVIS_DROPHILITED) || 
		LVIS_SELECTED == (lvi.state & LVIS_SELECTED) && (this == GetFocus() || 
		LVS_SHOWSELALWAYS == (GetStyle() & LVS_SHOWSELALWAYS));

	// Get rectangles for drawing	
	CRect rcBounds, rcLabel, rcIcon;
	GetItemRect(nItem, rcBounds, LVIR_BOUNDS);
	GetItemRect(nItem, rcLabel,  LVIR_LABEL);
	GetItemRect(nItem, rcIcon,   LVIR_ICON);
	CRect rcCol(rcBounds);
	CString sLabel = GetItemText(nItem, 0);

	// Labels are offset by a certain amount  
	// This offset is related to the width of a space character
	int offset = pDC->GetTextExtent(_T(" "), 1 ).cx * 2;

	CRect rcHighlight;
	CRect rcWnd;
	int   nExt;

	switch (m_HighlightType) {
		case HT_NORMAL: 
			nExt = pDC->GetOutputTextExtent(sLabel).cx + offset;
			rcHighlight = rcLabel;
			if (rcLabel.left + nExt < rcLabel.right)
				rcHighlight.right = rcLabel.left + nExt;
			break;	
		
		case HT_ALLCOLUMNS:
			rcHighlight = rcBounds;
			rcHighlight.left = rcLabel.left;
			break;

		case HT_ROW:
			GetClientRect(&rcWnd);
			rcHighlight       = rcBounds;
			rcHighlight.left  = rcLabel.left;
			rcHighlight.right = rcWnd.right;
			break;

		default:
			ASSERT(false);
	}

	// Draw the background color
	if (bHighlight)	{
		pDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
		pDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
		pDC->FillRect(rcHighlight, &CBrush(::GetSysColor(COLOR_HIGHLIGHT)));
	} 
	else {
		CRect rcClient, rcRow = rcItem;
		GetClientRect(&rcClient);
		rcRow.right = rcClient.right;
		pDC->FillRect(rcRow, &CBrush(nItem % 2 ?  COLOR_1 : COLOR_2));
		//pDC->FillRect(rcHighlight, &CBrush(::GetSysColor(COLOR_WINDOW)));	
	}

	// Set clip region
	rcCol.right = rcCol.left + GetColumnWidth(0);
	CRgn rgn;
	rgn.CreateRectRgnIndirect(&rcCol);
	pDC->SelectClipRgn(&rgn);
	rgn.DeleteObject();

	// Draw state icon
	CImageList *pImageList;	
	if (LVIS_STATEIMAGEMASK == (lvi.state & LVIS_STATEIMAGEMASK)) {
		pImageList = GetImageList(LVSIL_STATE);
		if (NULL != pImageList) {
			int nImage = ((lvi.state & LVIS_STATEIMAGEMASK) >> 12) - 1;
			pImageList->Draw(pDC, nImage, CPoint(rcCol.left, rcCol.top), 
				ILD_TRANSPARENT);
		}
Esempio n. 26
0
//绘画函数
void CHappyGoDlg::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	if (lpDrawItemStruct->CtlType==ODT_LISTVIEW)
	{
		//获取数据
		UINT iWidth=0;
		TCHAR szBuffer[30];
		memset(szBuffer,0,sizeof(szBuffer));
		CDC * pDcItem=CDC::FromHandle(lpDrawItemStruct->hDC);
		/// 创建内存缓冲DC
		CBitmap BufBmp;
		CDC dc;
		CDC *pDC = &dc;
		CRect rc;
		GetClientRect(&rc);
		BufBmp.CreateCompatibleBitmap(pDcItem, rc.Width(), rc.Height());
		dc.CreateCompatibleDC(pDcItem);
		CBitmap * pOldBmp=dc.SelectObject(&BufBmp);

		/// 选择字体
		CFont *pDefaultFont = pDcItem->GetCurrentFont();
		CFont *pOldFont = dc.SelectObject(pDefaultFont);
		UserItemStruct * pUserItem=(UserItemStruct *)GetItemData(lpDrawItemStruct->itemID);
		if (NULL == pUserItem)
		{
			dc.SelectObject(pOldBmp);
			BufBmp.DeleteObject();
			dc.DeleteDC();
			pDcItem->DeleteDC();
			return ;
		}
		//设置颜色
		COLORREF crTextColor,crBackColor;
		bool bSelect=(lpDrawItemStruct->itemState&ODS_SELECTED);//||(lpDrawItemStruct->itemState&ODS_FOCUS);
		GetDrawColor(crTextColor,crBackColor,pUserItem,0,bSelect);
		pDC->SetBkColor(crBackColor);
		pDC->SetTextColor(crTextColor);
		pDC->SetBkMode(TRANSPARENT);
		//绘画信息
		CSize TextSize;
		pDC->FillSolidRect(lpDrawItemStruct->rcItem.left,
			lpDrawItemStruct->rcItem.top,
			lpDrawItemStruct->rcItem.right-lpDrawItemStruct->rcItem.left,
			lpDrawItemStruct->rcItem.bottom-lpDrawItemStruct->rcItem.top,
			crBackColor);

		if((lpDrawItemStruct->itemState&ODS_SELECTED)||(lpDrawItemStruct->itemState&ODS_FOCUS))
		{//画虚框
			int mode=pDC->SetBkMode(TRANSPARENT);
			CPen penBlack,*pOldPen;
			//penBlack.DeleteObject();
			if(lpDrawItemStruct->itemState&ODS_SELECTED)
			{
				if(penBlack.CreatePen(PS_DOT,1, m_bkColor));// RGB(255,255,255)));
					pOldPen=pDC->SelectObject(&penBlack);
			}
			else
			{
				if(penBlack.CreatePen(PS_DOT,1, m_FocusbkColor));// RGB(0,0,0)));
					pOldPen=pDC->SelectObject(&penBlack);
			}
			pDC->SelectStockObject(NULL_BRUSH);
			pDC->Rectangle(lpDrawItemStruct->rcItem.left,lpDrawItemStruct->rcItem.top,
				lpDrawItemStruct->rcItem.right,lpDrawItemStruct->rcItem.bottom);	
			pDC->SetBkMode(mode);

			/// {{ Added by zxd 20100709 释放GDI资源
			pDC->SelectObject(pOldPen);
			penBlack.DeleteObject();
			/// Added by zxd 20100709 释放GDI资源}}
		}

		BOOL bDraw; ///< 是否画用户状态图
		HDITEM hdi;
		TCHAR  lpBuffer[256];
		hdi.mask       = HDI_TEXT;
		hdi.pszText    = lpBuffer;
		hdi.cchTextMax = 256;
		MapColumn::iterator ite;
		ite = m_MapColumn.find("Nickname");

		for (int i=0;i<m_ListHeader.GetItemCount();i++)
		{
			memset(lpBuffer,0,sizeof(TCHAR)*256);
			m_ListHeader.GetItem(i,&hdi); ///< 获取ListCtrl的列表名
			
			bDraw = FALSE;
			if (m_MapColumn.end() != ite)
			{
				if (0 ==_stricmp(lpBuffer,ite->second.ColumnName)) ///< 画用户状态图
				{
					CImageList *imgList = GetImageList(LVSIL_SMALL);
					if(imgList)
					{
						POINT pt;
						int IconID = GetStateImageIndex(pUserItem);
						pt.x = lpDrawItemStruct->rcItem.left+iWidth;
						pt.y = lpDrawItemStruct->rcItem.top;
						imgList->Draw(pDC,IconID,pt,ILD_TRANSPARENT);

						if (::g_global.bEnableUserType)
						{
							pt.x += 27;
							m_UserTypeList.Draw(pDC,pUserItem->GameUserInfo.userType,pt,ILD_TRANSPARENT);
						}

						if (::g_global.bEnableDiamondUserType)//邮游钻石身份标识 add by huangYuanSong 09.07.14
						{
							pt.x += 24;
							if (pUserItem->GameUserInfo.userInfoEx1 > 0 )
							{
								m_UserDiamondTypeList.Draw(pDC,0,pt,ILD_TRANSPARENT);
							}
						}
						bDraw = TRUE;
					}
				}
			}


			int iTemp = GetColumnWidth(i);
			TextSize  = pDC->GetTextExtent(szBuffer,lstrlen(szBuffer));
			GetItemText(lpDrawItemStruct->itemID,i,szBuffer,sizeof(szBuffer));
			CRect TextRect(lpDrawItemStruct->rcItem.left+iWidth+5,
				lpDrawItemStruct->rcItem.top,
				lpDrawItemStruct->rcItem.left+iWidth+iTemp,
				lpDrawItemStruct->rcItem.bottom);
			
			if (bDraw)
			{ ///< 此次列是用户名称Nickname,名称前画了图,输出文字需右移32
				TextRect.left += 32;

				//wushuqun 2009.6.26
				if (::g_global.bEnableUserType)
				{
					TextRect.left += 24;
				}
				if (::g_global.bEnableDiamondUserType)//邮游钻石身份标识 add by huangYuanSong 09.07.14
				{
					TextRect.left += 16;
				}
			}

			pDC->DrawText(szBuffer,lstrlen(szBuffer),&TextRect,(bDraw?DT_LEFT:DT_CENTER)|DT_SINGLELINE|DT_VCENTER|DT_END_ELLIPSIS);
			iWidth += iTemp;
		}

		//绘画屏幕
		pDcItem->BitBlt(
			lpDrawItemStruct->rcItem.left,
			lpDrawItemStruct->rcItem.top,
			lpDrawItemStruct->rcItem.right-lpDrawItemStruct->rcItem.left, 
			lpDrawItemStruct->rcItem.bottom-lpDrawItemStruct->rcItem.top,
			&dc,
			lpDrawItemStruct->rcItem.left,
			lpDrawItemStruct->rcItem.top,
			SRCCOPY);
		dc.SelectObject(pOldBmp);
		dc.SelectObject(pOldFont); 		
		BufBmp.DeleteObject();
		dc.DeleteDC();
	}
	return;
}
Esempio n. 27
0
void CColorTree::OnPaint()
{
	CTreeCtrl::OnPaint();
	CPaintDC dc(this); // device context for painting
	HTREEITEM hItem;
	CImageList *List;
			List = GetImageList(0);

	
	hItem = GetFirstVisibleItem();
	CRect rec, recText;

	 CBrush brush0(m_colRow1);
	CBrush brush1(m_colRow2);

	int i;
	i = 0;
	CDC * pDC;
	pDC = GetDC();
	CFont Font;
	Font.CreateFontW(15,0,0,0,FW_NORMAL, FALSE, FALSE,FALSE,RUSSIAN_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY,FF_MODERN|DEFAULT_PITCH,_T("TestFont"));
	pDC->SelectObject(Font);
	while(hItem!=NULL)
	{
		GetItemRect(hItem,rec,FALSE);
		GetItemRect(hItem,recText,TRUE);
		//
		if(i % 2 == 0)
			{
				pDC->FillRect(rec,&brush0);
				pDC->SetBkColor(m_colRow1);
			}
		else
			{
				pDC->SetBkColor(m_colRow2);
				pDC->FillRect(rec,&brush1);
			}
		CString sName;
		sName = GetItemText(hItem);
		if(sName.Find(_T("\n"))>-1)
		{
			sName =  sName.Left(sName.Find(_T("\n")));
		}
		if(sName.Find(_T("\t"))>-1)
			{
				CString sVal;
				sVal = sName.Left(sName.Find(_T("\t")));
				pDC->TextOutW(recText.left-20 ,rec.top,sVal,sVal.GetLength());
				
				sVal = sName.Right(sName.GetLength()-1-sVal.GetLength());
				pDC->TextOutW(rec.left + (rec.right - rec.left)/2,rec.top,sVal,sVal.GetLength());
			}
		else
			pDC->TextOutW(recText.left - 20,rec.top,sName,sName.GetLength());


		if(GetItemState(hItem, TVIS_EXPANDED)& TVIS_EXPANDED)
		{
			if(List!=NULL)
			{
				CPoint xy; 		
				xy =  recText.TopLeft();
				xy.x = xy.x - 40;
				List->Draw(pDC,1,xy,ILD_NORMAL);
			}
		}
		else
		{
			if(List!=NULL)
			{
				CPoint xy; 		
				xy =  recText.TopLeft();
				xy.x = xy.x - 40;
				if(GetChildItem(hItem)!=NULL)
					List->Draw(pDC,0, xy,ILD_NORMAL);
				else
					List->Draw(pDC,2, xy,ILD_NORMAL);
			}
		}

		hItem = GetNextVisibleItem(hItem);
		i++;
	}
}