按扭与菜单结合出现问题

adaisong 2006-05-29 11:26:50
自绘了个按扭,当鼠标移动`点击时,按扭会出现不同的样式.在没有与菜单结合时一切正常.

但是,当我为按纽加上一个单击弹出菜单响应时,按纽样式始终停留在mouse on button的样式.并且当

失去菜单后,按纽也停留在mouse no button 的样式. 奇怪的是,当我右键菜单外,使菜单消失时,按纽

变的正常了!

请问,这个菜单弹出后,菜单对focus, capture是如何处理的?为什么按纽跟菜单一结合就出了问题?

代码如下:

void CButtonEXT::OnMouseMove(UINT nFlags, CPoint point)
{
CWnd* pWnd;
CWnd* pParent;

CButton::OnMouseMove(nFlags, point);

// If the mouse enter the button with the left button pressed
// then do nothing
if (nFlags & MK_LBUTTON && m_MouseOnButton == FALSE)
return;

// If our button is not flat then do nothing
if (m_bIsFlat == FALSE)
return;

pParent = GetOwner();

if ((GetCapture() != this) &&
(
pParent != NULL))
{
TRACE0("mouse on button\n");
m_MouseOnButton = TRUE;
SetCapture();
Invalidate();
}
else
{
POINT p2 = point;
ClientToScreen(&p2);
CWnd* wndUnderMouse = WindowFromPoint(p2);
if (wndUnderMouse && wndUnderMouse->m_hWnd != this->m_hWnd)
{

// Redraw only if mouse goes out
if (m_MouseOnButton == TRUE)
{

m_MouseOnButton = FALSE;
Invalidate();
}
// If user is NOT pressing left button then release capture!
if (!(nFlags & MK_LBUTTON))
ReleaseCapture();
}
}
} // End of OnMouseMove


void CMyDlg::OnBnClickedButton10()
{
// TODO: 在此添加控件通知处理程序代码

CMenu menu ,* pSubMenu; //定义下面要用到的cmenu对象
menu.LoadMenu(IDR_POPUPMENU); //装载自定义的右键菜单

pSubMenu = menu.GetSubMenu(0);
CRect rect;
GetDlgItem(IDC_BUTTON10)->GetWindowRect(&rect);

//在指定位置显示弹出菜单
pSubMenu->TrackPopupMenu (TPM_LEFTALIGN, rect.left, rect.bottom, this);

GetDlgItem(IDC_BUTTON10)->SetCapture();
}
...全文
151 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
liquidlele 2006-06-09
  • 打赏
  • 举报
回复
我来也!!!
adaisong 2006-05-29
  • 打赏
  • 举报
回复
请高手看看吧,在线等
adaisong 2006-05-29
  • 打赏
  • 举报
回复
any person?

WecanHuang 2006-05-29
  • 打赏
  • 举报
回复
up
adaisong 2006-05-29
  • 打赏
  • 举报
回复
===========================================================================
adaisong 2006-05-29
  • 打赏
  • 举报
回复
怎么没人里啊

15,975

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧