Solved

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

Posted on 2000-03-07
4
562 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to understand recursion 12 229
IdTelnet1DataAvailable handler freezes the Application 4 84
Would like to move button in a function 3 79
Grammars for C C++ and java 1 131
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

840 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