The content of my application window is only updated when i change the window size.
Details: I have a windows application written in c++ and compiled with mingw64. Within WinMain, i do a CreateWindowW for the WndProc. In the WndProc callback, i have a WM_CREATE from where i setup all initial data to be shown and do a
case WM_CREATE:
hdc = BeginPaint(hwnd, &ps);
doAllTheDrawings(hdc);
EndPaint(hwnd, &ps);
break;
After that, i have my child window showing all the diagrams with initial values.
After that, in the background, some data change, and i want to update the diagrams. When resizing the child window, it immediately updates the data shown to the new values, as the WM_PAINT is called
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
doAllTheDrawings(hdc);
EndPaint(hwnd, &ps);
break;
Now i want to update my diagrams even if i do not change the window size. Therefore i added
case WM_LBUTTONDOWN:
hdc = BeginPaint(hwnd, &ps);
doAllTheDrawings(hdc);
EndPaint(hwnd, &ps);
break;
So i expect that the diagrams update as soon as i press the left mousebutton. I can see that WM_LBUTTONDOWN is called (as i have a few other actions done then), but the diagrams do not update until i resize the window.
What am i doing wrong? How can i force the diagrams to update, i.e. the window to be repainted? Just calling WM_PAINT manually does not help.
Looks like i found a solution: The whole creation of the diagrams, which i so far did on WM_CREATE and WM_LBUTTONDOWN is only required under WM_PAINT. On WM_CREATE and WM_LBUTTONDOWN, only
needs to be called. This 'flushes' the client area and then calls WM_PAINT and recreates it all. Refer to
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-invalidaterect