Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


MFC - Changing background of CStatic

This topic is 5281 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Im writing an app, where I click on a button and a colour dialog appears and I choose the colour, and when I do that I get the colour and store it in a COLORREF variable. I have labels on the dialog, now I want to set the background of these labels to the colour recieved from the colour dialog. I have overridden the WM_CTLCOLOR message to try to let me achieve this like so [souce] HBRUSH CPreferences::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); switch(nCtlColor) { case CTLCOLOR_STATIC: if(m_blCreateLabelCol) { hbr = ::CreateSolidBrush(RGB(255, 0, 0)); pDC->SetBkColor(RGB(255, 0, 0)); } break; } return hbr; } [/source] Then I call the function above when I click on the button for the colour dialog, like so:

  CWnd* pWnd = GetDlgItem(IDC_PREF_LBLBACK_COL_OUT);
  CDC *pDC;
  pDC = pWnd->GetDC();

  m_blCreateLabelCol = TRUE;
  OnCtlColor(pDC, pWnd, CTLCOLOR_STATIC);
  m_blCreateLabelCol = FALSE;
But it just wont work, is there anyone who has done this before, cos its really starting to wreck my head, for something that should be so simple. Keith

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!