Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CDialog

CDialog

Scheduled Pinned Locked Moved C / C++ / MFC
question
23 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U User 3037427

    How can i change the dialog box background color dynamically.:confused:

    N Offline
    N Offline
    Naveen
    wrote on last edited by
    #10

    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

    U 1 Reply Last reply
    0
    • N Naveen

      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

      U Offline
      U Offline
      User 3037427
      wrote on last edited by
      #11

      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:

      H V N 3 Replies Last reply
      0
      • U User 3037427

        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:

        H Offline
        H Offline
        Hamid Taebi
        wrote on last edited by
        #12

        what error you have previous error can you show your code that how to use to change background color_**


        **_

        whitesky


        1 Reply Last reply
        0
        • U User 3037427

          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:

          V Offline
          V Offline
          Viorel
          wrote on last edited by
          #13

          If you are using VS 2003 or VS 2005, you will found that the definition of SetDialogBkColor function in afxwin2.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.

          1 Reply Last reply
          0
          • H Hamid Taebi

            you ca use WM_CTLCOLORor WM_PAINT_**


            **_

            whitesky


            E Offline
            E Offline
            Eytukan
            wrote on last edited by
            #14

            Though you could do it by these ways, HandlingWM_ERASEBKGND is the right one for it.


            --[:jig:]-- [My Current Status]

            H 1 Reply Last reply
            0
            • U User 3037427

              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:

              N Offline
              N Offline
              Naveen
              wrote on last edited by
              #15

              ok... i Understood instead of calling the ChangeDialogColor from onPaint call this Function as the first line of OnCtlColor funtion nave

              U 1 Reply Last reply
              0
              • E Eytukan

                Though you could do it by these ways, HandlingWM_ERASEBKGND is the right one for it.


                --[:jig:]-- [My Current Status]

                H Offline
                H Offline
                Hamid Taebi
                wrote on last edited by
                #16

                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


                U 1 Reply Last reply
                0
                • N Naveen

                  ok... i Understood instead of calling the ChangeDialogColor from onPaint call this Function as the first line of OnCtlColor funtion nave

                  U Offline
                  U Offline
                  User 3037427
                  wrote on last edited by
                  #17

                  No its not working. Thanks for ur reply.:)

                  N 1 Reply Last reply
                  0
                  • U User 3037427

                    No its not working. Thanks for ur reply.:)

                    N Offline
                    N Offline
                    Naveen
                    wrote on last edited by
                    #18

                    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

                    U 1 Reply Last reply
                    0
                    • N Naveen

                      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

                      U Offline
                      U Offline
                      User 3037427
                      wrote on last edited by
                      #19

                      Sorry, its not working.:(

                      N 1 Reply Last reply
                      0
                      • U User 3037427

                        Sorry, its not working.:(

                        N Offline
                        N Offline
                        Naveen
                        wrote on last edited by
                        #20

                        ok yaar..I cannot figure out why its not working.... Well...Where r u working..? I am from India->Kerala.. nave

                        1 Reply Last reply
                        0
                        • H Hamid Taebi

                          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


                          U Offline
                          U Offline
                          User 3037427
                          wrote on last edited by
                          #21

                          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.:)

                          H 1 Reply Last reply
                          0
                          • U User 3037427

                            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.:)

                            H Offline
                            H Offline
                            Hamid Taebi
                            wrote on last edited by
                            #22

                            this code it seems not problem i tested this code and it work fine of course without if(m_clr.GetPos()!=0) like this BOOL CAnswerDlg::OnEraseBkgnd(CDC* pDC) { //int color=m_clr.GetPos(); COLORREF clr=RGB(53,97,200); CRect rect; GetClientRect(&rect); pDC->FillSolidRect(&rect,clr); return TRUE; } and controls are visible you can use WM_CTLCOLOR with a brush and it work and i think it good for you_**


                            **_

                            whitesky


                            U 1 Reply Last reply
                            0
                            • H Hamid Taebi

                              this code it seems not problem i tested this code and it work fine of course without if(m_clr.GetPos()!=0) like this BOOL CAnswerDlg::OnEraseBkgnd(CDC* pDC) { //int color=m_clr.GetPos(); COLORREF clr=RGB(53,97,200); CRect rect; GetClientRect(&rect); pDC->FillSolidRect(&rect,clr); return TRUE; } and controls are visible you can use WM_CTLCOLOR with a brush and it work and i think it good for you_**


                              **_

                              whitesky


                              U Offline
                              U Offline
                              User 3037427
                              wrote on last edited by
                              #23

                              I want to change the back ground of dialog when i move the slider ctrl. That's why i used int color=m_clr.GetPos(); Ths background of the dialog was changing but the controls are not visible.

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups