对了,我的Email是 [email protected] 

解决方案 »

  1.   

    做一个+形的光标SetCursor进去然后GetDC(0);在光标上显示坐标
      

  2.   

    可惜我不会VC:(
    用VB的话可能轻松搞定。
      

  3.   

    NowCan,好像是老朋友,经常见到你谢谢你的关注!
    对了,在这里再次丢下我得Email: [email protected] 
    希望对鼠标编程有经验的朋友顺便帮一下我,编个例程,非常感谢!
      

  4.   

    chen_pin,这个程序太容易了。 不过我现在在网吧里,没办法现在就写出来。我最迟后天给你发例程。不知道你能否把分保留给我呀? :)
      

  5.   

    程序已经编好,可惜邮箱出了问题
    编完后发现,没有什么难点啊
    只要在OnPaint()里面稍做修改就可以了啊
    不知道你是怎么想的,难道对Painting&Drawing不熟悉?
      

  6.   

    还是发不出去,把OnPaint()函数复制如下:
    void CCrossDlg::OnPaint() 
    {
    if (IsIconic())
    {
    CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
    CPaintDC *pDC = new CPaintDC(this);
    CPen pen, *pOldPen;
    pen.CreatePen(PS_DOT, 1, RGB(255, 255, 0));
    pOldPen = pDC->SelectObject(&pen);
    CRect rect;
    GetClientRect(&rect);
    //get the current char height and width
    int nCharWidth, nCharHeight;
    TEXTMETRIC Metrics;
    pDC->GetTextMetrics(&Metrics);
    nCharWidth = Metrics.tmAveCharWidth;
    nCharHeight = Metrics.tmHeight + Metrics.tmExternalLeading; CString strMessageYX, strMessageYY;
    int nStartTextYX, nStartTextYY, nStartLineYX, nStartLineYY;
    nStartTextYX = 0;
    nStartTextYY = m_MouseY; //we can input the mouse's y for this
    strMessageYY.Format(_T("Y=%d"), nStartTextYY); //the y of mouse
    //
    nStartLineYX = nStartTextYX + nCharWidth * (strMessageYY.GetLength() + 1);
    nStartLineYY = nStartTextYY;
    //draw the text
    pDC->TextOut(nStartTextYX, nStartTextYY-nCharHeight/2, strMessageYY);
    //draw the line
    pDC->MoveTo(nStartLineYX, nStartLineYY);
    pDC->LineTo(rect.Width(), nStartLineYY);
    //
    //Draw the XX line
    //
    int nStartTextXX, nStartTextXY, nStartLineXX, nStartLineXY;
    CString strMessageXX, strMessageXY;
    strMessageXX.Format(_T("X=%d"), m_MouseX);
    nStartTextXX = m_MouseX - nCharWidth*strMessageXX.GetLength()/2;
    nStartTextXY = 0;
    nStartLineXX = m_MouseX;
    nStartLineXY = nCharHeight;
    //draw x message text
    pDC->TextOut(nStartTextXX, nStartTextXY, strMessageXX);
    //draw line
    pDC->MoveTo(nStartLineXX, nStartLineXY);
    pDC->LineTo(nStartLineXX, rect.Height());
    pDC->SelectObject(pOldPen);
    delete pDC;
    }
    }
    另外有:
    void CCrossDlg::OnMouseMove(UINT nFlags, CPoint point) 
    {
    m_MouseX = point.x;
    m_MouseY = point.y;
    Invalidate(TRUE);
    CDialog::OnMouseMove(nFlags, point);
    }
    其中m_MouseX,m_MouseY是在CCrossDlg中声明的变量:
    ……
    public:
    int m_MouseY;//mouse's x coordinate
    int m_MouseX;//mouse's y coordinate
    ……
      

  7.   

    我的是画笔,你试试
    const unsigned char CursorA[32][4] = {0x00,0x00,0x00,0x00,  //0
                                 0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,
     0x00,0x00,0x00,0x00,  //5
     0x00,0x00,0x0e,0x00,
     0x00,0x00,0x1f,0x00,
     0x00,0x00,0x3f,0x80,
     0x00,0x00,0x3f,0xc0,
     0x00,0x00,0x3f,0xc0,  //10
     0x00,0x00,0x4f,0xc0,
     0x00,0x00,0x87,0x80,
                                 0x00,0x01,0x0f,0x00,
     0x00,0x02,0x18,0x00,
     0x00,0x04,0x30,0x00,  //15
     0x00,0x08,0x60,0x00,
     0x00,0x10,0xc0,0x00,
     0x00,0x21,0x80,0x00,
     0x00,0x43,0x00,0x00,
     0x00,0x86,0x00,0x00,  //20
     0x01,0x0c,0x00,0x00,
     0x02,0x18,0x00,0x00,
     0x04,0x30,0x00,0x00,
                                 0x08,0x60,0x00,0x00,
     0x10,0xc0,0x00,0x00,  //25
     0x21,0x80,0x00,0x00,
     0x63,0x00,0x00,0x00,
     0x76,0x00,0x00,0x00,
     0x7c,0x00,0x00,0x00,
     0xf8,0x00,0x00,0x00,  //30
     0xc0,0x00,0x00,0x00}; unsigned char CursorB[32][4];
    for(int i=0;i<32;i++)
    for(int j=0;j<4;j++)
    CursorB[i][j] = 0xff;
    NewCursor = CreateCursor(AfxGetApp()->m_hInstance,0,32,32,32,CursorB,CursorA);然后:BOOL CLedView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)    //改变光标
    {
    if(MouseChange == false)
    {
    if(MouseYesNo)
    {
    ::SetCursor(NewCursor);
    MouseChange = true;
    return -1;
    }
    return CView::OnSetCursor(pWnd, nHitTest, message);
    }
    else
    {
    if(!MouseYesNo)
    {
    ::SetCursor(oldCursor);
    MouseChange = false;
    return CView::OnSetCursor(pWnd, nHitTest, message);
    }
    return -1;
    }

    return CView::OnSetCursor(pWnd, nHitTest, message);
    }
      

  8.   

    (to) killingfield(灵胡):
       你的程序做的不错,就是当鼠标移动时候,OnPaint()会让矩形框内原有的图象擦除。我是想达到 鼠标线能在矩形框中原有曲线移动,又不破坏曲线的效果。~ 不知怎么改。(to) zf925(天下哪来那么多高手): 
      谢谢你的关注。我会看看。。
      

  9.   

    (to) zf925(天下哪来那么多高手):
      我不只是自定义光标,而是还要能产生 十字架橡皮筋线 的效果~~ 不知道你有没有办法
      谢谢你的关注!! 
      

  10.   

    你可以把killingfield(灵胡)的程序改一下,就是在OnPaint函数中,不用擦除,而用底色把刚才画的线重新画一下,这样就会覆盖了,然后在画新的线.很容易的,你自己可以做出来的
      

  11.   

    我看只能对鼠标移动的消息进行处理,这样才能保证速度。
    自己保存鼠标移动的标志:是否在矩形内,上个OnMouseMove消息的鼠标位置,这样,利用CDC类的基本画图工具就可以的。画线的时候,以像素取反的方式画,这样,两次之后就还原为原来的像素了。
      

  12.   

    (to) georgehuang & zxiaoer:
         我现在就是想在OnMouseMove中处理,但是,只要鼠标一移动,整个屏幕就会闪烁,包括按钮及按钮文字跟着一起闪。对这个不是太熟。不知是谁可以解决。
      

  13.   

    这是因为你调用了OnPaint函数,对话框客户区一直重画的结果。
    解决的方法有:
    1.用InvalidateRect()函数,不用Invalidate();他们的区别你应该知道的。这样效果会好点。
    2.可以用贴图的方法,就是不用重画,而是把前面一次移动的客户面的一块区域先拷贝下来,然后在这次移动的时候贴回去。这样屏幕不会闪动的很厉害,但是鼠标不能移动的太快。
      

  14.   

    》》》》》》》》》》》》》谨请注意(另)《《《《《《《《《《《《《《《《《《
       
     强烈注意:::例程需要具备 不改变、擦除 矩形框内原来曲线。不要使整个对话框闪烁 的功能。
     建议在例程中:先画一条曲线,再看看是否满足要求。(不要原先就在对话框中加picture控件,反映不出效果) 
      

  15.   

    我的完全可以满足你的要求的。对了刚才发信时忘记了告诉我的Email:[email protected]
      

  16.   

    void CShubiaoDialog::OnPaint()
    {CPaintDC dc(this); // device context for painting
    CString Xstring,Ystring;
    CBrush *brush;
    CRect rect,Inrect(20,20,150,150);
    dc.FillRect(Inrect,brush);
    if(Inrect.PtInRect(CurrentPoint))
    {
    CPen pen ,*pOldPen;
    GetClientRect(rect);
    Xstring.Format("x=%d",m_MouseX-20);
    Ystring.Format("y=%d",150-m_MouseY);
    dc.TextOut(m_MouseX,m_MouseY-20,Ystring);
    dc.TextOut(m_MouseX-50,m_MouseY,Xstring);
    pen.CreatePen(PS_DOT, 1, RGB(255, 255, 0));
    pOldPen =dc.SelectObject(&pen);
    dc.MoveTo(0,m_MouseY);
    dc.LineTo(rect.Width(),m_MouseY);
    dc.MoveTo(m_MouseX,0);
    dc.LineTo(m_MouseX,rect.Height());
    }
    }
    void CShubiaoDialog::OnMouseMove(UINT nFlags, CPoint point)
    m_MouseX = point.x;
          m_MouseY = point.y;
      CurrentPoint=point;
          Invalidate(TRUE);
          CDialog::OnMouseMove(nFlags, point);
      

  17.   

    参考 http://www.csdn.net/oldexpert/topicview1.asp 
    一回事