In this example, the dynamically changed toolbar button icon is stored in the toolbar resource whose ID is idr_toolbar_shell and can be used as a bitmap resource.
Cimagelist * m_imglist1;
M_imglist1 = (m_wndtoolbar.gettoolbarctrl (). getimagelist ();
Int A = m_imglist1-> getimagecount ();
Cbitmap CBMP;
Bitmap BMP;
CBMP. loadbitmap (idr_toolbar_shell );
CBMP. getbitmap (& BMP );
M_imglist1-> Add (& CBMP, RGB (192,192,192 ));
(M_wndtoolbar.gettoolbarctrl (). setimagelist (m );
M_imglist1-> detach ();
M_imglist1 = NULL;
CBMP. deleteobject ();
The above Code adds bitmap in idr_toolbar_shell to the image list of m_wndtoolbar, which can also be implemented through other methods.
Next, you can dynamically change the icon of a button. For example, change the icon ID id_menuitem32780 to the second icon in idr_toolbar_shell:
M_wndtoolbar.setbuttoninfo (m_wndtoolbar.commandtoindex (id_menuitem32780), id_menuitem32780, tbbs_button, A + 1 );