更改MFC中按钮的光标

Changing Cursor of a button in MFC

本文关键字:光标 按钮 MFC 更改      更新时间:2023-10-16

我正在尝试更改MFC对话框中按钮的光标。我用过

BOOL CStartDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if ( m_changeCursor )
{
    ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_HAND));
    return TRUE;
}
return CDialog::OnSetCursor(pWnd, nHitTest, message);
}

但它正在改变整个对话框的光标。m_button是CButton类的对象。请告诉我如何更改按钮的光标。我也尝试过这个,但没有工作

m_button1.SetCursor(::LoadCursor(NULL, IDC_HAND));

调用LoadCursor()函数并将其返回值传递给CMFCButton::SetMouseCursor)成员函数。这里有一个例子:

BOOL CExerciseDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();
    // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);         // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon
    // TODO: Add extra initialization here
    m_Calculate.SetMouseCursor(LoadCursor(AfxGetInstanceHandle(),
                               MAKEINTRESOURCE(IDC_CURSOR1)));
    return TRUE;
}

参考http://www.functionx.com/visualc/controls/mfcbtn.htm#subtitle

另请参阅Api CWinApp::LoadCursor