A further modification to get it working when the button is toggled.
' // Draws the button
IF m_bIsThemed THEN
' // Increase 1 pixel to include the edge
.InflateRect @rc, 1, 1
' // Draws the theme-specified border and fills for the "iPartId" and "iStateId".
.DrawThemeBackground(hTheme, hDc, BP_PUSHBUTTON, iStateId, @rc, NULL)
' // Gets the size of the content for the theme-defined background
.GetThemeBackgroundContentRect(hTheme, hDc, BP_PUSHBUTTON, iStateId, @rc, @rcContent)
ELSE
' // Uses GDI to draw the button
rcContent = rc
IF bIsFocused THEN
IF m_bIsToggle = FALSE OR bIsPressed = FALSE THEN
.FrameRect hDc, @rcContent, GetSysColorBrush(COLOR_WINDOWTEXT)
END IF
.InflateRect @rcContent, -1, -1
END IF
IF m_bIsToggle THEN
IF iStateId = PBS_PRESSED THEN
.DrawEdge hDc, @rcContent, EDGE_SUNKEN, BF_RECT OR BF_MIDDLE OR BF_SOFT
ELSE
IF (lStyle AND BS_FLAT) = BS_FLAT THEN
.DrawEdge hDc, @rcContent, EDGE_RAISED, BF_RECT OR BF_MIDDLE OR BF_SOFT OR BF_FLAT
ELSE
.DrawEdge hDc, @rcContent, EDGE_RAISED, BF_RECT OR BF_MIDDLE OR BF_SOFT
END IF
END IF
ELSE
IF bIsPressed THEN
.FrameRect hDc, @rcContent, GetSysColorBrush(COLOR_BTNSHADOW)
ELSE
uState = DFCS_BUTTONPUSH
IF iStateId = PBS_HOT THEN uState = uState OR DFCS_HOT
IF (lStyle AND BS_FLAT) = BS_FLAT THEN uState = uState OR DFCS_FLAT
.DrawFrameControl hDc, @rcContent, DFC_BUTTON, uState
END IF
END IF
IF m_hBkgBrush = NULL THEN
.FillRect hDc, @rcContent, GetSysColorBrush(COLOR_BTNFACE)
ELSE
.FillRect hDc, @rcContent, m_hBkgBrush
END IF
END IF
What I have done is to move FillRect to the bottom.