A/A,
Follow the following steps:
1. Open the .h file (say "uFile.h") in which u want to change the color of a Textbox,
2. Write the declaration as:
public:
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
CBrush *brush;
3. Now open your .cpp (uFile.cpp) file,
4. In the Message_Map write ON_WM_CTLCOLOR() message handler as:
BEGIN_MESSAGE_MAP(CVCSDlg, CDialog)
.
.
.
.
.
.
ON_WM_CTLCOLOR()
END_MESSAGE_MAP()
5. Write an event hanler for the Message_Handler as
Code:
HBRUSH CuFile::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
switch (1)
{
case 1:
pDC->SetTextColor(RGB(255, 255, 255));
pDC->SetBkColor(RGB(0, 0, 0));
return (HBRUSH)(brush->GetSafeHandle());
default:
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}
return hbr;
}
Alternatively you can do it as follows:
1. Open the .h or .cpp,
2. Open the properties Window,
3. Click on Messages button at the top of this Properties Window,
4. Search for "OnCtlColor",
5. Click on the right side of it and add the "OnCtlColor",
6. Now you need only to add the following code in the event handler that is generated automatically.
Code:
switch (1)
{
case 1:
pDC->SetTextColor(RGB(255, 255, 255));
pDC->SetBkColor(RGB(0, 0, 0));
return (HBRUSH)(brush->GetSafeHandle());
default:
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
}
return hbr;
That will work for sure.
If u need further assistance, u r always welcome.
Allah Hafiz!