We recommend you follow an absolutely different approach for constructing your "border weight" menu items. You can insert them into a popup menu as tool button like menu items. You can see these menu items in the popup menu displayed from the toolbar’s chevron button. This menu is filled with toolbar buttons which cannot fit in the toolbar. The tool menu items can be displayed in multiple rows with several menu items per row. The last tool menu item in each row is marked with the wrap flag. You can insert several "border weight" tool menu items that have the wrap flag and generate wide icons for them displaying the "border weight" information like you need or like the line width in many painting programs. Using this approach you will not have to implement any custom painting.
You can insert a menu item using the CExtPopupMenuWnd::ItemInsertCommand()
method. Get a reference to the CExtPopupMenuWnd::MENUITEMDATA
object by invoking the CExtPopupMenuWnd::ItemGetInfo()
method. Configure it so it is descrived as the tool button like menu item:
CExtPopupMenuWnd::MENUITEMDATA & mi = . . .
mi.SetNoCmdUI( true );
mi.Enable( true );
mi.SetToolButton( true );
mi.SetToolWrap( true );
CExtCmdIcon _icon;
// GENERATE THE icon.m_bmpNormal HERE
mi.SetPopupIcon( _icon );
The
icon.m_bmpNormal
property is an object of the CExtBitmap type. For instance, if you want to generate a
line width icon of the 150x15 size and a black line of some width inside, you should generate a 150x15
HBITMAP
(or
CBitmap)
object which has some known background color (for instance
RGB(255,0,255)
) of all its pixels and draw a line over this background. Then you can assign this bitmap handle to the
icon.m_bmpNormal
property and make all the background pixels transparent:
HBITMAP hBitmap = . . .
icon.m_bmpNormal.FromBitmap( hBitmap );
icon.m_bmpNormal.Make32();
icon.m_bmpNormal.AlphaColor( RGB(255,0,255), RGB(0,0,0), BYTE(0) );
// do not forget to destroy the hBitmap handle finally
::DeleteObject( hBitmap );