PDA

Click to See Complete Forum and Search --> : The "WM_PAINT" Message!


abdul
Jul 18th, 2001, 12:25 AM
I want to draw a round region when the move is down on my window. Please Look at the following code:



case WM_LBUTTONDOWN:
InvalidateRgn(hwnd, hrgn, TRUE);
hdc = GetDC(hwnd);
hbrush = CreateSolidBrush(RGB(34,43, 255));
FillRgn(hdc, hrgn, hbrush);
ReleaseDC(hwnd, hdc);
DeleteObject(hbrush);
ValidateRgn(hwnd, hrgn);
return 0;


That works fine but whenever, I move another window on top of my region or resize my window, it erases all that stuff and then the only way I can redraw the region is under the WM_PAINT message.

-- So what is the other way to draw the roundrect only after the mouse is down. I have tried putting this code under WM_pAINT message but it draws the roundrect whenever it is loader because I have included the styles "CS_HREDRAW | CS_VREDRAW"

Please help me with that!

Technocrat
Jul 18th, 2001, 09:58 AM
I think your only choice would be to make a function(s) that would draw your round region, keep track of its position, is it visable, etc. Then have it called each time by WM_LBUTTONDOWN and/or WM_PAINT.

abdul
Jul 18th, 2001, 11:55 AM
if even if I write the function and call it under the wm_paint message then i will draw the roundrect when the window is loaded or painted.
Is there any other way to do that?

Technocrat
Jul 18th, 2001, 12:10 PM
Originally posted by abdul
if even if I write the function and call it under the wm_paint message then i will draw the roundrect when the window is loaded or painted.

No it doesnt, there are a bunch of ways to keep it from painting on load. The easiest way might be a public bool that when set it false does not run the paint. That should keep it from runing on load. But when the user clicks the left mouse button it changes to true. Thus it will run the function. The quickest way would be to add something like this in your paint function.


bool ShouldIPaint;

void PaintWhatEver()
{
if !(ShouldIPaint)
return 0;
RestOfCode....
}

case WM_LBUTTONDOWN:
ShouldIPaint = true;
PaintWhatEver();
break;

case WM_PAINT
PAINTSTRUCT ps;
BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
PaintWhatEver();
DefWindowProc(hwnd, msg, wParam, lParam);
break;