让Toolbar显示大小不同的ICONs


It's said in MSDN that:“ Microsoft Windows assumes that all of a toolbar's bitmapped images are the same size. ” So the question is : How can we implement a toolbar with different sized images, which is just like as Google Toolbar?


There are two ways:

1.To use double ImageLists

You should note that the image's size of the toolbar is decided by the first ImageList, even though the second one is different from the first one. So after registering double ImageLists, you also have to reset the button's size to suit the second imagelist.
This is the code segment:

a. setting double imagelist
     // 1st ImageList, with normal images
    m_hImage1st  =  ImageList_Create( 16 16 , ILC_COLOR24,  1 0 );
    
int  nIdx11  =  ImageList_Add(m_hImageFirst,,NULL);
    
int  nIdx12  =   ImageList_Add(m_hImageFirst,,NULL);

        
// 2nd ImageList, with bigger image
    m_hImage2nd  =  ImageList_Create( 48 16 , ILC_COLOR24,  2 0 );
    
int  nIdx21  = ImageList_Add(m_hImage2nd ,,NULL);

    
//  add imagelists, the order is very important
    ::SendMessage(m_hWnd, CCM_SETVERSION, (WPARAM)  5 0 );
    ::SendMessage(m_hWnd, TB_SETIMAGELIST, 
0 , (LPARAM)m_hImage1st);
    ::SendMessage(m_hWnd, TB_SETIMAGELIST, 
1 , (LPARAM)m_hImage2nd);

    
//  set button image
    pTBBtn[ 0 ].iBitmap  =  MAKELONG(nIdx21,  1 );
    pTBBtn[
1 ].iBitmap  =  MAKELONG(nIdx11,  0 );
    pTBBtn[
2 ].iBitmap  =  MAKELONG(nIdx12,  0 );

b. resize the button with bigger image
    TBBUTTONINFO tbi;            
    tbi.cbSize 
=   sizeof (TBBUTTONINFO);
    tbi.dwMask 
=  TBIF_STYLE  |  TBIF_SIZE;
    tbi.fsStyle 
=  pTBBtn[ 0 ].fsStyle;
    tbi.cx 
=   48 ;
        ::SendMessage(m_hWnd, TB_SETBUTTONINFO, nID, (LPARAM)
& tbi);

And now,  the first button of the toolbar has different sized image from others.

2. To use Rebar control

A rebar control may have many toolbars, so you can create two toolbars with different sized imagelist.(See MSDN.). But we can only create one toolbar in WTL by default, so it's a little complex to implement using WTL in this method. You can try this in MFC.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值