0
votes

I'm creating a basic application in C++ (Win32 API). I tried to make a button with the CreateWindow() function as seen below:

button1 = CreateWindow("button", TEXT("Click Me!"), WS_TABSTOP | WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 100, 200, 70, 25, hwnd, (HMENU)NULL, NULL, NULL);

The problem is that there is a white border around the button as you can see here: Link

I tried to make it transparent with this code but is doesn't work.

case WM_CTLCOLORBTN:{
    HBRUSH hBrushbtn;
    hBrushbtn = (HBRUSH)GetStockObject(NULL_BRUSH);
    SetBkMode((HDC) wParam, TRANSPARENT);
    return ((LRESULT)hBrushbtn);
    break;
}

How can I do this?

Thanks

1

1 Answers

1
votes

SetBkMode() affects whether or not text rendering is transparent or not, which is not the issue here.

You're going to have to WM_PRINTCLIENT up to the parent control into the button's DC, as I demonstrate here. (Note that my code still calls SetBkMode() for transparent text in checkboxes, groupboxes, labels, etc.; for pushbuttons it won't matter if you're using visual styles).