Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OnCtlColor Use in MFC Application

Status
Not open for further replies.

sweep123

Technical User
May 1, 2003
185
GB
I want to change the colour of just two labels on a dialog, but I can only get the first label to change (Black backgroud with yellow text). I cant find the reason why the other If (ctrl2 == pWnd) will not work. It never goes in even then the pWnd is the same value as it.

What am I missing? .. See code below

BRUSH CTabFive::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
/* Arrange for the labels to be drawn in yellow on a black background. Also need to arrange for the background colour of the control to be black. */

HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

// Just want to arrange for the 2 IDU Last Key Press labels to be
// coloured yellow on a black background

if(nCtlColor == CTLCOLOR_STATIC)
{
CWnd* ctrl1 = GetDlgItem (IDC_IDU1_LASTKEY);
CWnd* ctrl2 = GetDlgItem (IDC_IDU2_LASTKEY);
//Is it one of the 2 label we are interested in
if(ctrl1 == pWnd)
{
pDC->SetBkColor(BLACK_BRUSH);
pDC->SetTextColor(RGB(255,255,0));
ctrl2 = pWnd;
return (HBRUSH)GetStoc
 
Do it like this

if(pWnd->GetDlgCtrlID()==IDC_STATIC1
|| pWnd->GetDlgCtrlID()==IDC_STATIC2)
{
pDC->SetBkColor(RGB(0,0,0));
pDC->SetTextColor(RGB(0,255,255)); // or whatever yellow is
}


Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top