2012-02-06 77 views
3

我正在嘗試更改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類的對象。 請告訴我如何更改button.I的光標也tryed這一點,但沒有工作

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

回答

2

調用使用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

+0

這種方法只適用於CMFCButton類。這裏m_button1是CButton類的對象。 – Durgesh 2012-02-06 06:18:55

+1

myButton.SetCursor(:: LoadCursor(NULL,IDC_HAND)); http://msdn.microsoft.com/en-us/library/8w6ks9y7%28v=vs.80%29.aspx – 2012-02-06 06:40:14