0

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.

Roger Breton
  • 81
  • 1
  • 9
  • `InvalidateRect()` causes a WM_PAINT message to be posted eventually. Notice I say posted. This means WM_PAINT is put in the message queue and gets dequeued when calling `GetMessage()` or `PeekMessage()` in the message loop. `InvalidateRect()` just says that piece of the window needs to be redrawn and windows will eventually post a WM_PAINT to the message queue. If you want to immediately redraw the window after `InvalidateRect()` then call `UpdateWindow()` or `RedrawWindow()`. But, I'm not sure that's a good thing to do in a loop. Not sure exactly is trying to be accomplished. – Joseph Willcoxson Jun 04 '21 at 14:24
  • @JosephWillcoxson : Thank you for the clarification and UpdateWindow() suggestion. I'll give it a try. Actually, what I'm trying to do is simple, to send a number of different RGB colors to the monitor and have my measuring instrument analyse each one, saving the results into a file for later processing. The number of colors could be 10 or 20 or 800, you see? Each cycle of measurements take about three seconds. – Roger Breton Jun 04 '21 at 14:28
  • @JosephWillcoxson: Wow! I merely added the UpdateWindow(hWnd) call following the InvalidateRect() call and the refresh, debug mode, as soon as the debugger hit that instruction, was instantaneous! Will pursue "this line of thought" gladly! In other languages, such as VisualBasic, which I used extensively and still do, there was a similar kind of "Update Control" kind of instruction, which I used with success. – Roger Breton Jun 04 '21 at 16:58

0 Answers0