关于MEASUREITEMSTRUCT的itemData

在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:

CComboBox::AddString

CComboBox::InsertString

CListBox::AddString

CListBox::InsertString

For a menu, this member contains the value that was passed to the menu by one of the following:

CMenu::AppendMenu

CMenu::InsertMenu

CMenu::ModifyMenu

 

发现程序前面是用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:

nFlagsInterpretation of lpszNewItem
MF_OWNERDRAWContains 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_STRINGContains a long pointer to a null-terminated string or to a CString.
MF_SEPARATORThe 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]));


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值