Esempio n. 1
0
// 重载窗口去激活时候的关闭窗口操作
BOOL CDuiMenu::OnNcCloseWindow()
{
	// 如果有父菜单,将父菜单窗口关闭
	CDuiMenu* pParentMenu = GetParentMenu();
	if(pParentMenu && !pParentMenu->IsAutoClose())
	{
		// 如果鼠标在父菜单窗口中,则不关闭父窗口
		CMenuItem* pHoverItem = pParentMenu->GetHoverMenuItem();
		if(pHoverItem == NULL)
		{
			pParentMenu->SetAutoClose(TRUE);
			pParentMenu->SetForegroundWindow();
			pParentMenu->PostMessage(WM_LBUTTONDOWN, 0, 0);
		}
	}

	// 如果父对象是菜单项,则将菜单项中的弹出菜单指针设置为空
	CDuiObject* pParent = GetParent();
	if((pParent != NULL) && (pParent->IsClass(CMenuItem::GetClassName())))
	{
		((CMenuItem*)pParent)->SetPopupMenu(NULL);
	}

	// 关闭自身
	m_pParentDuiObject = NULL;
	CloseWindow();	

	return TRUE;
}
Esempio n. 2
0
BOOL CMenuItem::OnControlMouseMove(UINT nFlags, CPoint point)
{
	enumButtonState buttonState = m_enButtonState;
	if (!m_bIsDisable && !m_bMouseDown)
	{
		if(m_rc.PtInRect(point))
		{
			if(m_bSelect)
			{
				if(m_bDown)
				{
					m_enButtonState = enBSHoverDown;
				}
				else
				{
					m_enButtonState = enBSHover;
				}
			}
			else
			{
				m_enButtonState = enBSHover;
				// 如果有子菜单,则加载弹出菜单
				if(m_bIsPopup)
				{
					ShowPopupMenu();
				}
			}
		}
		else
		{
			// 如果存在弹出菜单,并且鼠标不在弹出菜单范围内,则关闭弹出菜单
			if(m_bIsPopup && (m_pPopupMenu != NULL))
			{
				// 检查父菜单的各个子菜单,看鼠标当前是否在其他菜单项上面
				CDuiMenu* pParentMenu = GetParentMenu();
				CMenuItem* pHoverItem = pParentMenu->GetHoverMenuItem();
				if((pHoverItem != NULL) && (pHoverItem != this))
				{
					// 如果鼠标在其他平级的菜单上,则关闭子菜单
					if(IsWindow(m_pPopupMenu->GetSafeHwnd()))
					{
						m_pPopupMenu->CloseWindow();
					}
					m_pPopupMenu = NULL;
				
					// 父菜单对象设置回自动关闭
					CDuiMenu* pParentMenu = GetParentMenu();
					if(pParentMenu)
					{
						pParentMenu->SetAutoClose(TRUE);
						pParentMenu->SetForegroundWindow();
					}
				}
			}

			if(m_bSelect)
			{
				if(m_bDown)
				{
					m_enButtonState = enBSDown;
				}
				else
				{
					m_enButtonState = enBSNormal;
				}
			}
			else
			{
				m_enButtonState = enBSNormal;
			}
		}
	}
	
	if(buttonState != m_enButtonState)
	{
		UpdateControl();
		return true;
	}
	return false;
}