在 MFC 中更改按钮的光标 [英] Changing Cursor of a button in MFC

查看:103
本文介绍了在 MFC 中更改按钮的光标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to change cursor of a button in MFC dialog. i have used

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 类的对象.请告诉我如何更改按钮的光标.我也试过这个,但没有用

but it is changing cursor for whole dialog box. m_button is object of CButton class. Please tell me how to change cursor of a button.I have tryed this also but not working

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

推荐答案

调用 LoadCursor() 函数并将其返回值传递给 CMFCButton::SetMouseCursor() 成员函数.下面是一个例子:

Call the LoadCursor() function and pass its returned value to the CMFCButton::SetMouseCursor() member function. Here is an example:

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

这篇关于在 MFC 中更改按钮的光标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆