我用下面代码可以修改鼠标光标.
MyView::OnLButtonDown(...);
{
............................
::SetCursor(::LoadCursor(NULL,IDC_CROSS));
}
在我按下鼠标左键时,鼠标就会变成十字形.但是如果鼠标拖动一下或者放开鼠标,则鼠标得形状马上变成了指针了.
不知道为什么啊,难道SetCursor只能设置瞬间得鼠标形状吗?
还有,如果我在View得OnInitialUpdate中用
SetCursor后,发现程序启动后得鼠标指针没有变...更是感到奇怪...希望大哥们指教.

解决方案 »

  1.   

    看看这个
    BOOL m_cursor;void CCorsurDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
    {
    // TODO: Add your message handler code here and/or call default
    char lschar;
    HCURSOR lhcursor;
    lschar=char(nChar);
    if(lschar=='A')
    {
    lhcursor=AfxGetApp()->LoadStandardCursor(IDC_ARROW);
    SetCursor(lhcursor);
    }
        if(lschar=='B')
    {
    //lhcursor=AfxGetApp()->LoadCursor(IDC_CURSOR1);
    lhcursor=LoadCursor(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDC_CURSOR1));
        SetCursor(lhcursor);
    }
    if(lschar=='C')
    {
    lhcursor=AfxGetApp()->LoadStandardCursor(IDC_WAIT);
        SetCursor(lhcursor);
    }
    if(lschar=='X')
    {
    lhcursor=AfxGetApp()->LoadStandardCursor(IDC_WAIT);
    m_cursor=TRUE;
    SetCursor(lhcursor);
    // OnOK();
    }
    else
    {
    m_cursor=TRUE;SetCursor(lhcursor);


    CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
    }BOOL CCorsurDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
    {
    // TODO: Add your message handler code here and/or call default
    if(m_cursor)
    return TRUE;
    else
    return CDialog::OnSetCursor(pWnd, nHitTest, message);
    }
      

  2.   

    大哥,我时初学者,请给我讲讲原理吧,象这样地代码我再csdn可以找到一大堆啊...呵呵.
      

  3.   

    "我用下面代码可以修改鼠标光标.
    MyView::OnLButtonDown(...);
    {
    ............................
    ::SetCursor(::LoadCursor(NULL,IDC_CROSS));
    }
    在我按下鼠标左键时,鼠标就会变成十字形.但是如果鼠标拖动一下或者放开鼠标,则鼠标得形状马上变成了指针了."It's normal from ur code :)
    The framework calls this member function when the user presses the left mouse button.Note   This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was received. If you call the base-class implementation of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function.
    u'd use anther event
      

  4.   

    重载MyView::OnLButtonDown(...);MyView::OnLButtonUp(...);
    MyView::OnSetCursor(...);为MyView添加变量BOOL bDown;并在构造函数中初始化它为FALSE;
    MyView::OnLButtonDown(...)
    {
           //添加
          bDown=TRUE;
    }
    MyView::OnLButtonUp(...)
    {
          //添加
          bDown=FALSE;
    }
    MyView::OnSetCursor(...)
    {
        //修改如下
        if(bDown)
        {
    ::SetCursor(::LoadCursor(NULL,IDC_CROSS));
    return TRUE;
        }
        else return CView::OnSetCursor(pWnd, nHitTest, message);
    }
    非常简单,给分给分:)
      

  5.   

    to ukyoking(乐易) :
        大哥没有看清楚我的问题。
      

  6.   

    原因很简单啊,每当需要设置光标时框架会自动调用默认的光标设置,你的意思是想实现在鼠标移动
    到客户区时自动设置光标吗?那样可以重载框架类的OnSetCursor在其中添加
    if(nHitTest==HTCLIENT)
    {
     ::SetCursor(::LoadCursor(NULL,IDC_CROSS));
    return TRUE;
    }
    else return CMainFrame::OnSetCursor(pWnd, nHitTest, message);