Fix remote desktop cursor cross-contamination across dialogs
The view-mode "forbidden" cursor was applied with SetClassLongPtr(GCLP_HCURSOR), which mutates the cursor for the whole window class instead of the single dialog instance. Opening a second remote-desktop dialog without remote control overwrote that shared class cursor with IDC_NO, so the already-controlled dialog also began showing the forbidden icon even though it remained operable. Move the view-mode cursor decision into OnSetCursor, which Windows routes per window, and remove the now-unused class-cursor assignments. Remote-control mode and the remote cursor-shape path are left unchanged. Also drop the dead m_hRemoteCursor member and the leftover GetIconInfo block (which leaked hbmMask/hbmColor in ScreenSpyDlg), plus the now-unreferenced m_bMouseTracking flag. Co-Authored-By: deepseek-v4-pro
This commit is contained in:
@@ -90,11 +90,33 @@ BEGIN_MESSAGE_MAP(CHideScreenSpyDlg, CDialog)
|
||||
ON_WM_PAINT()
|
||||
ON_WM_TIMER()
|
||||
ON_WM_CLOSE()
|
||||
ON_WM_SETCURSOR()
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CHideScreenSpyDlg message handlers
|
||||
BOOL CHideScreenSpyDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
|
||||
{
|
||||
// 查看模式(未开启远程控制):客户区显示禁止图标;标题栏及系统按钮保持正常箭头,
|
||||
// 便于拖动窗口或通过标题栏右键菜单开启远程控制。
|
||||
// 这里按窗口自身状态判断,避免用窗口类光标(GCLP_HCURSOR)时被同类的其他对话框实例
|
||||
// 共享串扰——第二个对话框切到查看模式后,第一个控制中的对话框也被误显示成禁止图标。
|
||||
if (!m_bIsCtrl && nHitTest == HTCLIENT) {
|
||||
::SetCursor(LoadCursor(NULL, IDC_NO));
|
||||
return TRUE;
|
||||
}
|
||||
if (!m_bIsCtrl &&
|
||||
(nHitTest == HTCAPTION || nHitTest == HTSYSMENU || nHitTest == HTMENU ||
|
||||
nHitTest == HTCLOSE || nHitTest == HTMINBUTTON || nHitTest == HTMAXBUTTON ||
|
||||
nHitTest == HTHELP)) {
|
||||
::SetCursor(LoadCursor(NULL, IDC_ARROW));
|
||||
return TRUE;
|
||||
}
|
||||
// 控制模式:交父类处理,显示窗口类光标(远程光标形状)
|
||||
return __super::OnSetCursor(pWnd, nHitTest, message);
|
||||
}
|
||||
|
||||
void CHideScreenSpyDlg::OnClose()
|
||||
{
|
||||
if (!m_aviFile.IsEmpty()) {
|
||||
@@ -165,7 +187,6 @@ BOOL CHideScreenSpyDlg::OnInitDialog()
|
||||
// when the application's main window is not a dialog
|
||||
SetIcon(m_hIcon, TRUE); // Set big icon
|
||||
SetIcon(m_hIcon, FALSE); // Set small icon
|
||||
SetClassLongPtr(m_hWnd, GCLP_HCURSOR, (LONG_PTR)LoadCursor(NULL, IDC_NO));
|
||||
CMenu* pSysMenu = GetSystemMenu(FALSE);
|
||||
if (pSysMenu != NULL) {
|
||||
pSysMenu->AppendMenuSeparator(MF_SEPARATOR);
|
||||
@@ -214,15 +235,7 @@ BOOL CHideScreenSpyDlg::OnInitDialog()
|
||||
}
|
||||
|
||||
// TODO: Add extra initialization here
|
||||
m_hRemoteCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
ICONINFO CursorInfo;
|
||||
::GetIconInfo(m_hRemoteCursor, &CursorInfo);
|
||||
pSysMenu->CheckMenuItem(IDM_CONTROL, m_bIsCtrl ? MF_CHECKED : MF_UNCHECKED);
|
||||
SetClassLongPtr(m_hWnd, GCLP_HCURSOR, (LONG_PTR)m_hRemoteCursor);
|
||||
if (CursorInfo.hbmMask != NULL)
|
||||
::DeleteObject(CursorInfo.hbmMask);
|
||||
if (CursorInfo.hbmColor != NULL)
|
||||
::DeleteObject(CursorInfo.hbmColor);
|
||||
// 初始化窗口大小结构
|
||||
m_hFullDC = ::GetDC(m_hWnd);
|
||||
m_hFullMemDC = CreateCompatibleDC(m_hFullDC);
|
||||
@@ -440,11 +453,6 @@ void CHideScreenSpyDlg::OnSysCommand(UINT nID, LPARAM lParam)
|
||||
case IDM_CONTROL: {
|
||||
m_bIsCtrl = !m_bIsCtrl;
|
||||
pSysMenu->CheckMenuItem(IDM_CONTROL, m_bIsCtrl ? MF_CHECKED : MF_UNCHECKED);
|
||||
|
||||
if (m_bIsCtrl) {
|
||||
SetClassLongPtr(m_hWnd, GCLP_HCURSOR, (LONG_PTR)m_hRemoteCursor);
|
||||
} else
|
||||
SetClassLongPtr(m_hWnd, GCLP_HCURSOR, (LONG_PTR)LoadCursor(NULL, IDC_NO));
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user