Setting Font Color
Hello Everybody,
I have an EditControl now i want to change the textcolor of that editcontrol.
This is the code that i have written: -
PAINTSTRUCT ps;
HDC hDC;
hDC = BeginPaint( hWND, &ps );
SetTextColor(hDC,RGB(0,0,255)); // Change the color to Blue
TextOut( hDC, 0, 0, "Hello World",11);
EndPaint( hWND, &ps );
My problem is that when i click on the editcontrol then the color again changes from blue to black. Can anybody help me in this regard.
Can I use SetTextColor() but its not working i m using SetWindowText() to set the text of the editcontrol.
Thanking You,
Sonali....
Have a Gud Day!!!!!
[688 byte] By [
sss0379] at [2007-11-18 1:36:12]

# 1 Re: Setting Font Color
This trouble is probably not caused by your code, but by Microsofts control policy.
They do not accept user changes exept, when created with OwnerDraw style.
But thats pretty annoying, because if in ownerdraw style you have to draw everything. :(
In Ownerdraw-Style you get the Message WM_DRAWITEM if your control is to be redrawn. The rest is simply API - drawing (your control, Edges and all), using the structure you get with that message. This message shows you the state the control is in.
You might give WM_CTRLCOLOREDIT a try, but I'm not shure if text color changed there keeps changed, because it's normally for background changes. I've never tried it for changing text color. (I wrote some routine for OwnerDrawn buttons).
Hope this will help you
HoWeR
HoWeR at 2007-11-9 13:02:46 >

# 2 Re: Setting Font Color
My code:
RECT rect // this is the Edit box Rect
LRESULT CALLBACK EditClassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
case WM_PAINT:
HBRUSH hBrush;
PAINTSTRUCT ps;
hdc = BeginPaint( m_hWnd, &ps );
hBrush = CreateSolidBrush(rgb);
FillRect (hdc, &rect, hBrush);
DeleteObject (hBrush);
EndPaint( m_hWnd, &ps );
.............
..........
}
it changed the background color but in different position, why,
or how to fix this?
robin luo bin
robinluobin@hotmail.com
# 4 Re: Setting Font Color
// globals
HBRUSH hbrushEditBox = CreateSolidBrush(RGB(34,94,144)); // making a brush color (API)
//------------------
case WM_CTLCOLOREDIT: // Same as Static, only for EditBoxes
{
HDC hdcEdit = (HDC)wParam; //Get handles
SetTextColor(hdcEdit, RGB(255, 255, 255)); // Text color
SetBkMode(hdcEdit, TRANSPARENT); // EditBox Backround Mode (note: OPAQUE can be used)
SetBkColor(hdcEdit,(LONG)hbrushEditBox); // Backround color for EditBox
return (LONG)hbrushEditBox; // Paint it
}
break;
Bengi at 2007-11-9 13:05:57 >
