Let Toolbar displays different ICons

xiaoxiao2021-04-08  381

IT's said in msdn That: "

Microsoft Windows Assumes That All of a Toolbar's Bitmapped images is the same size. "So the Question IS:

How Can We IMPLEMENT A TOOLBAR WITH IS JUST LIKE AS GoOGLE TOOLBAR?

There is the 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

PTBTN [

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

(Tbuttoninfo); tbi.dwmask

=

TBIF_Style

|

TBIF_SIZE; TBI.FSStyle

=

PTBTN [

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 Size ImageList. (See

MSDN.). But we can only Create One Toolbar in WTL by Default, So it's a little complex to import using wtl in this method. You can Try this in mfc.

转载请注明原文地址:https://www.9cbs.com/read-132707.html

New Post(0)