|
-
December 2nd, 2003, 11:22 AM
#1
Change Edit Control Color Directly?
Howdy Y'all,
Instead of changing an Edit Control's background and text color by responding to the WM_CTLCOLOR message, I tried to do the following:
Code:
m_hEditBox = CreateWindow("EDIT",NULL,WS_CHILD|ES_AUTOHSCROLL|ES_AUTOVSCROLL|ES_MULTILINE|ES_WANTRETURN,
100,100,100,100, (HMENU) 1, NULL, NULL);
HDC editBoxDC = GetDC(m_hEditBox);
SetBkMode(editBoxDC, TRANSPARENT);
SetBkColor(editBoxDC, RGB(255,255,0));
SetTextColor(editBoxDC, RGB(0,0,255));
ShowWindow(m_hEditBox,SW_SHOW);
ReleaseDC(m_hEditBox, editBoxDC);
...While the edit control appears in the appropriate location, the background and text colors are unchanged. Any idea what I'm doing wrong?
-TM
Last edited by Tzalmaves; December 2nd, 2003 at 11:49 AM.
-
December 2nd, 2003, 01:18 PM
#2
Why not just use EM_SETBKGNDCOLOR?
-
December 2nd, 2003, 02:23 PM
#3
TSmooth,
This is an Edit control, not a Rich Edit control - to the best of my knowledge, EM_SETBKGNDCOLOR only works for Rich Edit controls.
-TM
-
December 2nd, 2003, 02:50 PM
#4
That does not work. 
Such "explanation" is not good enough ? 
How I think about it, your code does not work because the Edit box "knows" what to do with WM_PAINT and other messages.
you can subclass the edit box you created.
But for your edit box you can use the following:
MSDN:
"An edit control that is not read-only or disabled sends the
WM_CTLCOLOREDIT message to its parent window when the control is about to be drawn. By responding to this message, the parent window can use the specified device context handle to set the text and background colors of the edit control...
Read-only or disabled edit controls do not send the WM_CTLCOLOREDIT message; instead, they send the WM_CTLCOLORSTATIC message. "
To TSmooth:
EM_SETBKGNDCOLOR for rich edit control.
Last edited by Caprice; December 2nd, 2003 at 02:52 PM.
Good luck
-
December 2nd, 2003, 03:40 PM
#5
Caprice,
I'm trying to avoid putting code in the parent window's class.
If I subclass the Edit Control, then in OnPaint() would I just do the SetBkMode, SetTextColor, etc. and then call the Base Class's OnPaint?
That does not work.
Such "explanation" is not good enough ?
You must be a Sabra. 
-TM
-
December 2nd, 2003, 05:12 PM
#6
OnPaint() ?
Maybe you'll find something in MFC about subclassing, I don't know.
Without MFC it looks so:
1. WNDPROC wpOrigProc = (WNDPROC) SetWindowLong( hWnd, GWL_WNDPROC, (LONG) NewProc);
2. INT_PTR CALLBACK NewProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_LBUTTONDOWN) {
} else if ( WhatYouWant ) {
} else {
return CallWindowProc(wpOrigLinkProc, hWnd, uMsg, wParam, lParam);
}
}
3 . don't forget about:
::SetWindowLong(hWnd, GWL_WNDPROC, (LONG)wpOrigProc);
Why you don't want to disturb the "parent" ? 
That's the shortest way to change the color.
Good luck
-
December 2nd, 2003, 05:19 PM
#7
A!
About MFC..
class CYourEditBox: public CEdit
{
...
}
will work.
Good luck
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|