Solved

Control of forecolor and backcolor of a control using VC++ 6.0

Posted on 2000-03-07
4
557 Views
Last Modified: 2012-06-21
In Visual Basic, it's really easy to control the forecolor, backcolor, inside of an edit box or combo box, but how do you do this in VC++ ?
0
Comment
Question by:wannabeguru
  • 2
4 Comments
 
LVL 4

Expert Comment

by:inpras
Comment Utility
U have to derive UR class from CComboBox and CEdit and map handler OnCtrlColor and return the desired brush from there..
Hope this helps
0
 
LVL 3

Accepted Solution

by:
V_Bapat earned 30 total points
Comment Utility
Look at the technical note 62(TN062) in MSDN help. This tells you step by step how to change it for edit control.


This is an example from MSDN:

// This OnCtlColor handler will change the color of a static control
// with the ID of IDC_MYSTATIC. The code assumes that the CMyDialog
// class has an initialized and created CBrush member named m_brush.
// The control will be painted with red text and a background
// color of m_brush.

HBRUSH CZilchDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
   // Call the base class implementation first! Otherwise, it may
   // undo what we're trying to accomplish here.
   HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

   // Are we painting the IDC_MYSTATIC control? We can use
   // CWnd::GetDlgCtrlID() to perform the most efficient test.
   if (pWnd->GetDlgCtrlID() == IDC_MYSTATIC)
   {
      // Set the text color to red
      pDC->SetTextColor(RGB(255, 0, 0));

      // Set the background mode for text to transparent
      // so background will show thru.
      pDC->SetBkMode(TRANSPARENT);

      // Return handle to our CBrush object
      hbr = m_brush;
   }

   return hbr;
}


Also see help for CWnd::OnCtlColor in MSDN.
0
 
LVL 3

Expert Comment

by:V_Bapat
Comment Utility
You can this also for edit control:

HBRUSH MyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
   CBrush brush;
   brush.CreateSolidBrush(RGB(255, 0, 0));
   if(nCtlColor == CTLCOLOR_EDIT)
   {
      pDC->SetBkColor(brush);
      pDC->SetTextColor(m_clrText);
      return brush;
   }
}

0
 

Author Comment

by:wannabeguru
Comment Utility
Thanks to v_bapat for the comment.  TN062 in MSDN is excellent.  I just needed someone to point me in the right direction !

  wannabeguru
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now