Solved

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

Posted on 2000-03-07
4
561 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
ID: 2595091
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
ID: 2595133
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
ID: 2595145
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
ID: 2603345
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

831 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