【问题标题】:Win32 Toolbars and 24bit ImagesWin32 工具栏和 24 位图像
【发布时间】:2014-01-16 15:58:37
【问题描述】:

WinAPI 是否支持 24 位以上的图像?我想使用 24 位图标(更多定义)作为工具栏按钮图像。我已经加载了这样的图标:

// create toolbar
HWND hTool = CreateWindowEx( 0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
                        m_hWnd[ AUXILIARY_VIEWPORT ], ( HMENU )IDC_TEX_TOOL, GetModuleHandle( NULL ), NULL );

// Send the TB_BUTTONSTRUCTSIZE message, which is required for backward compatibility.
SendMessage( hTool, TB_BUTTONSTRUCTSIZE, ( WPARAM )sizeof( TBBUTTON ), 0 );
SendMessage( hTool, TB_SETBUTTONSIZE, 0, MAKELPARAM( 32, 32 ) );
SendMessage( hTool, TB_SETBITMAPSIZE, 0, MAKELPARAM( 32, 32 ) );

// declare button and bitmap structs
TBBUTTON tbb[ 19 ];
TBADDBITMAP tbab;

HICON hIcon = ( HICON )LoadIcon( GetModuleHandle( NULL ), MAKEINTRESOURCE( IDI_GRADIENT ) );

// create and add imagelist

HIMAGELIST hImgList = ImageList_Create( 32, 32, ILC_MASK, 1, 1 );
int nR = ImageList_AddIcon( hImgList, hIcon );
SendMessage( hTool, TB_SETIMAGELIST, 0, ( LPARAM )hImgList);

ZeroMemory( tbb, sizeof( tbb ) );
tbb[ 0 ].iBitmap = 0;
tbb[ 0 ].fsState = TBSTATE_ENABLED;
tbb[ 0 ].fsStyle = BTNS_CHECK;
tbb[ 0 ].idCommand = IDM_EDITTEXTURE_ENABLE;
    ...
SendMessage( hTool, TB_ADDBUTTONS, SIZEARRAY( tbb ), ( LPARAM )&tbb );

加载时图像似乎转换为 16 位...如何在按钮上使用高分辨率图像?

【问题讨论】:

    标签: c++ image winapi toolbar


    【解决方案1】:

    Windows 图像列表确实支持 24 位颜色以及更多格式。您需要在传递给ImageList_Create 的标志中指定颜色格式。对于 24 位颜色,您需要包含 ILC_COLOR24 标志。这些标志记录在这里:http://msdn.microsoft.com/en-us/library/windows/desktop/bb775232.aspx

    【讨论】:

      【解决方案2】:

      问题已解决...对于在调用 ImageList_Create() 时关心的任何人使用 ILC_COLOR24 或 ILC_COLOR32...这将告诉系统使用 24 或 32 bpp 图像。

      【讨论】:

      • 我的回答不是这样说的吗?
      • @DavidHeffernan 在我发帖时没有看到你的答案
      【解决方案3】:

      查看here 以获取功能齐全的 24 位颜色工具栏。它还包含一个演示解决方案。

      主要思想是使用:

      static const UINT   kToolBarBitDepth (ILC_COLOR24);
      

      【讨论】:

        猜你喜欢
        • 2021-07-18
        • 1970-01-01
        • 1970-01-01
        • 2014-10-13
        • 2018-04-01
        • 1970-01-01
        • 2021-08-17
        • 2016-10-25
        • 1970-01-01
        相关资源
        最近更新 更多