From f53193395203447b20b3e2e99960464b653c56ed Mon Sep 17 00:00:00 2001 From: yuanyuanxiang <962914132@qq.com> Date: Sat, 2 Aug 2025 17:24:17 +0800 Subject: [PATCH] fix: Showing the correct cursor status on window --- client/CursorInfo.h | 14 ++------------ server/2015Remote/HideScreenSpyDlg.cpp | 3 ++- server/2015Remote/ScreenSpyDlg.cpp | 24 ++++++++++++++++++++++-- server/2015Remote/ScreenSpyDlg.h | 3 ++- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/client/CursorInfo.h b/client/CursorInfo.h index 826f109..566d3be 100644 --- a/client/CursorInfo.h +++ b/client/CursorInfo.h @@ -59,12 +59,6 @@ public: } } - virtual ~CCursorInfo() - { - for (int i = 0; i < MAX_CURSOR_TYPE; ++i) - DestroyCursor(m_CursorHandleArray[i]); - } - int getCurrentCursorIndex() const { CURSORINFO ci; @@ -78,18 +72,14 @@ public: if (ci.hCursor == m_CursorHandleArray[i]) break; } - DestroyCursor(ci.hCursor); int nIndex = i == MAX_CURSOR_TYPE ? -1 : i; return nIndex; } - HCURSOR getCursorHandle( int nIndex ) + HCURSOR getCursorHandle( int nIndex ) const { - if (nIndex >= 0 && nIndex < MAX_CURSOR_TYPE) - return m_CursorHandleArray[nIndex]; - else - return NULL; + return (nIndex >= 0 && nIndex < MAX_CURSOR_TYPE) ? m_CursorHandleArray[nIndex] : NULL; } }; diff --git a/server/2015Remote/HideScreenSpyDlg.cpp b/server/2015Remote/HideScreenSpyDlg.cpp index 5e24e23..c8a258c 100644 --- a/server/2015Remote/HideScreenSpyDlg.cpp +++ b/server/2015Remote/HideScreenSpyDlg.cpp @@ -100,7 +100,8 @@ void CHideScreenSpyDlg::OnClose() ShowWindow(SW_HIDE); return; } - + // 恢复鼠标状态 + SetClassLongPtr(m_hWnd, GCLP_HCURSOR, (LONG_PTR)LoadCursor(NULL, IDC_ARROW)); CDialogBase::OnClose(); } diff --git a/server/2015Remote/ScreenSpyDlg.cpp b/server/2015Remote/ScreenSpyDlg.cpp index 7aceac2..b879337 100644 --- a/server/2015Remote/ScreenSpyDlg.cpp +++ b/server/2015Remote/ScreenSpyDlg.cpp @@ -59,7 +59,6 @@ CScreenSpyDlg::CScreenSpyDlg(CWnd* Parent, Server* IOCPServer, CONTEXT_OBJECT* C GetSystemDirectory(szFullPath, MAX_PATH); lstrcat(szFullPath, "\\shell32.dll"); //图标 m_hIcon = ExtractIcon(THIS_APP->m_hInstance, szFullPath, 17); - m_hCursor = LoadCursor(THIS_APP->m_hInstance, MAKEINTRESOURCE(IDC_ARROWS)); m_bIsFirst = TRUE; m_ulHScrollPos = 0; @@ -124,6 +123,7 @@ BEGIN_MESSAGE_MAP(CScreenSpyDlg, CDialog) ON_WM_LBUTTONUP() ON_WM_MOUSEWHEEL() ON_WM_MOUSEMOVE() + ON_WM_MOUSELEAVE() ON_WM_KILLFOCUS() ON_WM_SIZE() END_MESSAGE_MAP() @@ -200,7 +200,8 @@ VOID CScreenSpyDlg::OnClose() ShowWindow(SW_HIDE); return; } - + // 恢复鼠标状态 + SetClassLongPtr(m_hWnd, GCLP_HCURSOR, (LONG_PTR)LoadCursor(NULL, IDC_ARROW)); DialogBase::OnClose(); } @@ -826,9 +827,28 @@ BOOL CScreenSpyDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) void CScreenSpyDlg::OnMouseMove(UINT nFlags, CPoint point) { + if (!m_bMouseTracking) + { + // 第一次进入,开始追踪 WM_MOUSELEAVE + TRACKMOUSEEVENT tme = { sizeof(TRACKMOUSEEVENT) }; + tme.dwFlags = TME_LEAVE; + tme.hwndTrack = m_hWnd; + TrackMouseEvent(&tme); + + m_bMouseTracking = true; + SetClassLongPtr(m_hWnd, GCLP_HCURSOR, m_bIsCtrl ? (LONG_PTR)m_hRemoteCursor : (LONG_PTR)LoadCursor(NULL, IDC_NO)); + } + CDialog::OnMouseMove(nFlags, point); } +void CScreenSpyDlg::OnMouseLeave() +{ + CWnd::OnMouseLeave(); + + m_bMouseTracking = false; + SetClassLongPtr(m_hWnd, GCLP_HCURSOR, m_bIsCtrl ? (LONG_PTR)m_hRemoteCursor : (LONG_PTR)LoadCursor(NULL, IDC_NO)); +} void CScreenSpyDlg::OnKillFocus(CWnd* pNewWnd) { diff --git a/server/2015Remote/ScreenSpyDlg.h b/server/2015Remote/ScreenSpyDlg.h index ef20f0d..06aa85d 100644 --- a/server/2015Remote/ScreenSpyDlg.h +++ b/server/2015Remote/ScreenSpyDlg.h @@ -60,7 +60,6 @@ public: ULONG m_ulVScrollPos; VOID DrawTipString(CString strString); - HICON m_hCursor; POINT m_ClientCursorPos; BYTE m_bCursorIndex; BOOL m_bIsTraceCursor; @@ -95,6 +94,7 @@ public: HCURSOR m_hRemoteCursor = NULL; CRect m_CRect; double m_wZoom=1, m_hZoom=1; + bool m_bMouseTracking = false; bool Decode(LPBYTE Buffer, int size); void EnterFullScreen(); @@ -106,6 +106,7 @@ public: afx_msg void OnLButtonUp(UINT nFlags, CPoint point); afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt); afx_msg void OnMouseMove(UINT nFlags, CPoint point); + afx_msg void OnMouseLeave(); afx_msg void OnKillFocus(CWnd* pNewWnd); afx_msg void OnSize(UINT nType, int cx, int cy);