Specifically a control whose bgcolor has been preregistered in
wndclassex ?
And even more specifically, and edit control, which I would like to
appear greyed ?
Thankyou.
Todd
"Lawrence Marigold" <cen...@lineone.net> wrote in message
news:8i2t98$h8u$1...@supernews.com...
case WM_CTLCOLOREDIT:
if( (HWND) lParam == GetDlgItem( hwndParent, ID_YOUR_EDITBOX ) )
{
/* You can set your text color, background, and modes here, too */
SetTextMode( (HDC)wParam, TRANSPARENT ); /* also OPAQUE */
SetTextColor( (HDC)wParam, RGB( 255,255,255 ) /*WHITE_TEXT*/ );
return ( LRESULT )GetStockObject( LTGRAY_BRUSH );
}
return DefWindowProc( hwndParent, uMsg, wParam, lParam );
Adam "Nasiry" Foster
"Dave Ballinger" <dball...@worldnet.att.net> wrote in message
news:j2j15.7958$iy.5...@bgtnsc06-news.ops.worldnet.att.net...
This is bad news. You're going to get lots of WM_CTLCOLOR...
messages and each time, you create a new HBRUSH.
How are you deleting all of those brushes when your
dialog box ends? You've got a resource leak.
In addition, you do NOT select your HBRUSH into
the HDC provided. Just return the HBRUSH and the
control's drawing procedure will take care of selecting
it in and out of the HDC.
Here's the way you should be doing it:
static HBRUSH hbrush_recv,hbrush_send,
hbrush_serveraddy,hbrush_serverport;
...
case WM_INITDIALOG:
hbrush_recv=CreateSolidBrush(...);
hbrush_send=CreateSolidBrush(...);
hbrush_serveraddy=CreateSolidBrush(...);
hbrush_serverport=CreateSolidBrush(...);
break;
case WM_COMMAND
int id=GET_WM_COMMAND_ID(wparam,lparam);
switch(id){
case IDCANCEL:
case IDOK:
DeleteObject(hbrush_recv);
DeleteObject(hbrush_send);
DeleteObject(hbrush_serveraddy);
DeleteObject(hbrush_serverport);
EndDialog(hdlg,id==IDOK);
break;
Then you just return the appropriate HBRUSH at
WM_CTLCOLOR*
Also you don't have to hang on to the HWND of the controls.
Assuming you have some constants:
#define IDC_RECV 101
#define IDC_SEND 102
#define IDC_SERVERADDY 103
#define IDC_SERVERPORT 104
Then you can just do this:
case WM_CTLCOLOREDIT:
HDC hdc= GET_WM_CTLCOLOR_HDC(wparam,lparam);
HWND hwnd=GET_WM_CTLCOLOR_HWND(wparam,lparam);
int type=GET_WM_CTLCOLOR_TYPE(wparam,lparam);
int id=GetDlgCtrlID(hwnd);
switch(id){
case IDC_RECV:
...
break;
case IDC_SEND:
...
break;
case IDC_SERVERADDY:
...
break;
case IDC_SERVERPORT:
...
break;
}
If this is in a DlgProc(), you should be casting the HBRUSH
to a BOOL since the DlgProc() returns a BOOL. Yes, a
BOOL is always large enough to hold an 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