Originally posted by: Crercio O. Silva
Although I have seen many suggestions on dealign with multiline and ReadOnly CEdit I wonder if there is a way to change the background color of a CEditView derived class.
Great work by the way.
Originally posted by: sansingh
can anybody help me be able to change the background color of a button on a dialog box
regards
sansingh
There is no way to change background color. I tried all the possible ways. Finally I succeeded by painting the button background with the selected color. Here are the steps I followed: Override WM_CTLCOLOR message in your dialog class. Create solid brush with the intended color. Select it in the buttons device context. Get the client area of button. Call the FillRect() function of buttons device context by passing the brush handle & client area of button. Regards, Sanjiv SReply
Originally posted by: Jose Reyes
HBRUSH CTranparentEdit::CtlColor(CDC* pDC, UINT nCtlColor)
pDC->SetBrushOrg( 0, 0 );
pDC->SetBkMode(TRANSPARENT);
To create the background bitmap we can use a code like the
void CTransparentEdit::PrepareBackground( CRect pos )
CClientDC thisDC( this );
CClientDC viewDC( m_pView );
m_Background.DeleteObject();
thisMem.CreateCompatibleDC( &thisDC );
viewMem.CreateCompatibleDC( &viewDC );
thisMem.BitBlt( 0, 0, pos.Size().cx, pos.Size().cy, &viewMem, pos.left, pos.top, SRCCOPY );
thisMem.SelectObject( pOldThisBmp );
// Create the brush here to make the code faster
m_Brush.CreatePatternBrush( &m_Background );
What if, in order to create a transparent edit, we use a
pattern brush with a bitmap which duplicate the drawing on
the parent window. The code for the CtlColor message will
look like:
{
pDC->SelectObject( &m_Brush );
return m_Brush;
}
above:
(The rectangle "pos" is the position of the editor inside
the parent window. We assume here that we have the bitmap
m_drawBmp in the parent window, with the whole window
content in it).
{
ASSERT_VALID( m_pView );
CBitmap* pOldThisBmp;
CDC thisMem;
CBitmap* pOldViewBmp;
CDC viewMem;
m_Background.CreateCompatibleBitmap( &thisDC, pos.Size().cx, pos.Size().cy );
pOldThisBmp = thisMem.SelectObject( &m_Background );
pOldViewBmp = viewMem.SelectObject( &m_pView->m_drawBmp );
viewMem.SelectObject( pOldViewBmp );
//
m_Brush.DeleteObject();
if ( m_Brush.m_hObject != NULL )
m_Brush.UnrealizeObject();
}
Originally posted by: Melonie
Thanks so much for putting this out here. It's saved me a great deal of time and was just what I was looking for.
ReplyOriginally posted by: Jose
The solution is really great. If you want to use it for read-only CEdits, you just have to change CTLCOLOR_MSGBOX for CTLCOLOR_STATIC. George Sgouros also proposes something similar in a reply, so thanks to both, George and Duncan.
--Jose.
Originally posted by: lamback
It is a unbelievable easy way. Thanx a lot.
ReplyOriginally posted by: Radhakrishna.B.L
I want to create a component of Editbox (edit control)with different functions in it,for example:size (),Foreground (),Background () etc,where ever I create an object of this I want an editbox with default settings,I want handle the notifications dynamically ,since the component will be created dynamically,I cannot write the ON_COMMAND Notifications.
Regards
Radhakrishna.B.L
Originally posted by: The FreelancE
If You Don't Want To Overload Standard CEdit Control This Is the Best and Fast Solution
Thanks For The Code
Reply
Originally posted by: Dragonsnack
How can I set the backgroundcolor of a multiline editctrl ?
I�ve tested it with OnCtlColor but only the lines with text in it where colorized. But I want to set the background und textcolor for the whole EditCtrl. Any Ideas ? Thx
Originally posted by: Itay Frommer
Your OnCtlColor example helped me a lot. However, it did not work until I added ON_WM_CTLCOLOR() under BEGIN_MESSAGE_MAP(CEditDlg, CDialog).
See:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q117778
Thanks a lot anyway,
Itay.