How to change the Mouse Pointer Over a Button at runtime?

Submitted by: Administrator
Assuming that you have set the button's ID as IDC_BTNSAMPLE in the resource editor :-
// You have to handle the WM_SETCURSOR message handler to do that
BOOL CTestDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if (pWnd == GetDlgItem(IDC_BTNSAMPLE))
{ // To load a standard cursor
::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));
// To load your own custom cursor. Assuming that you have created a
// Cursor in the resource editor and named it as IDC_CURSAMPLE
::SetCursor(AfxGetApp()->LoadCursor(MAKEINTRESOURCE(IDC_CURSAMPLE)));
// Remember to return TRUE here return TRUE;
}
return CDialog::OnSetCursor(pWnd, nHitTest, message);
}
Submitted by: Administrator

Read Online Visual C++ Job Interview Questions And Answers