15,979
社区成员
发帖
与我相关
我的任务
分享
void CMyHead::DrawItem(LPDRAWITEMSTRUCT pDIS)
{
// TODO: Add your message handler code here and/or call default
HDITEM hDI;
TCHAR szBuf[MAX_PATH];
hDI.mask = HDI_TEXT;
hDI.pszText = szBuf;
hDI.cchTextMax = MAX_PATH;
GetItem(pDIS->itemID, &hDI);
CDC *pDC;
HDC hDC = pDIS->hDC; // Handle to device context
pDC = CDC::FromHandle(hDC);
int x = 0; // x-coordinate of reference point
int y = 0; // y-coordinate of reference point
UINT nOptions = 0; // Text-output options ETO_CLIPPED|ETO_OPAQUE
RECT *pIRect = NULL; // Optional clipping and/or opaquing rectangle
pIRect = &pDIS->rcItem;
SIZE Size = {0};
//*** Gets the header cell sizes
if(!GetTextExtentPoint(hDC, szBuf, strlen(szBuf), &Size))
{
AfxMessageBox("Failed to call GetTextExtentPoint for table header!");
return;
}
// x-coordinate of reference point
x = (pIRect->left + pIRect->right - Size.cx)/2 - 1;
x = (x < pIRect->left + 2) ? pIRect->left + 2 : x;
// y-coordinate of reference point
int hei=(pIRect->bottom-pIRect->top)/2;
y = pIRect->top + hei + (hei-Size.cy)/2;
// Specifies that the current background color fills the rectangle pIRect
nOptions |= ETO_CLIPPED;
// Decreases the text border to the right
pIRect->right -= 4;
// Writes the text in the (x, y) coordinates
pDC->ExtTextOut(x, y, nOptions, pIRect, szBuf, strlen(szBuf), NULL);
// CHeaderCtrl::OnDrawItem(nIDCtl, lpDrawItemStruct);
}