Home > OS >  Make Win32 edit control transparent (WM_CTLCOLOREDIT Nullbrush text issue)
Make Win32 edit control transparent (WM_CTLCOLOREDIT Nullbrush text issue)

Time:07-30

When i type something on an edit control which got its background 'transparent' by returning a NULL_BRUSH as response to WM_CTLCOLOREDIT into the WindowProc, it behaves weird with some visual glitches:

https://i.imgur.com/y4DxkIA.gif

case WM_CTLCOLOREDIT:
{
    SetBkMode((HDC)wParam, TRANSPARENT);
    return (LRESULT)GetStockObject(NULL_BRUSH);
}

When i minimize/restore the GUI looks like it 'repaint' the control to the correct state.

What am I missing?

CodePudding user response:

The edit control is trying to erase the wrong pixels by drawing the background colour over top of them, but now it's drawing a null brush so this doesn't actually erase the pixels and you see the leftover pixels.

You can't make a regular control transparent by making it not paint the background. That's just not a thing. Sorry.

The second time the control paints, it's not painting on top of a blank slate - it's painting on top of whatever it painted last time.

CodePudding user response:

AFAIK the only way to make the edit control appear transparent is to fake transparency by returning a brush from WM_CTLCOLOREDIT that looks like the background of the dialog. Transparent or NULL brushes are not supported.

This is trivial if the background is a single solid color. Just create a brush using Edit control bitmap background demo

  • Related