VincentWei / MiniGUI

A modern and mature cross-platform window system for embedded systems and smart IoT devices.
http://www.minigui.com
GNU General Public License v3.0
695 stars 157 forks source link

控件透明问题 #36

Closed GarrickLin closed 3 years ago

GarrickLin commented 4 years ago

目前使用版本 3.2

static void CreatePopUpMenu(HWND hWnd)
{
    // HDC hdc = GetClientDC(hWnd);
    hStaticWnd1.Create("static",
        "",
        WS_CHILD | WS_VISIBLE | SS_CENTER | SS_BITMAP | WS_EX_TRANSPARENT,
        // WS_CHILD | WS_VISIBLE | SS_CENTER | SS_BITMAP,
        IDC_STATIC1,
        1040, 0, 240, 720, hWnd, (DWORD)menubmp.bmp.get());
    // 1040, 0, 240, 720, hWnd, 0);
    SetWindowBkColor(hStaticWnd1.handle, 0x7f1d233a);

    hButton1.Create("button",
        "",
        WS_CHILD | BS_NOTIFY | BS_BITMAP | WS_VISIBLE | BS_NOBORDER
            | WS_EX_TRANSPARENT,
        // WS_CHILD | BS_NOTIFY | BS_BITMAP | WS_VISIBLE | BS_NOBORDER,
        IDC_BUTTON1,
        80, 20, 80, 120, hStaticWnd1.handle, (DWORD)btnbmp1.bmp.get());
    SetWindowBkColor(hButton1.handle, 0x7f1d233a);
}

微信截图_20200408184436

如图,右边蓝色是个 static 标签,上面贴有一个带透明的按钮,但是透明部分没有和背景融合,也设置了背景颜色,仍然不行。

VincentWei commented 4 years ago

Some issues I found in your code:

  1. you should specify extended styles like WS_EX_TRANSPARENT in dwExStyle argument. You should not OR'd general styles with extended styles.
  2. You should load the bitmap from a PNG file which has defined the transparent color.
  3. SetWindowBkColor does not make sense for the transparent control.
  4. You should pass a pixel value for SetWindowBkColor instead of a RGB DWORD value unless that the screen video mode is 32bit RGBA.

Hope this help you! Good luck.