Newsgroups: comp.windows.ms.programmer
Path: utzoo!utgpu!watserv1!watmath!hyper.hyper.com!bonneau
From: bonneau@hyper.hyper.com (Paul Bonneau)
Subject: Re: Rectangle tooo slow?
Message-ID: <1991Jun7.163337.8645@hyper.hyper.com>
Reply-To: bonneau@hyper.UUCP (Paul Bonneau,,)
Organization: HyperCube Inc.
References: <1991Jun3.140840.26667@cec1.wustl.edu>
Date: Fri, 7 Jun 1991 16:33:37 GMT

In article <1991Jun3.140840.26667@cec1.wustl.edu>
dave@wucs1.wustl.edu (David T Mitchell III) writes:
>I want to make my winapp's border non-standard colors (ie, active
>and inactive border colors != COLOR_ACTIVEBORDER, COLOR_INACTIVEBORDER).
>
>It appears that to process WM_NCPAINT, it's all or nothing (is this true?),
>so I decided to be Q&D about it...
>	.
>	.
>	case WM_NCPAINT:
>	    DefWindowProc(hwnd, msg, wParam, lParam);	// draw the window
>	    ExcludeClipRect(hdc, {everything inside the borders});
>	    SelectObject(hdc, CreateSolidBrush(myColor));
>	    Rectangle(hdc, 1, 1, {full window extents});
>	    return 0L;
>
>This works just dandy (left out details about checking for type of border,
>etc, for clarity), HOWEVER it's suprisingly slow!  Stepping through with the
>debugger I find that calling DefWindowProc paints the entire window frame
>with border BANG!, but Rectangle() paints so slowly that you first see the
>standard borders, then the new color flowing down over.
>
>I tried using 4 seperate rectangle calls (as opposed to excluding & 1 call),
>but that just gives the same results, but with 4 slow rectangles.
>
>Why is the DefWindowProc so much faster than a simple Rectangle?  Is there
>a better way (read: faster) to do this?
>
I think the problem with the first approach is the clipping.
Rectangle() is gawd-awful slow to begin with, but if you clip
out the inside of essentially a big PatBlt(), that can be
awesomely slow.  Not sure why the second approcah is slow as
well, make sure the ExcludeClipRect() is missing.

However, for the fastest possible solid fills, use
ExtTextOut()!

Something like:

	SetBkColor(hdc, myColor);
	ExtTextOut(hdc, 0, 0, ETO_OPAQUE, (LPRECT)&rect, lszNull, 0,
	    lpintNull);

4 times, should be fast.

cheers - Paul Bonneau.
