Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit Ctrl Colors Not quite Working

Status
Not open for further replies.

wduty

Programmer
Jun 24, 2000
271
US
I have an edit control in which I am changing the background and foreground colors.

The way I am doing it now is to get a COLORREF from a ChooseColor Dialog. A WM_PAINT message is then sent to the edit control which forces it to return an WM_CTLCOLOREDIT message to the main window which then does a SetBkColor() and SetTextColor().

The foreground color changes fine. The problem is that the background color only changes for the region of the edit control up to the last line of text. The rest of the text ctrl remains the original background color when the window was opened.

Here's the relevant code sections. Any suggestions appreciated.


HWND ghEdit;
HBRUSH ghBr;
COLORREF gFgCRef;
COLORREF gBgCRef;

int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
...
}

LRESULT CALLBACK MainProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{

RECT r;
switch(msg)
{
case WM_CREATE:
GetClientRect(hWnd, &r);
gFgCRef = RGB(200, 200, 200);
gBgCRef = RGB(255, 0, 0);
ghEdit = CreateWindow( "EDIT", "", WS_CHILD | WS_VISIBLE | ES_MULTILINE | WS_VSCROLL,
0, 0, r.right, r.bottom, hWnd, (HMENU)IDC_EDIT, ghInst, NULL);
ghBr = CreateSolidBrush(gBgCRef);
break;

case WM_SIZE:
GetClientRect(hWnd, &r);
MoveWindow(ghEdit, 0, 0, r.right, r.bottom, TRUE);
break;

case WM_COMMAND:
switch(LOWORD(wParam))
{
[red]//menu options for color selection[/red]
case CM_EDIT_FG:
OpenColorDialogBox(hWnd, TRUE);
break;

case CM_EDIT_BG:
OpenColorDialogBox(hWnd, FALSE);
break;
}


case WM_CTLCOLOREDIT:
SetTextColor((HDC)wParam, gFgCRef);
SetBkColor((HDC)wParam, gBgCRef);
return (DWORD) ghBr;
break;

case WM_CLOSE:
DestroyWindow(hWnd);

case WM_DESTROY:
PostQuitMessage(0);
DeleteObject(ghBr);
break;

default: return DefWindowProc(hWnd, msg, wParam, lParam);
}
return 0;
}


void OpenColorDialogBox(HWND hWnd, BOOL fg)
{
CHOOSECOLOR cc;
cc.Flags = CC_ANYCOLOR;
cc.hwndOwner = hWnd;
cc.lpTemplateName = NULL;
cc.lStructSize = sizeof(CHOOSECOLOR);
if(ChooseColor(&cc))
{
if(fg) gFgCRef = cc.rgbResult;
else gBgCRef = cc.rgbResult;
[red]//forces edit ctrl to send WM_CTLCOLOREDIT after user selects color[/red]
SendMessage(ghEdit, WM_PAINT, (WPARAM)GetDC(ghEdit), 0);
}
}



--Will Duty
wduty@radicalfringe.com

 
Will,

Take a look at the Platform SDK GDI API InvalidateRect()

Good luck
-pete
 
Pete,

Worked (with a few additional modifications). Thanks.

-Will

--Will Duty
wduty@radicalfringe.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top