In Win32, almost all drawings must be executed in the WM_PAINT handler. You probably do not see any picture, because as soon as you finish processing the button click, you will get WM_PAINT.
If you paint outside of WM_PAINT, your drawing has a short lifespan due to the windows being invalidated, and then the WM_PAINT message.
Thus, the correct way to draw in Win32 is with the WM_PAINT handler.
I edited the answer after the comment of the author. Suppose you need to change the image after a mouse click. You can do:
case WM_PAINT: { hdc = BeginPaint(hWnd, &ps); Gdiplus::Graphics graphics(hdc); Gdiplus::Image gdiImage(clicked ? L"image_A.png" : L"image_B.png"); graphics.DrawImage(&gdiImage, 40, 40); EndPaint(hWnd, &ps); break; } case WM_LBUTTONDOWN: { clicked = true; InvalidateRect(hwnd, NULL, true); break; }
The InvalidateRect function is the answer. With this function, you tell Windows to redraw the window. This is a link to the man page: InvalidateRect
source share