To use the modified code, with progress percentage, in an ANSI project simply change the functions wsprintf to wsprintfW, and DrawText to DrawTextW, as in the amended following code:
void DrawProgressBar(HTHEME hTheme, HDC hdc, LPRECT rcBar, BOOL bSmooth, INT iProgress)
{
RECT rcContent, rcChunk;
int trackprog = iProgress;
GetThemeBackgroundContentRect(hTheme, hdc, PP_BAR, 0, rcBar, &rcContent);
iProgress = rcContent.left + (int)((rcContent.right - rcContent.left) * ((float)max(min(iProgress, 100), 0) / 100.0f));
int ellipse_width_height = 0, ellipse_height = 0;
HRGN hRgn = CreateRoundRectRgn(rcBar->left, rcBar->top, rcBar->right + 1, rcBar->bottom + 1, ellipse_width_height, ellipse_height);
SelectClipRgn(hdc, hRgn);
DrawThemeBackground(hTheme, hdc, PP_BAR, 0, rcBar, NULL);
SelectClipRgn(hdc, NULL);
DeleteObject(hRgn);
int progressPercentage = (trackprog > 100) ? 100 : ((trackprog < 0) ? 0 : trackprog);
WCHAR szProgressText[5];
wsprintfW(szProgressText, L"%d%%", progressPercentage);
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, RGB(0, 0, 0)); // Set text color to black
if (bSmooth)
{
rcChunk = rcContent;
rcChunk.right = iProgress;
DrawThemeBackground(hTheme, hdc, PP_CHUNK, 0, &rcChunk, NULL);
}
else
{
int nChunkSize = 6, nSpaceSize = 2;
GetThemeMetric(hTheme, hdc, PP_BAR, 0, TMT_PROGRESSCHUNKSIZE, &nChunkSize);
GetThemeMetric(hTheme, hdc, PP_BAR, 0, TMT_PROGRESSSPACESIZE, &nSpaceSize);
rcChunk = rcContent;
rcChunk.right = rcChunk.left;
while (rcChunk.left < iProgress)
{
rcChunk.right = min(rcChunk.left + nChunkSize, rcContent.right);
DrawThemeBackground(hTheme, hdc, PP_CHUNK, 0, &rcChunk, NULL);
rcChunk.left = min(rcChunk.right + nSpaceSize, rcContent.right);
}
}
DrawTextW(hdc, szProgressText, -1, rcBar, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
}
EDIT: Modified code to write percentage for both styles (smoothed or not).