简体   繁体   English

具有透明背景的C ++按钮

[英]C++ Button with transparent background

I'm creating a basic application in C++ (Win32 API). 我正在用C ++(Win32 API)创建一个基本应用程序。 I tried to make a button with the CreateWindow() function as seen below: 我试图用CreateWindow()函数制作一个按钮,如下所示:

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 谢谢

SetBkMode() affects whether or not text rendering is transparent or not, which is not the issue here. SetBkMode()影响文本渲染是否透明,这不是这里的问题。

You're going to have to WM_PRINTCLIENT up to the parent control into the button's DC, as I demonstrate here . 正如我在此处演示的那样 ,您将必须WM_PRINTCLIENT直到父控件进入按钮的DC。 (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). (请注意,我的代码仍然为复选框,组框,标签等中的透明文本调用SetBkMode() ;对于按钮,如果您使用视觉样式,则无关紧要)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM