0

In my small, small and humble c++ Win32 GUI application, I got to the point of being able to draw a grid :

enter image description here

This is in preparation for displaying spectral data, the 36 (floats) measurement points returned from my device. I still have to get the axis labeled… This is my code for drawing the grid so far :

case WM_PAINT:
{
    PAINTSTRUCT ps;
    HDC hdc = BeginPaint(hWnd, &ps);    

    FillRect(hdc, &ps.rcPaint, HBRUSH (COLOR_WINDOW + 1));  

    bool Retour;
    
    pen = (HPEN)GetStockObject(TRANSPARENT);
    SelectObject(hdc, pen);

    Brosse = CreateSolidBrush(RGB(240, 240, 240));
    SelectObject(hdc, Brosse);

    Retour = LineTo(hdc, 100, 500);*/

    Retour = Rectangle(hdc, 350, 150, 750, 375);

    for (int i = 380; i <= 730; i=i+10) {   // 36 vertical lines
        MoveToEx(hdc, i, 175, NULL);
        LineTo(hdc, i, 350);
    }
    for (int i = 175; i <= 350; i = i + 17) {
        MoveToEx(hdc, 375, i, NULL);
        LineTo(hdc, 730, i);
    }

    DeleteObject(pen);
    DeleteObject(Brosse);

    EndPaint(hWnd, &ps);

As you can see, I located the code to draw the grid inside the WM_PAINT procedure. It made sense to locate the code there to experiment with GDI instructions but also because the grid needs to be visible at launch time as part of the interface.

My question is how should I go "updating" the graph when, after pressing the "Measure Sample" button, I have access to the data? I gather that the code to draw on the grid does not necessarily needs to be located inside the WM_PAINT procedure, does it? According to my limited understanding, as long as I can get a Device Context handle (hDC), I should be good to go? All I need to plot is a "line" uniting the 36 data points from left to right. Not sure I should use simple MOVE_TO and LINE_TO for this purpose? I think there is a way to draw a "smoothed" line that passes through all 36 data points?

One last thing, if I may… I’m going at this in a very elementary way because I’m intimidated by the idea of using a "graphic library" and objects. But I suspect they would make my life a lot easier while offering umpteen options that will take me too long to figure out, I’ll bet, and implement?

Thank you so much in advance for your kind help and patience.

Anonymous Asked question May 14, 2021