c – 更改MFC中按钮的光标

我试图在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

点赞