i have two rectangle in my WM_PAINT and i wanted to draw Frame Rect on it once WM_MOUSE CLICK EVENT is triggered that toggle on each rectangle. is this even possible?
Asked
Active
Viewed 453 times
-3
-
2You need to elaborate your question. A it stands here it is totally unclear and too broad. – Jabberwocky Jun 26 '18 at 06:22
-
You need to have your mouse click handler save which rectangle is being clicked on, and then invalidate the window so a new `WM_PAINT` is triggered, so it can then draw a frame around the clicked rectangle. – Remy Lebeau Jun 26 '18 at 19:19
1 Answers
0
See @RemyLebeau's comment above regarding your mouse clicks. Then, in your WndProc, something like:
switch (uMsg)
{
// ...
case WM_PAINT:
{
PaintStruct ps;
HDC hDC = BeginPaint (hWnd, &ps);
HBRUSH hBrush = (HBRUSH) GetStockObject (LTGRAY_BRUSH); // say
if (draw_first_rectangle)
FrameRect (hDC, &my_first_rectangle, hBrush);
if (draw_second_rectangle)
FrameRect (hDC, &my_second_rectangle, hBrush);
EndPaint (hWnd, &ps);
return 0;
}
// ...
}
return DefWindowProc (hWnd, uMsg, wParam, lParam);
I'm sure you can fill in the blanks.

Paul Sanders
- 24,133
- 4
- 26
- 48
-
Hmm right but this mean i need to invalidate in order to proc the WM_PAINT message everytime i Receive the WM_MOUSECLICK message right? If this the case this will cause flickering each time i click on my rectangle. – cole Jun 28 '18 at 11:54
-
Ah well, flickering. That's a whole other issue. See if it's really a problem for you, and if so please ask a new question. – Paul Sanders Jun 28 '18 at 12:00
-
And [accepting the answer](https://stackoverflow.com/help/someone-answers) would be nice, thanks. – Paul Sanders Jun 28 '18 at 14:49
-
Thank you, much appreciated. I did actually post something about writing a flicker-free WM_PAINT handler, see: https://stackoverflow.com/a/50656524/5743288. In addition to what it says there, you have to set your class background brush to `GetStockObject (NULL_BRUSH)` and draw the entire window - background and all - in your `WM_PAINT` handler. You might start by filling the hDC with (say) a WHITE_BRUSH and then draw your rectangles and whetever else. Then, when you call `EndBufferedPaint ()`, it all gets blasted to the screen in a single operation, so no flicker. – Paul Sanders Jun 28 '18 at 15:59
-
But this is all just in passing. If you want to get a proper answer about this, please post a new question. – Paul Sanders Jun 28 '18 at 15:59