CEdit Control Problem - Bkgr color
-
The edit control has a grey background & black text, but the grey background only fills as far as the text, the rest of the edit control's background is WHITE. HOW CAN I FILL THE WHOLE BACKGROUND COLOR AS GREY. edit controls properties is set at read-only. OnCtlColor code..... HBRUSH CRSStationDefOne::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor==CTLCOLOR_EDIT) { CRSValueLoadApp* pApp = (CRSValueLoadApp*)AfxGetApp(); pDC->SetBkColor(pApp->BK_COLOR); pDC->SetTextColor(pApp->FG_COLOR); return hbr; } return NULL; } Gerry.
-
The edit control has a grey background & black text, but the grey background only fills as far as the text, the rest of the edit control's background is WHITE. HOW CAN I FILL THE WHOLE BACKGROUND COLOR AS GREY. edit controls properties is set at read-only. OnCtlColor code..... HBRUSH CRSStationDefOne::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor==CTLCOLOR_EDIT) { CRSValueLoadApp* pApp = (CRSValueLoadApp*)AfxGetApp(); pDC->SetBkColor(pApp->BK_COLOR); pDC->SetTextColor(pApp->FG_COLOR); return hbr; } return NULL; } Gerry.
You need to change the brush. 1) add a member variable in the dialog: CBrush m_brush; 2) init in in OnInitDialog() : m_brush.CreateSolidBrush(pApp->BK_COLOR); 3) in the destructor : m_brush.DeleteObject(); 4) modify your OnCtlColor() function : HBRUSH CRSStationDefOne::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor==CTLCOLOR_EDIT) { CRSValueLoadApp* pApp = (CRSValueLoadApp*)AfxGetApp(); pDC->SetBkColor(pApp->BK_COLOR); pDC->SetTextColor(pApp->FG_COLOR); return (HBRUSH)m_brush.GetSafeHandle(); } return hbr; // why did you return NULL here ? }
-
The edit control has a grey background & black text, but the grey background only fills as far as the text, the rest of the edit control's background is WHITE. HOW CAN I FILL THE WHOLE BACKGROUND COLOR AS GREY. edit controls properties is set at read-only. OnCtlColor code..... HBRUSH CRSStationDefOne::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor==CTLCOLOR_EDIT) { CRSValueLoadApp* pApp = (CRSValueLoadApp*)AfxGetApp(); pDC->SetBkColor(pApp->BK_COLOR); pDC->SetTextColor(pApp->FG_COLOR); return hbr; } return NULL; } Gerry.
You need to change the brush. 1) add a member variable in the dialog: CBrush m_brush; 2) init in in OnInitDialog() : m_brush.CreateSolidBrush(pApp->BK_COLOR); 3) in the destructor : m_brush.DeleteObject(); 4) modify your OnCtlColor() function : HBRUSH CRSStationDefOne::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor==CTLCOLOR_EDIT) { CRSValueLoadApp* pApp = (CRSValueLoadApp*)AfxGetApp(); pDC->SetBkColor(pApp->BK_COLOR); pDC->SetTextColor(pApp->FG_COLOR); return (HBRUSH)m_brush.GetSafeHandle(); } return hbr; // why did you return NULL here ? }
-
You need to change the brush. 1) add a member variable in the dialog: CBrush m_brush; 2) init in in OnInitDialog() : m_brush.CreateSolidBrush(pApp->BK_COLOR); 3) in the destructor : m_brush.DeleteObject(); 4) modify your OnCtlColor() function : HBRUSH CRSStationDefOne::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (nCtlColor==CTLCOLOR_EDIT) { CRSValueLoadApp* pApp = (CRSValueLoadApp*)AfxGetApp(); pDC->SetBkColor(pApp->BK_COLOR); pDC->SetTextColor(pApp->FG_COLOR); return (HBRUSH)m_brush.GetSafeHandle(); } return hbr; // why did you return NULL here ? }
Thank you Mr Anonymous, this works brilliant. We have to change lots of dialog classes, is there a place, perhaps at the app level, we could create the solidbrush & it would work for all dialogs.... Currently, we are creating the brushes in each class, this works. Again, Thanks..... Gerry.