
Background color in CEdit Control ?
martin:
Yes, m_hYell is a member of the dialog, but the CBrush which owns the handle is
not. Make the CBrush a member variable of the dialog and extract its handle in
OnCtlColor().
I'm sure there is another way to do it, but since you're using MFC it makes
sense (to me) to limit the references to HBRUSH ro the OnCtlColor function
where it is needed.
HTH,
David Wilkinson
======================
Quote:
> Sorry - of course m_hYell is a menber of the dialog.
> > Martin:
> > Isn't your CBrush Brush going out of scope, taking its handle with it? You
> > need to make the brush itself a member variable of the dialog. Return the
> > HBRUSH of this brush in OnCtlColor().
> > HTH,
> > David Wilkinson
> > =======================
> > > Hy,
> > > I,m trying to change the background color of a CEdit control, but it
> seems
> > > it does not work the way i try.
> > > Only the the line of the cursor is set to the color i want, but not the
> > > whole CEdti control.
> > > Can anyone give me some advice.
> > > Thx.
> > > Martin
> > > Here is my sample code:
> > > BOOL CNotepadDlg::OnInitDialog()
> > > {
> > > CDialog::OnInitDialog();
> > > .
> > > .
> > > CBrush Brush;
> > > Brush.CreateSolidBrush( RGB(255,255,0) );
> > > m_hYell = (HBRUSH)Brush.GetSafeHandle();
> > > .
> > > .
> > > BRUSH CNotepadDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
> > > {
> > > // TODO: Change any attributes of the DC here
> > > if( nCtlColor == CTLCOLOR_EDIT )
> > > {
> > > pDC->SetBkColor(RGB(255,255,0));
> > > return m_hYell;
> > > }
> > > // TODO: Return a different brush if the default is not desired
> > > return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
> > > }