-1

Is it possible to "transparent" the background of "edit box" in mfc vc++. I am trying different methods but not able to do that.

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
Lata
  • 11
  • 5
  • 2
    What methods have you tried? – Schmocken Mar 15 '19 at 12:05
  • @Schmocken see his previous question https://stackoverflow.com/questions/55179927/how-to-transparent-the-background-of-edit-box-in-mfc-vc – Jabberwocky Mar 15 '19 at 12:49
  • Possible duplicate of [how to transparent the background of edit box in mfc vc++?](https://stackoverflow.com/questions/55179927/how-to-transparent-the-background-of-edit-box-in-mfc-vc) – zett42 Mar 15 '19 at 13:24
  • I have used ONCTLCOLOR function and also try to use OnErasebackground function .but not able to getting the transparent background color for edit box – Lata Mar 16 '19 at 03:31

1 Answers1

1

Yes it is possible.

You have to create the class derived from CEdit and implement your own ON_WM_CTLCOLOR_REFLECT handler just like this:

BEGIN_MESSAGE_MAP(CTransparentEdit, CEdit)
    ON_WM_CTLCOLOR_REFLECT()
END_MESSAGE_MAP()

class CTransparentEdit : public CEdit
{
  ....
  CBrush   m_brBkgnd;
  afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor)
  {
    m_brBkgnd.DeleteObject();
    m_brBkgnd.CreateStockObject(NULL_BRUSH);
    pDC->SetBkMode(TRANSPARENT);
    return (HBRUSH)m_brBkgnd;
  }
}
Andrew Komiagin
  • 6,446
  • 1
  • 13
  • 23