Hello. I'm using the following code to draw the background of the window and the progress bar:
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
BITMAP bm;
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, imagemdeteste);
GetObject(imagemdeteste, sizeof(bm), &bm);
BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
SelectObject(hdc, GetStockObject(DC_PEN));
SetDCPenColor(hdc, RGB(75, 75, 75));
SelectObject(hdc, GetStockObject(NULL_BRUSH));
Rectangle(hdc, 0, 0, WindowSize.cx, WindowSize.cy);
/* AQUI COMEÇA O DESENHO DA BARRA DE PROGRESSO */
SelectObject(hdc, GetStockObject(DC_PEN));
SetDCPenColor(hdc, RGB(75, 75, 75));
SelectObject(hdc, GetStockObject(NULL_BRUSH));
Rectangle(hdc,
ProgressBarLocation.x, ProgressBarLocation.y,
ProgressBarLocation.x + ProgressBarSize.cx, ProgressBarLocation.y + ProgressBarSize.cy
);
SelectObject(hdc, GetStockObject(DC_PEN));
SetDCPenColor(hdc, RGB(75, 75, 75));
SelectObject(hdc, GetStockObject(DC_BRUSH));
SetDCBrushColor(hdc, RGB(75, 75, 75));
Rectangle(hdc,
(ProgressBarLocation.x + 1) + iProgressBarPadding, (ProgressBarLocation.y + 1) + iProgressBarPadding,
(ProgressBarLocation.x + 1) + iProgressBarPadding + (((ProgressBarSize.cx - (2 * (1 + iProgressBarPadding))) * ProgressBarValue) / 100), (ProgressBarLocation.y - 1) - iProgressBarPadding + ProgressBarSize.cy
);
EndPaint(hWnd, &ps);
}
To update the progress bar I use the following code:
ProgressBarValue = QUALQUER VALOR DE 0 A 100;
RedrawWindow(hWnd, 0, 0, RDW_INVALIDATE);
This code will call WM_PAINT and I would be drawing the whole window again, even the background. I would like to only change the rectangles used to make the progress bar. Or is that what you do?
What is the right way to do this?