2

CStatic派生クラス内のカーソルを処理して変更しようとしていますOnSetCursor

class CMyStatic : public CStatic
{
    // ....
};

BEGIN_MESSAGE_MAP(CMyStatic, CStatic)
    ON_WM_SETCURSOR()
END_MESSAGE_MAP()

BOOL CMyStatic::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
    TRACE(_T("OnSetCursor\n"));
    SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));
    return TRUE;
}

OnSetCursorマウスを動かすたびに呼び出されますが、カーソルは変更されません。私は何が間違っているのですか?

4

3 に答える 3

5

use ::SetCursor. Or you can call SetCursor once elsewhere and don't capture WM_SETCURSOR, and the cursor will be set automatically.

The CWnd::SetCursor you used is for setting a cursor for a window, and that cursor will be used if you don't override OnSetCursor. That is, the default behavior of OnSetCursor is calling ::SetCursor with the cursor one set by calling CWnd::SetCursor.

于 2012-04-18T08:29:56.277 に答える
1

You don't need (or want) to use MAKEINTRESOURCE in this case, so change:

SetCursor(AfxGetApp()->LoadStandardCursor(MAKEINTRESOURCE(IDC_CROSS)));

To:

SetCursor(AfxGetApp()->LoadStandardCursor(IDC_CROSS));
于 2012-04-18T07:50:41.483 に答える
1
m_hHandCursor = LoadCursor(NULL ,MAKEINTRESOURCE(IDC_HAND));

Make m_hHandCursor as member variable and initialize using win32 API LoadCursor in OnInitDialog....Then OnSetCursor() event set this cursor always using SetCursor API....So your application will always get system defined HAND cursor

于 2014-02-11T14:25:55.780 に答える