CDialog
-
How can i change the dialog box background color dynamically.:confused:
you ca use
WM_CTLCOLOR
orWM_PAINT
_**
**_
whitesky
-
you ca use
WM_CTLCOLOR
orWM_PAINT
_**
**_
whitesky
But i want to chage the background depending on the color specified dynamically. I am getting an exception when i post the WM_CTLCOLOR message . Thanks for ur reply,
-
But i want to chage the background depending on the color specified dynamically. I am getting an exception when i post the WM_CTLCOLOR message . Thanks for ur reply,
i guess you getting exception because use a brush,yes? see here maybe it is some helpful to you
void CAnswerDlg::OnPaint() { CPaintDC dc(this); // device context for painting dc.FillSolidRect(0,0,GetSystemMetrics (SM_CXSCREEN),GetSystemMetrics (SM_CYSCREEN), RGB(53,97,200)); } -------------- HBRUSH CAnswerDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); return (HBRUSH)GetStockObject(WHITE_BRUSH); }
_**
**_
whitesky
-
How can i change the dialog box background color dynamically.:confused:
Try this
CRect rc; GetClientRect(&rc); // // Paint the client in the specified background color // pDC->FillSolidRect(&rc, m_clrBack);
Appu.. "If you judge people, you have no time to love them." -
How can i change the dialog box background color dynamically.:confused:
Hey Sruthi, Chk this.This contains everything. http://www.nntu.sci-nnov.ru/DISLRN/cpppage/q117778.htm[^] Appu.. "If you judge people, you have no time to love them."
-
i guess you getting exception because use a brush,yes? see here maybe it is some helpful to you
void CAnswerDlg::OnPaint() { CPaintDC dc(this); // device context for painting dc.FillSolidRect(0,0,GetSystemMetrics (SM_CXSCREEN),GetSystemMetrics (SM_CYSCREEN), RGB(53,97,200)); } -------------- HBRUSH CAnswerDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); return (HBRUSH)GetStockObject(WHITE_BRUSH); }
_**
**_
whitesky
The code was working fine. But the controls like edit box etc.. are not visible bcoz of FillSolidRect(). How can i solve this problem :)
-
The code was working fine. But the controls like edit box etc.. are not visible bcoz of FillSolidRect(). How can i solve this problem :)
Are you sure i test your problem but these are visible i used this code (editbox,button,radio,..)are visible
COLORREF Color; Color=GetDC()->GetBkColor(); .... .... void CAnswerDlg::OnPaint() { CPaintDC dc(this); // device context for painting dc.FillSolidRect(0,0,GetSystemMetrics (SM_CXSCREEN),GetSystemMetrics (SM_CYSCREEN), Color); } void CAnswerDlg::OnBnClickedButton1() { Color=RGB(53,97,200); Invalidate(); }
_**
**_
whitesky
-
How can i change the dialog box background color dynamically.:confused:
I think the appropriate place to change the background colour of your dialog box is the handler for
WM_ERASEBKGND
notification. You can put here just two lines:BOOL CMyDlg::OnEraseBkgnd(CDC* pDC) { pDC->FillRect(CRect(0,0,32000,32000), &CBrush(RGB(0,0,255))); // blue return TRUE; }
If you need to vary the colour (or just to optimize the solution), make a
CBrush
member variable and useCreateSolidBrush
to set the colour. You can useCreatePatternBrush
orCreateHatchBrush
to have another kind of background. -- modified at 3:13 Friday 16th June, 2006 -
How can i change the dialog box background color dynamically.:confused:
one way HBRUSH MYDialog::OnCtlColor( CDC* pDC_i, CWnd* pWnd_i, UINT uCtlColor_i ) { HBRUSH hDefaultBrush = CDialog::OnCtlColor( pDC_i, pWnd_i, uCtlColor_i ); if( CTLCOLOR_DLG == uCtlColor_i ) { // Return a black brush so that the background become balck return reinterpret_cast(GetStockObject( BLACK_BRUSH )); } return hDefaultBrush; } Another way from the InitInstance of the App class u may call SetDialogBkColor( RGB(255,0,0) ) nave
-
one way HBRUSH MYDialog::OnCtlColor( CDC* pDC_i, CWnd* pWnd_i, UINT uCtlColor_i ) { HBRUSH hDefaultBrush = CDialog::OnCtlColor( pDC_i, pWnd_i, uCtlColor_i ); if( CTLCOLOR_DLG == uCtlColor_i ) { // Return a black brush so that the background become balck return reinterpret_cast(GetStockObject( BLACK_BRUSH )); } return hDefaultBrush; } Another way from the InitInstance of the App class u may call SetDialogBkColor( RGB(255,0,0) ) nave
But the background color is not changing. Here is my code: OnPaint() { ............. CSliderApp* app=(CSliderApp*)AfxGetApp(); app->ChangeDialogColor((COLORREF)m_clr.GetPos()); } void CSliderApp::ChangeDialogColor(COLORREF ref) { SetDialogBkColor(ref); } Is there anything wrong:confused:
-
But the background color is not changing. Here is my code: OnPaint() { ............. CSliderApp* app=(CSliderApp*)AfxGetApp(); app->ChangeDialogColor((COLORREF)m_clr.GetPos()); } void CSliderApp::ChangeDialogColor(COLORREF ref) { SetDialogBkColor(ref); } Is there anything wrong:confused:
what error you have previous error can you show your code that how to use to change background color_**
**_
whitesky
-
But the background color is not changing. Here is my code: OnPaint() { ............. CSliderApp* app=(CSliderApp*)AfxGetApp(); app->ChangeDialogColor((COLORREF)m_clr.GetPos()); } void CSliderApp::ChangeDialogColor(COLORREF ref) { SetDialogBkColor(ref); } Is there anything wrong:confused:
If you are using VS 2003 or VS 2005, you will found that the definition of
SetDialogBkColor
function inafxwin2.inl
file is:_AFXWIN_INLINE void CWinApp::SetDialogBkColor(COLORREF /*clrCtlBk*/, COLORREF /*clrCtlText*/) { }
Therefore it does nothing. Documentation says that it is obsolete. You should consider other solutions.
-
you ca use
WM_CTLCOLOR
orWM_PAINT
_**
**_
whitesky
Though you could do it by these ways, Handling
WM_ERASEBKGND
is the right one for it.
--[:jig:]-- [My Current Status]
-
But the background color is not changing. Here is my code: OnPaint() { ............. CSliderApp* app=(CSliderApp*)AfxGetApp(); app->ChangeDialogColor((COLORREF)m_clr.GetPos()); } void CSliderApp::ChangeDialogColor(COLORREF ref) { SetDialogBkColor(ref); } Is there anything wrong:confused:
-
Though you could do it by these ways, Handling
WM_ERASEBKGND
is the right one for it.
--[:jig:]-- [My Current Status]
but i want to know why he cant show controls its attract for me to find answer for this question (of course i need to see his code that how to use)_**
**_
whitesky
-
ok... i Understood instead of calling the ChangeDialogColor from onPaint call this Function as the first line of OnCtlColor funtion nave
No its not working. Thanks for ur reply.:)
-
No its not working. Thanks for ur reply.:)
ok another way... forgot every thing done before...Now do as below 1. Create a member variable of CBrush say m_BkBrush 2. Write Function like this ChangeColor( COLORREF clr_i ) { if( m_BkBrush.m_hObject ) m_BkBrush.DeleteObject(); m_BkBrush.CreateSolidBrush( clr_i ) Invalidate(); } 3. Call this function in the OnInitDialog and where ever u want to change the color 4. now overide the WM_CTLCOLOR message and inside that write as below HBRUSH MYDialog::OnCtlColor( CDC* pDC_i, CWnd* pWnd_i, UINT uCtlColor_i ) { HBRUSH hDefaultBrush = CDialog::OnCtlColor( pDC_i, pWnd_i, uCtlColor_i ); if( CTLCOLOR_DLG == uCtlColor_i ) { return m_BkBrush; } return hDefaultBrush; } try and tell me the result..;) nave
-
ok another way... forgot every thing done before...Now do as below 1. Create a member variable of CBrush say m_BkBrush 2. Write Function like this ChangeColor( COLORREF clr_i ) { if( m_BkBrush.m_hObject ) m_BkBrush.DeleteObject(); m_BkBrush.CreateSolidBrush( clr_i ) Invalidate(); } 3. Call this function in the OnInitDialog and where ever u want to change the color 4. now overide the WM_CTLCOLOR message and inside that write as below HBRUSH MYDialog::OnCtlColor( CDC* pDC_i, CWnd* pWnd_i, UINT uCtlColor_i ) { HBRUSH hDefaultBrush = CDialog::OnCtlColor( pDC_i, pWnd_i, uCtlColor_i ); if( CTLCOLOR_DLG == uCtlColor_i ) { return m_BkBrush; } return hDefaultBrush; } try and tell me the result..;) nave
Sorry, its not working.:(
-
Sorry, its not working.:(
-
but i want to know why he cant show controls its attract for me to find answer for this question (of course i need to see his code that how to use)_**
**_
whitesky
My code is: BOOL CSliderDlg::OnEraseBkgnd(CDC* pDC) { if(m_clr.GetPos()!=0) { int color=m_clr.GetPos(); COLORREF clr=RGB(color,color,color); CRect rect; GetClientRect(&rect); pDC->FillSolidRect(&rect,clr); } return CDialog::OnEraseBkgnd(pDC); } I am calling this function from WM_HSCROLL handler. m_clr is the slider ctrl. If there is any mistake in my, let me that mistake. Thanx.:)