Here are the answers to your questions.
#1 Thank you for the bug report. The problem was with detecting the button alignment. To detect whether the center alignment, we checked the BS_CENTER
style, but in fact this style is a bit mask for the BS_LEFT
and BS_RIGHT
styles, so the alignment was always center when either the left/right alignment was applied. Here is the update for the CExtButton::PreSubclassWindow()
method:
void CExtButton::PreSubclassWindow()
{
CButton::PreSubclassWindow();
DWORD dwWndStyle = GetStyle();
DWORD dwWndType = dwWndStyle&0x0F;
m_nButtonType = INT(dwWndType);
SetButtonStyle( BS_OWNERDRAW );
bool bAlignLeft = (dwWndStyle&BS_LEFT) != 0 ? true : false;
bool bAlignRight = (dwWndStyle&BS_RIGHT) != 0 ? true : false;
INT nAlignHorz = CExtPaintManager::__ALIGN_HORIZ_CENTER;
if( bAlignLeft && bAlignRight )
nAlignHorz = CExtPaintManager::__ALIGN_HORIZ_CENTER;
else if( bAlignLeft )
nAlignHorz = CExtPaintManager::__ALIGN_HORIZ_LEFT;
else if( bAlignRight )
nAlignHorz = CExtPaintManager::__ALIGN_HORIZ_RIGHT;
else if( SupportsCommand() || (dwWndStyle&BS_PUSHLIKE) != 0 )
nAlignHorz = CExtPaintManager::__ALIGN_HORIZ_CENTER;
bool bAlignTop = (dwWndStyle&BS_TOP) != 0 ? true : false;
bool bAlignBottom = (dwWndStyle&BS_BOTTOM) != 0 ? true : false;
INT nAlignVert = CExtPaintManager::__ALIGN_VERT_CENTER;
if( bAlignTop && bAlignBottom )
nAlignVert = CExtPaintManager::__ALIGN_VERT_CENTER;
else if( bAlignTop )
nAlignVert = CExtPaintManager::__ALIGN_VERT_TOP;
else if( bAlignBottom )
nAlignVert = CExtPaintManager::__ALIGN_VERT_BOTTOM;
else if( SupportsCommand() || (dwWndStyle&BS_PUSHLIKE) != 0 )
nAlignVert = CExtPaintManager::__ALIGN_VERT_CENTER;
m_nAlign = (nAlignHorz | nAlignVert);
m_nCheck = GetCheck();
bool bEnabled = OnQueryWindowEnabledState();
PostMessage( // delayed repainting
WM_ENABLE,
(WPARAM) bEnabled ? TRUE : FALSE
);
}
#2 We cannot say that this is a bug, but we agree that the text painting can be improved. Please open the
CExtPaintManager::PaintPushButton()
and
CExtPaintManagerXP::PaintPushButton()
methods. Find the following code snippet:
CRect rcCenteredCaption( rectCaption );
rcCenteredCaption.OffsetRect(
( ( _ppbd.m_nDrawTextFlagsH & DT_CENTER ) != 0 )
? ( ( rectCaption.Width() - rcText.Width() ) / 2 )
: 0
,
( ( _ppbd.m_nDrawTextFlagsH & DT_VCENTER ) != 0 )
? ( ( rectCaption.Height() - rcText.Height() ) / 2 )
: 0
);
and replace it with the following one:
CRect rcCenteredCaption( rectCaption );
if( rcText.Width() < rectCaption.Width() )
rcCenteredCaption.OffsetRect(
( ( _ppbd.m_nDrawTextFlagsH & DT_CENTER ) != 0 )
? ( ( rectCaption.Width() - rcText.Width() ) / 2 )
: 0,
0
);
if( rcText.Height() < rectCaption.Height() )
rcCenteredCaption.OffsetRect(
0,
( ( _ppbd.m_nDrawTextFlagsH & DT_VCENTER ) != 0 )
? ( ( rectCaption.Height() - rcText.Height() ) / 2 )
: 0
);