worker018
asked on
changing label text color
It's very smple question but I can't find solution.
I wanted to use a differnt style label, so changed
the font and font size, but couldn't change text
colot and background color.
It's there any suggestion?
I wanted to use a differnt style label, so changed
the font and font size, but couldn't change text
colot and background color.
It's there any suggestion?
What is a label?
You can't set this in the dialog editor.
At runtime, you need to handle WM_CTLCOLOR for the control and set its color that way. That means you need to give the control a real ID, and not IDC_STATIC (which is -1).
..B ekiM
At runtime, you need to handle WM_CTLCOLOR for the control and set its color that way. That means you need to give the control a real ID, and not IDC_STATIC (which is -1).
..B ekiM
Here's a code framgnet:
HBRUSH CYourDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->GetDlgCtrlID() == IDC_FOO)
{
pDC->SetTextColor(RGB(255, 0, 0));
}
return hbr;
}
Obviously, you'll use whatever ID you want in place of IDC_FOO. Also, you can pick any color; I used RGB(255, 0, 0) which is red.
..B ekiM
HBRUSH CYourDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->GetDlgCtrlID() == IDC_FOO)
{
pDC->SetTextColor(RGB(255,
}
return hbr;
}
Obviously, you'll use whatever ID you want in place of IDC_FOO. Also, you can pick any color; I used RGB(255, 0, 0) which is red.
..B ekiM
Is worker018 talking about a static control?
> Is worker018 talking about a static control?
I would say so. Some Windows environments call 'em labels.
..B ekiM
I would say so. Some Windows environments call 'em labels.
..B ekiM
ASKER
Oh sorry, I mean static control.
but, I can't understand how can I use your code
==========================
HBRUSH CScan04Dlg::OnCtlColor(CDC
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->GetDlgCtrlID() == IDC_FOO){
pDC->SetTextColor(RGB(255,
}
return hbr;
}
==========================
I inserted this code in my dialog, and wrote the header file.
and replace IDC_FOO to IDC_POSITION (my control name)
what can I do next?
ASKER
Oh sorry, I mean static control.
but, I can't understand how can I use your code
==========================
HBRUSH CScan04Dlg::OnCtlColor(CDC
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->GetDlgCtrlID() == IDC_FOO){
pDC->SetTextColor(RGB(255,
}
return hbr;
}
==========================
I inserted this code in my dialog, and wrote the header file.
and replace IDC_FOO to IDC_POSITION (my control name)
what can I do next?
Hi worker018,
take a look at http://www.codeguru.com/staticctrl/label_static.shtml for a extended CStatic derived class code and sample ...
hope that helps,
ZOPPO
take a look at http://www.codeguru.com/staticctrl/label_static.shtml for a extended CStatic derived class code and sample ...
hope that helps,
ZOPPO
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your answer.