Newsgroups: comp.windows.ms.programmer Path: utzoo!utgpu!watserv1!watmath!hyper.hyper.com!bonneau From: bonneau@hyper.hyper.com (Paul Bonneau) Subject: Re: QUESTION: Changing color of Edit Control text Message-ID: <1991Mar28.195218.22241@hyper.hyper.com> Reply-To: bonneau@hyper.UUCP (Paul Bonneau,,) Organization: HyperCube Inc. References: <25920006@hpkslx.mayfield.HP.COM> Date: Thu, 28 Mar 1991 19:52:18 GMT In article <25920006@hpkslx.mayfield.HP.COM> ssl@hpkslx.mayfield.HP.COM (SSL Guest User) writes: > >How does one change the color of text entered and displayed >in a dialog box edit control? > >I've tried the following (which failed as predicted by the SDK manuals) > >hDC = GetDC(GetDlgItem(hDlg, controlid)); >SetTextColor(hDC, RGB(blah, blah, blah)); >ReleaseDC(hDC, blah blah); > The problem is that each time the edit control gets a DC, it is re-initialized to the default setting. If the control were registered with one of the other DC attributes your fix would work (the text color would not be nuked--see the discussion of DC attributes in Reference--Volume 2--wndclass). However, you can use the WM_CTLCOLOR message. This is sent just before the control paints itself. Just call SetTextColor() as above except use the DC supplied with the message. cheers - Paul Bonneau.