There's just two changes you need to make. In each case, it's because you've forgotten that when drawing to the HDC of a control, the RECT always has the top and left members set to 0.
However, when drawing this rect onto the background of the dialog, the top and left members are no longer 0.
The changes you need to make are:
1.
WAS:
vertexS[1].y = ( rect.bottom - rect.top ) / 2;
IS:
vertexS[1].y = rect.top + ( rect.bottom - rect.top ) / 2;
2.
WAS:
vertex1S[0].y = ( rect.bottom - rect.top ) / 2;
IS:
vertex1S[0].y = rect.top + ( rect.bottom - rect.top ) / 2;
I strongly recommend that you use the functions I've mentioned in the past, repeated here for clarity.
void GradientFillRect(HDC hdc, RECT fillMe, COLORREF colStart, COLORREF colEnd, bool isVertical)
{
TRIVERTEX vertex[2];
GRADIENT_RECT gRect;
gRect.UpperLeft = 0;
gRect.LowerRight = 1;
vertex[0].x = fillMe.left;
vertex[0].y = fillMe.top;
vertex[0].Red = GetRValue(colStart) << 8;
vertex[0].Green = GetGValue(colStart) << 8;
vertex[0].Blue = GetBValue(colStart) << 8;
vertex[0].Alpha = 255;
vertex[1].x = fillMe.right;
vertex[1].y = fillMe.bottom;
vertex[1].Red = GetRValue(colEnd) << 8;
vertex[1].Green = GetGValue(colEnd) << 8;
vertex[1].Blue = GetBValue(colEnd) << 8;
vertex[1].Alpha = 255;
if (isVertical)
GradientFill(hdc, vertex, 2, &gRect, 1, GRADIENT_FILL_RECT_V );
else
GradientFill(hdc, vertex, 2, &gRect, 1, GRADIENT_FILL_RECT_H );
}
void drawBigBtn(HDC dst, RECT btnRect, wchar_t *wndText, HFONT btnFont)
{
RECT topRect, botRect;
topRect = botRect = btnRect;
topRect.bottom = botRect.top = ((btnRect.bottom - btnRect.top)/2) + btnRect.top;
GradientFillRect(dst, topRect, RGB(0x95,0xb3,0xd7), RGB(0x4f,0x8b,0xb0), true);
GradientFillRect(dst, botRect, RGB(0x4f,0x8b,0xb0), RGB(0x95,0xb3,0xd7), true);
HBRUSH blueBrush, oldBrush;
blueBrush = CreateSolidBrush(RGB(79,129,189));
oldBrush = (HBRUSH) SelectObject(dst, blueBrush);
FrameRect(dst, &btnRect, blueBrush);
SelectObject(dst, oldBrush);
DeleteObject(blueBrush);
RECT textRect = btnRect;
textRect.top = textRect.bottom - 40;
SetBkMode(dst, TRANSPARENT);
int textLen = wcslen(wndText);
HFONT oldFont;
if (btnFont != NULL)
{
oldFont = (HFONT)SelectObject( dst, btnFont );
DrawTextEx( dst, wndText, textLen, &textRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_WORDBREAK, 0 );
SelectObject(dst, oldFont);
}
else
DrawTextEx( dst, wndText, textLen, &textRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_WORDBREAK, 0 );
}