Exemplo n.º 1
0
//---------------------------------------------------------------------------
void __fastcall TForm1::OvcTCString1OwnerDraw(TObject *Sender,
  TCanvas *TableCanvas, const TRect &CellRect, int RowNum, int ColNum,
  const TOvcCellAttributes &CellAttr, Pointer Data, bool &DoneIt)
{
  bool F;
  TRect R;
  TCanvas* C;
  char Buf[255];

  DoneIt = True;
  R = CellRect;
  C = TableCanvas;

  // paint background
  C->Brush->Style = bsClear;
  C->Pen->Color = clBtnFace;
  C->Rectangle(R.Left, R.Top, R.Right, R.Bottom);

  // draw button
  F = (RowNum == TBL->ActiveRow) && (ColNum == TBL->ActiveCol);
  DrawButtonFace(C, R, 1, bsNew, true, F, F);

  // draw data
  if ((RowNum % 2) == 1)
    C->Font->Color = clRed;
  else
    C->Font->Color = clBlack;
  sprintf(Buf, "%d:%d", RowNum, ColNum);
  DrawText(C->Handle, Buf, StrLen(Buf),
    (RECT*)&R, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
Exemplo n.º 2
0
/*! This Function is called each time, the Button needs a redraw
*/
void CRoundButton2::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	// Get DC of Item
	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	ASSERT (pDC != NULL);

	// Should Buttons be generated?
	bool bGenerate = !m_rBtnSize.EqualRect(&lpDrawItemStruct->rcItem) || m_bRedraw;

	// If Rectangles of Button are not the same
	if (bGenerate)
	{
		// Generate Bitmap to hold Buttons
		GenButtonBMPs(pDC, lpDrawItemStruct->rcItem);

		// Redraw done
		m_bRedraw = false;
	}

	// Generate DC to draw in Memory
	CDC MemDC;
	MemDC.CreateCompatibleDC(pDC);

	HGDIOBJ hOldBmp = MemDC.SelectObject(m_tBmpBtn);

	CString sActualCaption;
	// Get actual caption
	GetWindowText(sActualCaption);

	// Check, if caption has changed
	if (sActualCaption != m_sOldCaption)
		bGenerate = true;

	// Store old caption
	m_sOldCaption = sActualCaption;

	// If Rectangles of Button are not the same
	if (bGenerate)
	{
		// Draw Buttons
		DrawButtonFace(&MemDC);

		// Draw Button-Caption
		DrawButtonCaption(&MemDC);
	}

	int nButtonState;

	nButtonState = BS_ENABLED;

	if (m_bIsHotButton && m_bMouseOnButton)
		nButtonState = BS_HOT;

	if ((lpDrawItemStruct->itemState & ODS_DISABLED) == ODS_DISABLED)
		nButtonState = BS_DISABLED;
	else
	{
		if ((lpDrawItemStruct->itemState & ODS_SELECTED) == ODS_SELECTED)
			nButtonState = BS_PRESSED;
		else
		{
			if (this->m_bIsChecked)
			{
				nButtonState = BS_CLICKED;
			}
		}
	}

	// Copy correct Bitmap to Screen
	pDC->BitBlt(
		lpDrawItemStruct->rcItem.left,
		lpDrawItemStruct->rcItem.top,
		m_rBtnSize.Width(),
		m_rBtnSize.Height(),
		&MemDC,
		0,
		m_rBtnSize.Height() * nButtonState,
		SRCCOPY);

	MemDC.SelectObject(hOldBmp);
}