Win32 Toolbars and 24bit Images

ぐ巨炮叔叔 提交于 2019-12-08 01:34:29

问题


Does the WinAPI support 24bit+ images? I would like to use 24bit icons( more definition ) as toolbar button images. I've loaded the icon's like this:

// 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 );

The images seem to be converted to 16bit when loaded...How can I use high res images on buttons?


回答1:


Check out here to get the full-featured 24-bit color toolbar. It also contains a demo solution there.

Main idea is to use:

static const UINT   kToolBarBitDepth (ILC_COLOR24);



回答2:


Windows image lists do indeed support 24 bit color, and many more formats. You need to specify the color format in the flags you pass to ImageList_Create. For 24 bit color, you need to include the ILC_COLOR24 flag. The flags are documented here: http://msdn.microsoft.com/en-us/library/windows/desktop/bb775232.aspx




回答3:


Problem solved...for anyone who cares when calling ImageList_Create() use ILC_COLOR24 or ILC_COLOR32...this will tell the system to use 24 or 32 bpp images.



来源:https://stackoverflow.com/questions/20828139/win32-toolbars-and-24bit-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!