Question about CEdit
-
Hi. I set my dialog color to black with
GetStockObject( BLACK_BRUSH );
, then I put edit control with different 'BkColor'CDC *pEditDC=m_edtInfo.GetDC(); pEditDC->SetBkColor(RGB(230,251,251)); pEditDC->SetTextColor(RGB(255,255,255)); ReleaseDC(pEditDC);
When my dialog shows at first (before my edit control has no input string) I don't even see it (all dialog is black)! When I populate edit controlm_edtInfo.SetWindowText('some text')
text is displayed and edit ctrl's BkColor is shown but only behind the text not on all edit ctrl rectangle.why? How to get all edit ctrl's region being filled with BkColour, even at first? Thanks! P.S. My apology for my language. -
Hi. I set my dialog color to black with
GetStockObject( BLACK_BRUSH );
, then I put edit control with different 'BkColor'CDC *pEditDC=m_edtInfo.GetDC(); pEditDC->SetBkColor(RGB(230,251,251)); pEditDC->SetTextColor(RGB(255,255,255)); ReleaseDC(pEditDC);
When my dialog shows at first (before my edit control has no input string) I don't even see it (all dialog is black)! When I populate edit controlm_edtInfo.SetWindowText('some text')
text is displayed and edit ctrl's BkColor is shown but only behind the text not on all edit ctrl rectangle.why? How to get all edit ctrl's region being filled with BkColour, even at first? Thanks! P.S. My apology for my language.Trying to set the back colour like this will not work. You need to override WM_CTLCOLOR in the dialog class to change the colours of the dialog itself and its controls.
-
Hi. I set my dialog color to black with
GetStockObject( BLACK_BRUSH );
, then I put edit control with different 'BkColor'CDC *pEditDC=m_edtInfo.GetDC(); pEditDC->SetBkColor(RGB(230,251,251)); pEditDC->SetTextColor(RGB(255,255,255)); ReleaseDC(pEditDC);
When my dialog shows at first (before my edit control has no input string) I don't even see it (all dialog is black)! When I populate edit controlm_edtInfo.SetWindowText('some text')
text is displayed and edit ctrl's BkColor is shown but only behind the text not on all edit ctrl rectangle.why? How to get all edit ctrl's region being filled with BkColour, even at first? Thanks! P.S. My apology for my language.You can get the whole rectangle with
void CEdit::GetRect( LPRECT lpRect ) const;
and insteads of set the background of the CEdit, do it with the lpRect. Then use theCDialog::OnInitDialog ();
to make your changes and... remember to change the background of the dialog before changing/filling the editsGreetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you ;)
-
Hi. I set my dialog color to black with
GetStockObject( BLACK_BRUSH );
, then I put edit control with different 'BkColor'CDC *pEditDC=m_edtInfo.GetDC(); pEditDC->SetBkColor(RGB(230,251,251)); pEditDC->SetTextColor(RGB(255,255,255)); ReleaseDC(pEditDC);
When my dialog shows at first (before my edit control has no input string) I don't even see it (all dialog is black)! When I populate edit controlm_edtInfo.SetWindowText('some text')
text is displayed and edit ctrl's BkColor is shown but only behind the text not on all edit ctrl rectangle.why? How to get all edit ctrl's region being filled with BkColour, even at first? Thanks! P.S. My apology for my language.Easiest would be if you look into one of the controls shown in the Editcontrol-section of codeproject[^]. You will find a lot of source code to look how it is done. Chris Losinger has made a coloring Editcontrol I use.
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
George Orwell, "Keep the Aspidistra Flying", Opening words -
Trying to set the back colour like this will not work. You need to override WM_CTLCOLOR in the dialog class to change the colours of the dialog itself and its controls.
Thanks for replay. I'm already overriding that:
HBRUSH CDialList::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if( nCtlColor == CTLCOLOR_DLG ) { m_myHbr = (HBRUSH) GetStockObject( BLACK_BRUSH ); } return m_myHbr; }
for setting my dialog color to black! You are saying I can put more code on it and deal with color for my edit ctrl. Ok I put additional line code (if statement):if( nCtlColor == CTLCOLOR_EDIT )
but can you tell me what to use to set color to RGB value and not to use GetStockObject? Thanks! -
Thanks for replay. I'm already overriding that:
HBRUSH CDialList::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if( nCtlColor == CTLCOLOR_DLG ) { m_myHbr = (HBRUSH) GetStockObject( BLACK_BRUSH ); } return m_myHbr; }
for setting my dialog color to black! You are saying I can put more code on it and deal with color for my edit ctrl. Ok I put additional line code (if statement):if( nCtlColor == CTLCOLOR_EDIT )
but can you tell me what to use to set color to RGB value and not to use GetStockObject? Thanks!This is how it looks now:
HBRUSH CDialList::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if( nCtlColor == CTLCOLOR_DLG )//for dialog { m_myHbr = (HBRUSH) GetStockObject( BLACK_BRUSH ); } if( nCtlColor == CTLCOLOR_EDIT )//for edit ctrl { CDC *pEditDC=m_edtInfo.GetDC(); //set text to black SetTextColor(*pEditDC,RGB(255,255,255)); //set background to RGB(230,251,251) m_myHbr = (HBRUSH) pEditDC->SetBkColor(RGB(230,251,251)); ReleaseDC(pEditDC); } return m_myHbr; }
But unfortunate still doesn't work!?! -
This is how it looks now:
HBRUSH CDialList::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if( nCtlColor == CTLCOLOR_DLG )//for dialog { m_myHbr = (HBRUSH) GetStockObject( BLACK_BRUSH ); } if( nCtlColor == CTLCOLOR_EDIT )//for edit ctrl { CDC *pEditDC=m_edtInfo.GetDC(); //set text to black SetTextColor(*pEditDC,RGB(255,255,255)); //set background to RGB(230,251,251) m_myHbr = (HBRUSH) pEditDC->SetBkColor(RGB(230,251,251)); ReleaseDC(pEditDC); } return m_myHbr; }
But unfortunate still doesn't work!?!You shouldn't be getting a DC for the control. Everything you need is passed to your OnCtlColor() method. You should use the passed DC. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: