MenuRef GetControl32BitValue 始终返回 0
您好,我需要使用弹出菜单,女巫是动态创建的。
OSErr err = GetBevelButtonMenuHandle(m_pRecallAOptionalButton, &m_pRecallAMenuRef);
for (countitem)
{
String szItem (List.GetAt(i));
CFStringRef sz = ToCFStringRef(szItem);
AppendMenuItemTextWithCFString(m_pRecallAMenuRef, sz, 0, 0, 0);
}
short sCount = CountMenuItems(m_pRecallAMenuRef);
SetControl32BitMaximum(m_pRecallAOptionalButton, sCount);
没关系,菜单显示正确的项目数量。我设置了最大值。
当我想获取所选项目索引时,出现了我的问题。 为此,我使用 kEventClassMenu 事件 & kEventMenuClosed kind
case kEventClassMenu:
{
MenuRef Menu;
GetEventParameter( inEvent, kEventParamDirectObject, typeMenuRef, NULL, sizeof(Menu), NULL, &Menu );
if (Menu && (Menu == pMainForm->m_pRecallAMenuRef))
{
SInt32 nIndex = GetControl32BitMaximum(m_pRecallAOptionalButton); // return the correct items count
nIndex = GetControl32BitValue(m_pRecallAOptionalButton); // always return 0 !!!!!
}
}
我错过了什么吗?这是附加的正确事件吗?
非常感谢您的帮助。
Hello i' need to use a pop-up menu, witch is created dynamically.
OSErr err = GetBevelButtonMenuHandle(m_pRecallAOptionalButton, &m_pRecallAMenuRef);
for (countitem)
{
String szItem (List.GetAt(i));
CFStringRef sz = ToCFStringRef(szItem);
AppendMenuItemTextWithCFString(m_pRecallAMenuRef, sz, 0, 0, 0);
}
short sCount = CountMenuItems(m_pRecallAMenuRef);
SetControl32BitMaximum(m_pRecallAOptionalButton, sCount);
This is ok, menu show the correct number of items. I set maximum value.
My problem occur when i want to get the selected item index.
For this, i use the kEventClassMenu event & kEventMenuClosed kind
case kEventClassMenu:
{
MenuRef Menu;
GetEventParameter( inEvent, kEventParamDirectObject, typeMenuRef, NULL, sizeof(Menu), NULL, &Menu );
if (Menu && (Menu == pMainForm->m_pRecallAMenuRef))
{
SInt32 nIndex = GetControl32BitMaximum(m_pRecallAOptionalButton); // return the correct items count
nIndex = GetControl32BitValue(m_pRecallAOptionalButton); // always return 0 !!!!!
}
}
Did i missed something ? is it the right event to attach ?
Many thanks for help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想要处理 kEventClassCommand/kEventProcessCommand,并使用菜单项中的命令 id。
请注意,commandID 是 AppendMenuItemTextWithCFString 的参数之一;这就是您在生成菜单时为每个项目指定唯一的 commandID 的方法。 commandID 通常是 4 个字符的代码(例如“打开”或“保存”),但是您没有理由不能对动态生成的命令使用简单的整数。
You probably want to handle kEventClassCommand/kEventProcessCommand, and use the command id from the menu item.
Note that the commandID is one of the parameters to
AppendMenuItemTextWithCFString
; that's how you can give each item a unique commandID as you generate the menu. commandID's are conventionally 4-char codes (like 'open' or 'save'), but there's no reason you couldn't use simple ints for your dynamically-generated commands.