Win32 c++ Iterate RGB colors to windows in WM_PAINT

381 Views Asked by At

I have a VS2019 c++ application which has the following interface : interface.png

It works wonder for 'single' measurements (through the 'Measure Sample' button). The measurement is made and all the data gathered is shown on the interface a) in graph form, b)in numeric form and c) in "color" form, as you can see by the big Yellow square on the right (a simulation).

The next step in my development is to display a series of RGB colors on the screen, take measurements and save them to a file. In order to do this, I simply attach the measuring device to the screen and successively all the RGB colors I need, taking measurements each time.

So I added a 'Measure Screen' button. Which uses this code :

inProgress = true;
RECT RectRGB = { 561, 83, 968, 439 };

int Red[] = {255, 128, 64, 0};

for (int i = 0; i < 3; i++) {
    Red1 = Red[i];
    Green1 = 0;
    Blue1 = 0;
    InvalidateRect(hWnd, &RectRGB, true);
}

inProgress = false;

The way I "expected" the code to work was, each Invalidate call would send a message to the WM_PAINT event and would be processed this way :

RECT rectSRGB = { 561, 83, 968, 439 }; // x1, y1, x2, y2
    if (inProgress) {               
        HBRUSH FillRGB = CreateSolidBrush(RGB(Red1, Green1, Blue1));
        FillRect(hdc, &rectSRGB, FillRGB);
        DeleteObject(FillRGB);
    }
    else {
        HBRUSH FillRGB = CreateSolidBrush(RGB(sRGB.Red, sRGB.Green, sRGB.Blue));
        FillRect(hdc, &rectSRGB, FillRGB);
        DeleteObject(FillRGB);
    }

IOW, as long as the flag 'inProgress' is not raised, the WM_PAINT event processes the message "normally". Only when the message comes from the "MEASURE_SCREEN function is the rectangle filled with the specified RGB color (specified in global scope).

Well, this does not work? The function iterates through the colors OK and call 'Invalidate' each time, it hits my 'InProgress' logic but the "new" color is never shown to the screen, until control exits the function.

I have been searching how to do this for quite some time now and I figured I might ask for your kind and patient help.

0

There are 0 best solutions below