Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 592
  • Last Modified:

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

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
wannabeguru
Asked:
wannabeguru
  • 2
1 Solution
 
inprasCommented:
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
 
V_BapatCommented:
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
 
V_BapatCommented:
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
 
wannabeguruAuthor Commented:
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now