按扭与菜单结合出现问题
自绘了个按扭,当鼠标移动`点击时,按扭会出现不同的样式.在没有与菜单结合时一切正常.
但是,当我为按纽加上一个单击弹出菜单响应时,按纽样式始终停留在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();
}