Archived

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

khalligan

MFC - Changing background of CStatic

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);
  ASSERT_VALID(pWnd);
  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