Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2000-03-07
4
Medium Priority
?
580 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 120 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

722 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