| | |
| | | m_hIcon[1] = nullptr; |
| | | m_nIconWidth = 0; |
| | | m_nFlashState = 0; |
| | | m_bTextRight = FALSE; |
| | | } |
| | | |
| | | |
| | |
| | | return m_nFlashState != 0; |
| | | } |
| | | |
| | | void CBlButton::SetTextRight() |
| | | { |
| | | m_bTextRight = TRUE; |
| | | } |
| | | |
| | | void CBlButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) |
| | | { |
| | | HDC hDC = lpDrawItemStruct->hDC; |
| | |
| | | HICON hIcon = this->IsWindowEnabled() ? m_hIcon[0] : m_hIcon[01]; |
| | | if (hIcon != nullptr) { |
| | | int xIcon = (rcClient.right - rcClient.top - m_nIconWidth) / 2; |
| | | if (m_bTextRight) { |
| | | xIcon = 15; |
| | | } |
| | | |
| | | if (m_hMenu != nullptr) xIcon -= 10; |
| | | int yIcon = (rcClient.bottom - rcClient.top - m_nIconWidth) / 2; |
| | | if (nTextLen != 0) { |
| | | if (nTextLen != 0 && !m_bTextRight) { |
| | | yIcon -= 8; |
| | | } |
| | | |
| | | DrawIconEx(hDC, xIcon, yIcon, |
| | | hIcon, m_nIconWidth, m_nIconWidth, 0, 0, DI_NORMAL); |
| | | rcText.top = yIcon + m_nIconWidth + 2; |
| | | if (m_bTextRight) { |
| | | rcText.left = xIcon + m_nIconWidth + 2; |
| | | } |
| | | else { |
| | | rcText.top = yIcon + m_nIconWidth + 2; |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | hFont = (HFONT)pFont->GetSafeHandle(); |
| | | } |
| | | |
| | | |
| | | ::SelectObject(hDC, hFont); |
| | | HFONT hOldFont = (HFONT)::SelectObject(hDC, hFont); |
| | | ::SetBkMode(hDC, TRANSPARENT); |
| | | ::SetTextColor(hDC, m_crText[state]); |
| | | |
| | | UINT format1 = m_bTextRight ? DT_LEFT : DT_CENTER; |
| | | if ((BS_MULTILINE & GetStyle()) == BS_MULTILINE) { |
| | | CRect rcBound; |
| | | int height = DrawTextA(hDC, szText, (int)strlen(szText), &rcBound, DT_CENTER | DT_CALCRECT | DT_EDITCONTROL); |
| | | rcText.top = rcBound.top + (rcClient.bottom - rcClient.top - height) / 2; |
| | | rcText.bottom = rcText.top + height; |
| | | DrawTextA(hDC, szText, (int)strlen(szText), &rcText, DT_CENTER | DT_EDITCONTROL); |
| | | DrawTextA(hDC, szText, (int)strlen(szText), &rcText, format1 | DT_EDITCONTROL); |
| | | } |
| | | else { |
| | | if (m_hMenu != nullptr) { |
| | | rcText.right -= (10); |
| | | } |
| | | DrawTextA(hDC, szText, (int)strlen(szText), &rcText, DT_VCENTER | DT_CENTER | DT_SINGLELINE | DT_END_ELLIPSIS); |
| | | DrawTextA(hDC, szText, (int)strlen(szText), &rcText, format1 | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS); |
| | | } |
| | | ::SelectObject(hDC, hOldFont); |
| | | |
| | | |
| | | // 是否有小圆点 |
| | |
| | | ::Polygon(hDC, pt, 3); |
| | | ::SelectObject(hDC, hOldBrush); |
| | | ::SelectObject(hDC, hOldPen); |
| | | ::DeleteObject(hBrush); |
| | | ::DeleteObject(hPen); |
| | | ::DeleteObject(hbrDrop); // 正确释放小三角使用的画刷 |
| | | ::DeleteObject(hPenDrop); // 正确释放小三角的笔 |
| | | } |
| | | } |
| | | |