// 重载窗口去激活时候的关闭窗口操作 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; }
// 消息响应 LRESULT CDuiMenu::OnMessage(UINT uID, UINT Msg, WPARAM wParam, LPARAM lParam) { if((Msg != MSG_BUTTON_UP) && (Msg != MSG_BUTTON_CHECK)) { return 0; } CControlBase* pControl = GetControl(uID); if(pControl && !pControl->GetAction().IsEmpty()) { // 如果菜单项设置了action,则添加到动作任务队列中,通过任务来执行 CString strControlName = pControl->GetName(); CString strAction = pControl->GetAction(); //CDuiObject* pParent = pControl->GetParent(); CDlgBase* pParentDlg = pControl->GetParentDialog(); DuiSystem::Instance()->AddDuiActionTask(uID, Msg, wParam, lParam, strControlName, strAction, pParentDlg); }else { // 否则就调用Popup的函数 __super::OnMessage(uID, Msg, wParam, lParam); /*tagMenuInfo* pMenuInfo = new tagMenuInfo; pMenuInfo->uMenuID = uID; pMenuInfo->bSelect = (bool)lParam; pMenuInfo->bDown = (bool)wParam; PostMessage(m_uMessageID, Msg, (LPARAM)pMenuInfo);*/ } if(Msg == MSG_BUTTON_UP) { // 如果点击的是弹出菜单,则不用关闭 if(pControl && pControl->IsClass(CMenuItem::GetClassName()) && ((CMenuItem*)pControl)->IsPopup()) { return 0; } // 如果有父菜单,将父菜单关闭,不采用直接关闭的方法,而是设置自动关闭标识,并通过鼠标事件触发自动关闭 CDuiMenu* pParentMenu = GetParentMenu(); if(pParentMenu && !pParentMenu->IsAutoClose()) { pParentMenu->SetAutoClose(TRUE); pParentMenu->SetForegroundWindow(); pParentMenu->PostMessage(WM_LBUTTONDOWN, 0, 0); } // 关闭自身 CloseWindow(); } return 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(); CMenuItem* pHoverItem = pParentMenu->GetMenuItemWithPoint(point); 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; }
// 鼠标左键放开事件处理 BOOL CMenuItem::OnControlLButtonUp(UINT nFlags, CPoint point) { bool bSend = false; BOOL bbDown = FALSE; bool bSelect = false; enumButtonState buttonState = m_enButtonState; if (!m_bIsDisable) { if(m_rc.PtInRect(point)) { if(m_bSelect) { if(m_bDown) { m_enButtonState = enBSHoverDown; } else { m_enButtonState = enBSHover; } if(m_bMouseDown) { // 如果组名非空,说明是radiobutton组,则刷新同一个组下面其他radiobtn if(!m_strGroupName.IsEmpty()) { m_bDown = true; ResetGroupCheck(); }else { m_bDown = !m_bDown; } bSend = false; bbDown = m_bDown; bSelect = true; } } else { m_enButtonState = enBSHover; bSend = true; } } else { // 如果存在弹出菜单,并且鼠标不在弹出菜单范围内,则关闭父菜单 if(m_bIsPopup) { // 父菜单对象设置回自动关闭 CDuiMenu* pParentMenu = GetParentMenu(); if(pParentMenu) { pParentMenu->SetAutoClose(TRUE); pParentMenu->SetForegroundWindow(); } } if(m_bDown) { m_enButtonState = enBSDown; } else { m_enButtonState = enBSNormal; } } } m_bMouseDown = false; if(buttonState != m_enButtonState) { UpdateControl(); if(bSend) { SendMessage(MSG_BUTTON_UP, bbDown, bSelect); } return true; } return false; }