Transparent Button?

Nov 3, 2010 at 1:42am
Hi, im trying to make my button edges blend into the background. Right now when i use

CreateWindowExA(WS_EX_TRANSPARENT,"BUTTON", "Msg", WS_VISIBLE|WS_CHILD, 156, 1, 86, 22, hWnd, NULL, NULL, NULL);

it does this

http://i55.tinypic.com/21kb1g2.png

Is there another way to make the background of the button to be the background color of the window.
Last edited on Nov 3, 2010 at 1:43am
Nov 3, 2010 at 9:35pm
Do you mean you want to get rid of that black border that defines the area of the button?
Nov 6, 2010 at 7:39pm
Yes, sorry for explaining it incorrectly.
Dec 9, 2010 at 2:26pm
I've encountered this problem too...

Try to handle WM_CTLCOLORBTN message

1
2
3
4
5
6
7
8
9
10
switch (message)
{
    case WM_CTLCOLORBTN:
            HBRUSH hBrushBtn;
            hBrushBtn = (HBRUSH) GetStockObject(NULL_BRUSH);
            SetBkMode((HDC) wParam, TRANSPARENT);
    return ((LRESULT) hBrushBtn);
}

return 0;


I suppose you know how to handle the messages :)

And create your button with CreateWindow() function. If you use CreateWindowEx() or other,
DON'T ADD WS_EX_TRANSPARENT FLAG !
Last edited on Dec 9, 2010 at 2:28pm
Dec 27, 2010 at 7:40pm
O.o I took out "WS_EX_TRANSPARENT" and the same thing happened. : (
Last edited on Dec 27, 2010 at 7:48pm
Jan 7, 2011 at 5:20pm
Then I don't know what happened when you've removed it :D
It didn't work for me when I added WS_EX_TRANSPARENT flag so if it works for you with that flag do it your way :) Windows is a really messed up thing...

And what Windows do you have ? 7 or XP ?
Last edited on Jan 7, 2011 at 5:22pm
Topic archived. No new replies allowed.