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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Background color

Background color

Scheduled Pinned Locked Moved C / C++ / MFC
question
11 Posts 4 Posters 1 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.
  • A ArielR

    Does exist a simple way to change the background color of edit and button ctrls when has the focus? thanks VC6++

    N Offline
    N Offline
    Nelek
    wrote on last edited by
    #2

    Take a look in SetBkColor ()

    Greetings. -------- 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 ;)

    T 1 Reply Last reply
    0
    • A ArielR

      Does exist a simple way to change the background color of edit and button ctrls when has the focus? thanks VC6++

      T Offline
      T Offline
      ThatsAlok
      wrote on last edited by
      #3

      ArielR wrote:

      Does exist a simple way to change the background color of edit and button ctrls when has the focus? thanks VC6++

      you need to SUBCLASS that control to achieve same.. search SUBCLASS by mr Chris!

      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
      Never mind - my own stupidity is the source of every "problem" - Mixture

      cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

      A S 2 Replies Last reply
      0
      • N Nelek

        Take a look in SetBkColor ()

        Greetings. -------- 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 ;)

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #4

        Nelek wrote:

        Take a look in SetBkColor ()

        it will not work.. you have to subclass

        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
        Never mind - my own stupidity is the source of every "problem" - Mixture

        cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

        S 1 Reply Last reply
        0
        • T ThatsAlok

          ArielR wrote:

          Does exist a simple way to change the background color of edit and button ctrls when has the focus? thanks VC6++

          you need to SUBCLASS that control to achieve same.. search SUBCLASS by mr Chris!

          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
          Never mind - my own stupidity is the source of every "problem" - Mixture

          cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

          A Offline
          A Offline
          ArielR
          wrote on last edited by
          #5

          Thank for your reply. The SUBCLASS change the background color by the mouse movement. I need to change the color when it was focused by mouse or tab order. Could you help me? Thanks

          1 Reply Last reply
          0
          • T ThatsAlok

            Nelek wrote:

            Take a look in SetBkColor ()

            it will not work.. you have to subclass

            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
            Never mind - my own stupidity is the source of every "problem" - Mixture

            cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

            S Offline
            S Offline
            Stephen Hewitt
            wrote on last edited by
            #6

            Not true. Consider this code (dots are code that's been omitted): ================================================================= In ".h" file. ------------- class CFocusColourDlg : public CDialog { . . . // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CFocusColourDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam); //}}AFX_VIRTUAL // Implementation protected: HICON m_hIcon; CBrush m_RedBrush; // Generated message map functions //{{AFX_MSG(CFocusColourDlg) virtual BOOL OnInitDialog(); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor); afx_msg void OnDestroy(); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; In ".cpp" file. --------------- . . . BEGIN_MESSAGE_MAP(CFocusColourDlg, CDialog) //{{AFX_MSG_MAP(CFocusColourDlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_WM_CTLCOLOR() ON_WM_DESTROY() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CFocusColourDlg message handlers BOOL CFocusColourDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here m_RedBrush.CreateSolidBrush(RGB(255, 0, 0)); return TRUE; // return TRUE unless you set the focus to a control } . . . BOOL CFocusColourDlg::OnCommand(WPARAM wParam, LPARAM lParam) { WORD NotifyCode = HIWORD(wParam); WORD Id = LOWORD(wParam); HWND hWnd = reinterpret_cast(lParam); if (NotifyCode==EN_SETFOCUS || NotifyCode==EN_KILLFOCUS) { ::InvalidateRect(hWnd, NULL, TRUE); } return CDialog::OnCommand(wParam, lParam); } HBRUSH CFocusColourDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (pWnd->GetSafeHwnd() == ::GetFocus()) { pDC->SetBkColor(RGB(255, 0, 0)); return m_RedBrush; } return hbr; } void CFocusColourDlg::OnDestroy() { CDialog::OnDestroy(); m_RedBrush.DeleteObject(); } Steve

            T 1 Reply Last reply
            0
            • T ThatsAlok

              ArielR wrote:

              Does exist a simple way to change the background color of edit and button ctrls when has the focus? thanks VC6++

              you need to SUBCLASS that control to achieve same.. search SUBCLASS by mr Chris!

              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
              Never mind - my own stupidity is the source of every "problem" - Mixture

              cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #7

              Not so. See here[^]

              Steve

              T 1 Reply Last reply
              0
              • A ArielR

                Does exist a simple way to change the background color of edit and button ctrls when has the focus? thanks VC6++

                S Offline
                S Offline
                Stephen Hewitt
                wrote on last edited by
                #8

                You could subclass it or use this[^] approach.

                Steve

                1 Reply Last reply
                0
                • S Stephen Hewitt

                  Not so. See here[^]

                  Steve

                  T Offline
                  T Offline
                  ThatsAlok
                  wrote on last edited by
                  #9

                  he he he.. good one.. i already got your answer:)

                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
                  Never mind - my own stupidity is the source of every "problem" - Mixture

                  cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

                  1 Reply Last reply
                  0
                  • S Stephen Hewitt

                    Not true. Consider this code (dots are code that's been omitted): ================================================================= In ".h" file. ------------- class CFocusColourDlg : public CDialog { . . . // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CFocusColourDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam); //}}AFX_VIRTUAL // Implementation protected: HICON m_hIcon; CBrush m_RedBrush; // Generated message map functions //{{AFX_MSG(CFocusColourDlg) virtual BOOL OnInitDialog(); afx_msg void OnPaint(); afx_msg HCURSOR OnQueryDragIcon(); afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor); afx_msg void OnDestroy(); //}}AFX_MSG DECLARE_MESSAGE_MAP() }; In ".cpp" file. --------------- . . . BEGIN_MESSAGE_MAP(CFocusColourDlg, CDialog) //{{AFX_MSG_MAP(CFocusColourDlg) ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_WM_CTLCOLOR() ON_WM_DESTROY() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CFocusColourDlg message handlers BOOL CFocusColourDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here m_RedBrush.CreateSolidBrush(RGB(255, 0, 0)); return TRUE; // return TRUE unless you set the focus to a control } . . . BOOL CFocusColourDlg::OnCommand(WPARAM wParam, LPARAM lParam) { WORD NotifyCode = HIWORD(wParam); WORD Id = LOWORD(wParam); HWND hWnd = reinterpret_cast(lParam); if (NotifyCode==EN_SETFOCUS || NotifyCode==EN_KILLFOCUS) { ::InvalidateRect(hWnd, NULL, TRUE); } return CDialog::OnCommand(wParam, lParam); } HBRUSH CFocusColourDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (pWnd->GetSafeHwnd() == ::GetFocus()) { pDC->SetBkColor(RGB(255, 0, 0)); return m_RedBrush; } return hbr; } void CFocusColourDlg::OnDestroy() { CDialog::OnDestroy(); m_RedBrush.DeleteObject(); } Steve

                    T Offline
                    T Offline
                    ThatsAlok
                    wrote on last edited by
                    #10

                    but according to OPPs principal.. i am just abstracting that thing from outer world i.e. Dialog!

                    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
                    Never mind - my own stupidity is the source of every "problem" - Mixture

                    cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

                    S 1 Reply Last reply
                    0
                    • T ThatsAlok

                      but according to OPPs principal.. i am just abstracting that thing from outer world i.e. Dialog!

                      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
                      Never mind - my own stupidity is the source of every "problem" - Mixture

                      cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

                      S Offline
                      S Offline
                      Stephen Hewitt
                      wrote on last edited by
                      #11

                      This approach doesn't necessarily break OOP principles; there's nothing wrong with an edit control asking its parent what colour it should use.

                      Steve

                      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