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

Read-only Edit control with a white background

66 views
Skip to first unread message

Seb

unread,
Mar 19, 2000, 3:00:00 AM3/19/00
to
The subject is exactly what I want. A read-only edit control has a grey
background, I want to change it to the value of
GetSysColor(COLOR_WINDOW) which is white in the default windows theme.

I have accomplished this in the past where the parent of the control was a
window. But in my current project, the parent is a dialog. The difference
is that the dialog procedure function's return value is a BOOL as opposed to
the windows's procedure function which is LRESULT. Handling
WM_CTLCOLORSTATIC requires you to use SetBkColor() with the DC passed as a
parameter to change the text's bg color and return a brush you want to use
to color the background of the control. But the dialog proc's return value
is bool, and the documentation says to just return your brush casting it to
a BOOL value. That doesn't make any sense to me. And it also ignores the
DWL_MSGRESULT value of GetWindowLog(). So how do I do it? My text has a
white background, but the rest of the control is grey.

Seb

Chris Becke

unread,
Mar 19, 2000, 3:00:00 AM3/19/00
to

For some reason (that is, I don't know why) WM_CTLCOLORSTATIC is an
exception, even when handled in a DialogProc you return the HBRUSH or NULL.
As NULL is a valid alias for FALSE :) DefDlgProc can tell if you handled the
message or not, if you return a non-null result DefDlgProc uses that
directly by upcasting the BOOL return back to an HBRUSH.

I refer you to:
http://support.microsoft.com/support/kb/articles/q68/5/66.asp
a KB article that mentions "defdlg.c". While not available in the platform
sdk samples, you can get it off the net here:
http://www.mvps.org/user32/rc/defproc.zip

Another place that indirectly mentions this crazy special caseness is
"windowsx.h" a file you should have available in your platform sdk. It has a
wierd macro that is intended to filter all dialog returns by message code
and determine if it must return TRUE (and place the return code in
DWL_RESULT) or simply cast and return the given lResult.

So, take your HBRUSH and cast it to a BOOL (NOT a bool!) and return it.

Hope this helps.

Chris
--
VisualC++ & Win32 FAQ: http://www.mvps.org/vcfaq
My Win32 Page: http://www.mvps.org/user32


John A. Grant

unread,
Mar 19, 2000, 3:00:00 AM3/19/00
to
"Seb" <s...@cyberdream.net> wrote in message
news:yZ9B4.2100$L5.2...@newsfeed.slurp.net...

> The subject is exactly what I want. A read-only edit control has a grey
> background, I want to change it to the value of
> GetSysColor(COLOR_WINDOW) which is white in the default windows theme.
>
> I have accomplished this in the past where the parent of the control was a
> window. But in my current project, the parent is a dialog. The
difference
> is that the dialog procedure function's return value is a BOOL as opposed
to
> the windows's procedure function which is LRESULT. Handling
> WM_CTLCOLORSTATIC requires you to use SetBkColor() with the DC passed as a
> parameter to change the text's bg color and return a brush you want to use
> to color the background of the control. But the dialog proc's return
value
> is bool, and the documentation says to just return your brush casting it
to
> a BOOL value. That doesn't make any sense to me. And it also ignores the
> DWL_MSGRESULT value of GetWindowLog(). So how do I do it? My text has a
> white background, but the rest of the control is grey.

The DlgProc() return value is BOOL, not 'bool'. 'bool' is
a formal data type for C++. BOOL is something completely
different and is for Windows only. BOOL is guaranteed to
be large enough to hold an HBRUSH. BOOL & HBRUSH
were both 16-bit values in Win16, but they are both 32-bit
values in Win32, so all is ok.

You can return an HBRUSH as a BOOL. It will work:
static HBRUSH brush...

case WM_CTLCOLORSTATIC:
...
return (BOOL)hbrush;

--
John A. Grant * I speak only for myself * (remove 'z' to reply)
Radiation Geophysics, Geological Survey of Canada, Ottawa
If you followup, please do NOT e-mail me a copy: I will read it here


0 new messages