MFC:带有派生 CButton 子项的 CDialogEx 在按钮上方不会更改光标?

MFC: CDialogEx with derived CButton child won't change cursor when over the button?

我希望光标在 CDialogEx window 上时禁用,但在从 CButton 派生的子按钮上时显示标准光标。

为了不显示鼠标光标,我不得不覆盖 WM_SETCURSOR 消息(用 NULL 光标注册 class 无效)。

BOOL CMyDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
  if (nHitTest==HTCLIENT) {
    ::SetCursor(NULL);
    return TRUE;
  }

  return CDialogEx::OnSetCursor(pWnd, nHitTest, message);
}

在我的子按钮上:

BOOL CMyButton::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
  HCURSOR hcursor=::LoadCursor(NULL, IDC_ARROW);
  SetCursor(hcursor);
  return TRUE;
}

但是鼠标光标在按钮上时不显示?按钮函数被调用。我做错了什么?

谢谢。

CMyButton::OnSetCursor 中的 SetCursor() 调用改为使用 ::SetCursor(hcursor)。原因是 CButton::SetCursor() 没有设置光标,它将图像设置为 BM_SETIMAGE 中的图像(尽管可能很奇怪)。

BOOL CMyButton::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
  HCURSOR hcursor=::LoadCursor(NULL, IDC_ARROW);
  ::SetCursor(hcursor);
  return TRUE;
}