CEdit background color problem with multiline edit
Dave Tucker -- orca!dtucker@netcom.com Tuesday, March 26, 1996 I am setting the background color of a multiline CEdit using the = OnCtlColor message. The CEdit is a child of an OLE control. Environment: MSVC 1.52c, MFC 2.5 OS: Win95 & Win 3.1 OCX Control using VB16 4.0 as container. The background color of the CEdit is set correctly, but when I enter = text in the edit, the text displays using the background color of the = control, not the background color that I set and returned in my = OnCtlColor message. I tried setting the background mode to TRANSPARENT = in OnCtlColor which gives me the correct background color, but then = backspace, delete, etc. don't update the screen correctly when I am = typing. Following is a section of the code I am using: HBRUSH CQueryCtrlRect::OnCtlColor (CDC* pDC, CWnd* pWnd, UINT nCtlColor) = { switch ( nCtlColor ) { =20 case CTLCOLOR_EDIT: =20 // Following line causes CEdit to display correctly but doesn't = update when I use Backspace, etc. // pDC->SetBkMode ( TRANSPARENT ); pDC->SetTextColor ( RGB(0,0,255) ); pDC->SetBkColor ( m_EditHiliteBackColor ); return (HBRUSH)( m_pEditNormalBackBrush->GetSafeHandle() ); =20 } =09 return CWnd::OnCtlColor(pDC, pWnd, nCtlColor); } Any Ideas? Thanks -------------------------------------------------------------------------= ----- Dave Tucker T.R.A.D.E., Inc. dtucker@tradeinfo.com Ph: (415) 513-0940 ext. 225 Fax: (415) 513-0944 -------------------------------------------------------------------------= -----
Elliott Kleinrock -- ELLIOTT@flexi.com Friday, March 29, 1996 [Mini-digest: 2 responses] If the color you set your edit control to is not one of a limited set of 'major' colors, this is the behavior you will get. In your SetBkColor try setting your RGB values to 0, 128, or 255 only. - Elliott -----From: "Mike Blaszczak"Call the base-class implementation of OnCtlColor() _first_. Then, if the control interests you, call yours. That is, rewrite your code to be like this: HBRUSH CQueryCtrlRect::OnCtlColor (CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbrRet = CWnd::OnCtlColor(pDC, pWnd, nCtlColor); switch ( nCtlColor ) { case CTLCOLOR_EDIT: // pDC->SetBkMode ( TRANSPARENT ); pDC->SetTextColor ( RGB(0,0,255) ); pDC->SetBkColor ( m_EditHiliteBackColor ); return (HBRUSH)( m_pEditNormalBackBrush->GetSafeHandle() ); } return hbrRet; } If you think about it, the way you've written the function will always call the base class to effectively undo the processing you've just done. .B ekiM Ride to work, work to ride.
| Вернуться в корень Архива |