【发布时间】:2018-12-28 23:33:07
【问题描述】:
有没有办法将按钮内的文本水平和垂直居中对齐?
case WM_DRAWITEM:
{
LPDRAWITEMSTRUCT Item;
Item = (LPDRAWITEMSTRUCT)lParam;
SelectObject(Item->hDC, CreateFont(17, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial Black"));
FillRect(Item->hDC, &Item->rcItem, CreateSolidBrush(0xE0E0E0) );
SetBkMode(Item->hDC, 0xE0E0E0);
SetTextColor(Item->hDC, RGB(255,255,255));
int len;
len = GetWindowTextLength(Item->hwndItem);
LPSTR lpBuff;
lpBuff = new char[len+1];
GetWindowTextA(Item->hwndItem, lpBuff, len+1);
DrawTextA(Item->hDC, lpBuff, len, &Item->rcItem, DT_CENTER);
}
break;
【问题讨论】:
标签: c++ winapi button text center