Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WM_CTLCOLOREDIT Refresh Problem

137 views
Skip to first unread message

issam

unread,
Oct 22, 1996, 3:00:00 AM10/22/96
to is...@ceci.mit.edu

I am running into a strange problem with WM_CTLCOLOREDIT using win32:

Even though the code below sets the background and text color to red and
green
correctly, if I try to edit the text i.e. delete some chars or insert
some in the
middle, the edit control is not refreshing the text correctly, the
characters get
drawn on top of the previous chars. If the window receives a refresh
message from
outside it redraws everything fine. It is only during editing that
things
get messed up.

case WM_CTLCOLOREDIT:
hdc=(HDC) wParam;
PtrToUXobj= (UXwidget*) GetWindowLong((HWND) lParam,GWL_USERDATA);
hbr=CreateSolidBrush(RGB(255,0,0));
SetBkMode( hdc,TRANSPARENT);
SetTextColor(hdc, RGB(0,255,0));
SetBkColor(hdc, PtrToUXobj->clr);
return ((long) hbr);
break;


Any idea on this is highly appreciated...


Issam Bazzi
MIT
Bldg E40-370
is...@mit.edu

Heiner Eichmann

unread,
Oct 23, 1996, 3:00:00 AM10/23/96
to

issam <is...@mit.edu> wrote:

>Even though the code below sets the background and text color to red and
>green
>correctly, if I try to edit the text i.e. delete some chars or insert
>some in the
>middle, the edit control is not refreshing the text correctly, the
>characters get
>drawn on top of the previous chars. If the window receives a refresh
>message from
>outside it redraws everything fine. It is only during editing that
>things
>get messed up.

> case WM_CTLCOLOREDIT:
> hdc=(HDC) wParam;
> PtrToUXobj= (UXwidget*) GetWindowLong((HWND) lParam,GWL_USERDATA);
> hbr=CreateSolidBrush(RGB(255,0,0));
> SetBkMode( hdc,TRANSPARENT);
> SetTextColor(hdc, RGB(0,255,0));
> SetBkColor(hdc, PtrToUXobj->clr);
> return ((long) hbr);
> break;

I guess its the SetBkMode. Try SetBkMode(hdc, OPAQUE);
BTW: I think you have to delete the SolidBrush which
you are creating. Otherwise you are wasting your GDI heap.


Yours


Heiner Eichmann
Inst. of Quantum Optics
University of Hanover, Germany
h.eic...@mbox.iqo.uni-hannover.de


Matt Arnold

unread,
Oct 23, 1996, 3:00:00 AM10/23/96
to

issam <is...@mit.edu> writes:

>I am running into a strange problem with WM_CTLCOLOREDIT using win32:

>Even though the code below sets the background and text color to red and


>green
>correctly, if I try to edit the text i.e. delete some chars or insert
>some in the
>middle, the edit control is not refreshing the text correctly, the
>characters get
>drawn on top of the previous chars. If the window receives a refresh
>message from
>outside it redraws everything fine. It is only during editing that
>things
>get messed up.

> case WM_CTLCOLOREDIT:
> hdc=(HDC) wParam;
> PtrToUXobj= (UXwidget*) GetWindowLong((HWND) lParam,GWL_USERDATA);
> hbr=CreateSolidBrush(RGB(255,0,0));
> SetBkMode( hdc,TRANSPARENT);
> SetTextColor(hdc, RGB(0,255,0));
> SetBkColor(hdc, PtrToUXobj->clr);
> return ((long) hbr);
> break;

First, this code has a resource leak. You are supposed to return the
handle of brush that you own. You above code returns a brand new
brush each time!

The system DOES NOT delete the brush you return from this message, it
simply uses it. You are supposed to allocate the brush *once* and
return its handle for each message. When the window goes away, you
delete the brush. If you get a WM_SYSCOLORCHANGE, you may need to
destroy and current brush and allocate the new one. The point is,
the system does not assume ownership of the brush and code like what
you show above is "throwing away" a brush each time the edit window
paints (at least).

Second, why are you setting the background to TRANSPARENT mode? This
could be your problem. Normally, in response to a WM_CTLCOLOREDIT
message, you only need to call SetBkColor(), SetTextColor() and return
a brush handle. I believe a normal edit control relies on OPAQUE mode
for proper repaints.

Regards,
-------------------------------------------------------------------------
Matt Arnold | class Disclaimer {
mar...@netcom.com | public:
Boston, MA | Disclaimer() { opinion = L"Mine!"; }
C++, MIDI, Win32/95 developer | private:
e fan | wchar_t* opinion; };
------------------------------------------------------------------------


issam

unread,
Oct 23, 1996, 3:00:00 AM10/23/96
to is...@mit.edu


Thanks for your response, this actually fixed my problem. I remember I
saw
a sample code on this news group where SetBkMode gets called with
TRANSPARENT
mode and that is why I had it in. This is the mail I saw it in:

----------------------------------------------------------------------
HELP! Can't set text color in edit control...

From Mike Thurber <mthu...@hiwaay.net>
Organization Redstone Arsenal, Alabama
Date Thu, 05 Sep 1996 15:25:13 -0500
Newsgroups comp.os.ms-windows.programmer.controls
Message-ID <322F37...@hiwaay.net>


I need to be able to set the text color in an edit control. The
background is being handled just fine in the WM_CTLCOLOREDIT
message handler, but the text is always balck...

Am I leaving out a step or just missing the big picture?
This shouldn't be so difficult... should it?

Here's what I'm doing:

case WM_CTLCOLOREDIT:
SetBkMode((HDC)uParam, TRANSPARENT);
/* OK */
SetTextColor((HDC)uParam, TmpWidg->NT->ForegroundPixel); /* ???
Always black */
return((long)CreateSolidBrush(TmpWidg->NT->BackgroundPixel)); /* OK
*/
break;

The background is set properly, but the text is balck no matter what
color I try to set it
to. I've tried using 0x00FF0000 in place of ForegroundPixel with no
luck either:

SetTextColor((HDC)uParam, 0x00FF0000); /* ??? Still black */
----------------------------------------------------------------------------


Thanks for thr comment on the resource leak, my original code does not
have this problem; only the email code was missing this.

Regards,

0 new messages