加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 更改MFC中按钮的光标

发布时间:2020-12-16 07:28:54 所属栏目:百科 来源:网络整理
导读:我试图在MFC对话框中更改按钮的光标.我用过 BOOL CStartDlg::OnSetCursor(CWnd* pWnd,UINT nHitTest,UINT message){if ( m_changeCursor ){ ::SetCursor(AfxGetApp()-LoadStandardCursor(IDC_HAND)); return TRUE;}return CDialog::OnSetCursor(pWnd,nHitTes
我试图在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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读