我正在使用此代码通过具有自定义图像的one按钮向窗口添加工具栏:
HWND hToolbar = CreateWindow(TOOLBARCLASSNAME, NULL,WS_CHILD | TBSTYLE_FLAT|TBSTYLE_AUTOSIZE |TBSTYLE_LIST|CCS_BOTTOM, 0, 0, 0, 0,hwnd, NULL, ghInstance, NULL); //create the toolbar
SendMessage(hToolbar, WM_SETFONT, (WPARAM)hFontBold, static_cast<LPARAM>(MAKELONG(TRUE, 0))); //set the font. there cannot be the problem
//↓↓↓↓↓**ILC_COLOR32 is specificied here but 32bit bmp is still not showing**//
auto hImagelist = ImageList_Create(32, 32,ILC_COLOR32|ILC_MASK,1, 0);
//↑↑↑↑↑**ILC_COLOR32 is specificied here but 32bit bmp is still not showing**//
HBITMAP bitmap = static_cast<HBITMAP>(LoadImage((HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
MAKEINTRESOURCE(ID_IMG_SPAWN),// <- ID_IMG_SPAWN is my custom resource
IMAGE_BITMAP, 32, 32, NULL));
ImageList_Add(hImagelist, bitmap, nullptr);
SendMessage(hToolbar, TB_SETIMAGELIST,static_cast<WPARAM>(0),(LPARAM)hImagelist);
在上面的代码中,ID_IMG_SPAWN
是我导入到Visual Studio的资源bmp图像。但是,Visual Studio弹出一个错误,提示它无法识别我的bmp,并且在运行应用程序时bmp显示blank。
Visual Studio告诉我我的bmp无法识别:
当应用运行时,其外观如下:
来自Google的后来我知道Visual Studio特此识别ONLY
24位bmp。因此,我将bmp转换为24bit并再次导入,将ILC_COLOR32
更改为ILC_COLOR24
,这确实有效。没有错误,并且我的图像显示在按钮上。
但是,我丢失了我的Alpha频道。因为,24位位图不支持Alpha通道
,最终导致我的图像具有难看的正方形背景。我需要你的帮助。感谢任何人回答我的长问题并阅读全文。
32px bmp文件https://drive.google.com/open?id=1w2BUSUA9h31FbpvZFWmBbVaIfViefsoN
我正在使用此代码通过一个具有自定义图像的按钮将工具栏添加到窗口:HWND hToolbar = CreateWindow(TOOLBARCLASSNAME,NULL,WS_CHILD | TBSTYLE_FLAT | TBSTYLE_AUTOSIZE | TBSTYLE_LIST | ...