在VC范例宝典中有绘制图标菜单的实例,在重写的重绘菜单函数中有这么几句
...
m_iteminfo = (CMenuItemInfo*)lpStruct->itemData;
//lpStruct是LPMEASUREITEMSTRUCT类型 或LPDRAWITEMSTRUCT
//CMenuItemInfo是自定义的结构
lpStruct->itemWidth = ((CMenuItemInfo*)lpStruct->itemData)->m_ItemText.GetLength()*10;
switch(m_iteminfo->m_ItemID)//m_iteminfo是自定义的结构,itemData与其相符吗
...
刚开始还奇怪系统给的结构怎么可以转成自定义的??
后找到答案,
先看关于itemData的说明
itemData
For a combo box or list box, this member contains the value that was passed to the list box by one of the following:
For a menu, this member contains the value that was passed to the menu by one of the following:
发现程序前面是用ModifyMenu来修改菜单来着,再找它:
BOOL ModifyMenu( UINT nPosition, UINT nFlags, UINT nIDNewItem = 0, LPCTSTR lpszNewItem = NULL );
在其函数参数中有lpszNewItem,说明如下
lpszNewItem
Specifies the content of the new menu item. The nFlags parameter can be used to interpret lpszNewItem in the following ways:
nFlags | Interpretation of lpszNewItem |
MF_OWNERDRAW | Contains an application-supplied 32-bit value that the application can use to maintain additional data associated with the menu item. This 32-bit value is available to the application when it processes MF_MEASUREITEM and MF_DRAWITEM. |
MF_STRING | Contains a long pointer to a null-terminated string or to a CString. |
MF_SEPARATOR | The lpszNewItem parameter is ignored (not needed). |
MF_OWNERDRAW:含有被应用程序应用的32位值,可以保留与菜单项有关的附加数据。当菜单被创建或其外观被修改时,此值在消息WM_MEASURE或WM_DRAWITEM的参数lparam指向的结构中,成员itemData里。
而使用的ModifyMenu为
m_menu->ModifyMenu(i,MF_OWNERDRAW|MF_BYPOSITION |MF_STRING,m_ItemLists[m_index].m_ItemID,(LPSTR)&(m_ItemLists[m_index]));