// 鼠标左键按下事件处理 BOOL CControlBase::OnLButtonDown(UINT nFlags, CPoint point) { if(!m_bIsVisible || !m_bRresponse) return false; // 保存原始的鼠标位置,并进行位置变换 CPoint oldPoint = point; OnMousePointChange(point); m_bMouseDown = m_rc.PtInRect(point); // 查找鼠标是否在某个内部控件位置,如果是的话就更新当前子控件(按照反向顺序查找,因为定义在后面的控件是优先级更高的) // 找到第一个符合条件的就结束查找 for (int i = m_vecControl.size()-1; i >= 0; i--) { CControlBase * pControlBase = m_vecControl.at(i); if (pControlBase && pControlBase->PtInRect(point)) { if(pControlBase->GetVisible() && !pControlBase->GetDisable() && pControlBase->GetRresponse()) { m_pControl = pControlBase; break; } } } if(m_pControl != NULL) { // 如果是控件内置滚动条子控件,则不进行位置变换,因为滚动条位置是不需要变换的 UINT uControlID = m_pControl->GetControlID(); if((SCROLL_V == uControlID) || (SCROLL_H == uControlID)) { point = oldPoint; } if(m_pControl->OnLButtonDown(nFlags, point)) { return true; } } else { // 切换对话框中的当前焦点控件(暂不处理Popup窗口的切换) CDlgBase* pDlg = GetParentDialog(FALSE); if(pDlg) { pDlg->SetFocusControl(this); } // 发送鼠标左键按下DUI消息 if(m_bDuiMsgMouseLDown && m_rc.PtInRect(point)) { SendMessage(MSG_MOUSE_LDOWN, (WPARAM)nFlags, (LPARAM)(&point)); } return OnControlLButtonDown(nFlags, point); } return false; }
// 滚动事件处理 BOOL CControlBase::OnScroll(BOOL bVertical, UINT nFlags, CPoint point) { if(!m_bIsVisible || !m_bRresponse) return false; BOOL bRresponse = false; if(m_pControl) { // 判断当前活动控件 if(m_pControl->PtInRect(point) && m_pControl->OnCheckMouseResponse(nFlags, point)) { if(m_pControl->OnScroll(bVertical, nFlags, point)) { return true; } return false; } } if(PtInRect(point)) { // 在此控件范围内,先判断此控件是否能处理 if(OnControlScroll(bVertical, nFlags, point)) { return true; }else { // 此控件没有处理,则遍历子控件看是否能处理 for (size_t i = 0; i < m_vecControl.size(); i++) { CControlBase * pControlBase = m_vecControl.at(i); if (pControlBase && pControlBase->PtInRect(point)) { if(pControlBase->OnScroll(bVertical, nFlags, point)) { return true; } } } } } return false; }
// 鼠标左键事件处理 BOOL CControlBase::OnLButtonDown(UINT nFlags, CPoint point) { if(!m_bIsVisible || !m_bRresponse) return false; OnMousePointChange(point); m_bMouseDown = m_rc.PtInRect(point); // 查找鼠标是否在某个内部控件位置,如果是的话就更新当前子控件 for (size_t i = 0; i < m_vecControl.size(); i++) { CControlBase * pControlBase = m_vecControl.at(i); if (pControlBase && pControlBase->PtInRect(point)) { if(pControlBase->GetVisible() && !pControlBase->GetDisable() && pControlBase->GetRresponse()) { m_pControl = pControlBase; } } } if(m_pControl != NULL) { if(m_pControl->OnLButtonDown(nFlags, point)) { return true; } } else { // 切换对话框中的当前焦点控件(暂不处理Popup窗口的切换) CDlgBase* pDlg = GetParentDialog(FALSE); if(pDlg) { pDlg->SetFocusControl(this); } return OnControlLButtonDown(nFlags, point); } return false; }
// 鼠标移动事件处理 BOOL CControlBase::OnMouseMove(UINT nFlags, CPoint point) { if(!m_bIsVisible || !m_bRresponse) return false; OnMousePointChange(point); BOOL bRresponse = false; if(m_pControl) { if((m_pControl->PtInRect(point) && m_pControl->OnCheckMouseResponse(nFlags, point)) || m_bMouseDown) { if(m_pControl->OnMouseMove(nFlags, point)) { return true; } return false; } } CControlBase * pOldControl = m_pControl; m_pControl = NULL; if(!m_strTooltip.IsEmpty() && PtInRect(point) && OnCheckMouseResponse(nFlags, point)) { // 如果当前控件有Tooltip,则添加一个Tooltip CDlgBase* pDlg = GetParentDialog(); if(pDlg && (pDlg->GetTooltipCtrlID() != GetID())) { pDlg->SetTooltip(this, m_strTooltip, m_rc); pDlg->SetTooltipCtrlID(GetID()); } } bRresponse = OnControlMouseMove(nFlags, point); if(!m_bMouseDown) { for (size_t i = 0; i < m_vecControl.size(); i++) { CControlBase * pControlBase = m_vecControl.at(i); if (pControlBase) { if(pControlBase->OnMouseMove(nFlags, point)) { if(pControlBase->PtInRect(point)) { m_pControl = pControlBase; } bRresponse = true; } } } if (pOldControl) { bRresponse = true; } if (m_pControl) { bRresponse = true; } } return bRresponse; }
// 鼠标移动事件处理 BOOL CControlBase::OnMouseMove(UINT nFlags, CPoint point) { if(!m_bIsVisible || !m_bRresponse) return false; // 保存原始的鼠标位置,并进行位置变换 CPoint oldPoint = point; OnMousePointChange(point); BOOL bRresponse = false; if(m_pControl) { CPoint pt = point; // 如果是控件内置滚动条子控件,则不进行位置变换,因为滚动条位置是不需要变换的 UINT uControlID = m_pControl->GetControlID(); if((SCROLL_V == uControlID) || (SCROLL_H == uControlID)) { pt = oldPoint; } if((m_pControl->PtInRect(pt) && m_pControl->OnCheckMouseResponse(nFlags, pt)) || m_bMouseDown) { if(m_pControl->OnMouseMove(nFlags, pt)) { return true; } return false; } } CControlBase * pOldControl = m_pControl; m_pControl = NULL; if(!m_strTooltip.IsEmpty() && PtInRect(point) && OnCheckMouseResponse(nFlags, point)) { // 如果当前控件有Tooltip,并且当前Tooltip设置的是其他控件,则设置Tooltip if(GetTooltipCtrlID() != GetID()) { SetTooltip(this, m_strTooltip, m_rc, FALSE, m_nTipWidth); SetTooltipCtrlID(GetID()); } } // 调用控件的设置鼠标光标函数 OnControlSetCursor(nFlags, point); // 调用控件的鼠标移动函数 bRresponse = OnControlMouseMove(nFlags, point); // 发送鼠标移动的DUI消息 if(m_bDuiMsgMouseMove) { if(PtInRect(point)) { // 发送鼠标在控件范围内移动的消息 SendMessage(MSG_MOUSE_MOVE, (WPARAM)nFlags, (LPARAM)(&point)); m_bMouseLeave = FALSE; }else { if(!m_bMouseLeave) { // 发送鼠标离开控件的消息(离开之后仅发送一次离开消息) SendMessage(MSG_MOUSE_LEAVE, (WPARAM)nFlags, (LPARAM)(&point)); m_bMouseLeave = TRUE; } } } if(!m_bMouseDown) { for (size_t i = 0; i < m_vecControl.size(); i++) { CControlBase * pControlBase = m_vecControl.at(i); if (pControlBase) { CPoint pt = point; // 如果是控件内置滚动条子控件,则不进行位置变换,因为滚动条位置是不需要变换的 UINT uControlID = pControlBase->GetControlID(); if((SCROLL_V == uControlID) || (SCROLL_H == uControlID)) { pt = oldPoint; } if(pControlBase->OnMouseMove(nFlags, pt)) { if(pControlBase->PtInRect(pt)) { m_pControl = pControlBase; } bRresponse = true; } } } if (pOldControl) { bRresponse = true; } if (m_pControl) { bRresponse = true; } } return bRresponse; }
void CDlgPopup::OnMouseMove(UINT nFlags, CPoint point) { if (!m_bTracking) { TRACKMOUSEEVENT tme; tme.cbSize = sizeof(tme); tme.hwndTrack = m_hWnd; tme.dwFlags = TME_LEAVE | TME_HOVER; tme.dwHoverTime = 1; m_bTracking = ::_TrackMouseEvent(&tme); } BOOL bInvalidateRect = false; if (m_pControl) { if(((m_pControl->PtInRect(point) && m_pControl->OnCheckMouseResponse(nFlags, point)) || m_bIsLButtonDown) && m_bTracking) { m_pControl->OnMouseMove(nFlags, point); return; } } if (!m_bIsLButtonDown) { CControlBase * pOldControl = m_pControl; BOOL bIsSelect = FALSE; BOOL bIsSystemSelect = FALSE; if(m_bTracking) { // 用户控件 for (size_t i = 0; i < m_vecControl.size(); i++) { CControlBase * pControlBase = m_vecControl.at(i); if (pControlBase) { pControlBase->OnMouseMove(nFlags, point); if (!bIsSystemSelect) { if(pControlBase->PtInRect(point) && pControlBase->GetRresponse()) { m_pControl = pControlBase; bIsSelect = TRUE; } } } } } if (!bIsSelect && !bIsSystemSelect) { m_pControl = NULL; } // 调用自身的OnMouseMove if(OnMouseMove(point)) { DrawWindow(); } } }