user13947011
user13947011

Reputation:

Making The Edit Control Transparent WinAPI (win32)

This is the relevant part of my code:

case WM_CTLCOLORBTN:
case WM_CTLCOLOREDIT:
case WM_CTLCOLORSTATIC:
    SetBkMode(HDC(wParam),TRANSPARENT);
    return LRESULT(HBRUSH(GetStockObject(NULL_BRUSH)));

It makes the background all the controls transparent, including the edit ones. But when some text is typed, it overwrites on itself and looks messy. How should I reset the visible area and redraw with the current situation? Should I process something inside WM_COMMANDs EN_CHANGE or WM_PAINT or something else?

Here is how it currently looks:

Upvotes: 5

Views: 1096

Answers (1)

user13947011
user13947011

Reputation:

I realized that once the control is hidden and shown again, it fixes the visibility as intended.

case WM_COMMAND:
    if(HIWORD(wParam)==EN_CHANGE)
    {
        ShowWindow(HWND(lParam),SW_HIDE);
        ShowWindow(HWND(lParam),SW_SHOW);
        SetFocus(HWND(lParam));
    }
    break;
case WM_CTLCOLORBTN:
case WM_CTLCOLOREDIT:
case WM_CTLCOLORSTATIC:
    SetBkMode(HDC(wParam),TRANSPARENT);
    return LRESULT(HBRUSH(GetStockObject(NULL_BRUSH)));

Result:
enter image description here

Upvotes: 4

Related Questions