各位大侠: 
     
       帮帮小妹,我想实现picture控件的鼠标响应,就是在打开的图像上移动鼠标,可以得到或显示出picture控件中打开图像的坐标信息。(基于对话框的)
      我的C++和MFC学的实在不好,帮帮我吧~~
      多谢啦!!!

解决方案 »

  1.   

    本帖最后由 VisualEleven 于 2012-12-28 16:26:50 编辑
      

  2.   

    不知道你要哪种效果1.直接弄个Label,放在Picture Control旁边。
    OnMouseMove事件里面触发,每次修改Label的值,可以在窗体的PretranslateMessage里面截获,判断如果再Picture的Rect之中(PtInRect函数)则修改Label的值。
    2.如果想在Picture上面显示的话,可以用CToolTipCtrl,我个人一般用cpptooltips(开源控件)
      

  3.   


       我添加了 但是不知道为什么没反应。我是这样做的:
    void CBianxingDlg::OnOpenfile()   //打开源图像-img对象
    {
    // TODO: Add your control notification handler code here
    UpdateData(true);
    CString  FileName;  
        CFileDialog dlg(TRUE);  
        if(dlg.DoModal()==IDOK)
    FileName=dlg.GetPathName();  //获取路径
    {
    img=cvLoadImage(FileName);  //载入图像 

    DrawPicToHDC(img, IDC_Show1);
    flag=1;
    }
    void CBianxingDlg::OnMouseMove(UINT nFlags, CPoint point)
     {
     if(flag==1)
     { 
     CString str1,str2;
     pWnd = GetDlgItem(IDC_Show1);
     CDC *mpDC = pWnd->GetDC();
     int w,h;
     w=img->width; //源图像的宽和高
     h=img->height;
     
     for( int y=0;y<h;y++)
     {
     for (int x=0;x<w;x++)
     {
     point1.x=x;
     point1.y=y;
     m_x=point1.x;
                     m_y=point1.y;  }
     
     }       UpdateData(false);
             }     }
    不知道对不 请大侠指点。
      

  4.   

    你的OnMouseMove是对话框的,不是控件的,
    事件要在自定义控件类中写
      

  5.   

    在那个设计界面,设置pic控件的属性Notify为TRUE就可以接收到mouse move msg了
      

  6.   

    谢谢大家 我已经解决了~~不能用opencv直接读图,然后实现鼠标移动响应~~
      

  7.   

    问一下,你这个不能用opencv直接读图是啥意思啊?
      

  8.   

    你好,我也是基于对话框处理图片的,加载完图像后想在picture控件里用鼠标画矩形区域,并将该矩形区域显示在预览窗口,现在遇到的问题是,鼠标在picture控件中按下没有反应,在对话框其他地方鼠标按下可以画矩形,不知道什么原因
    下面是我鼠标按下和移动的代码,弹起的代码没有贴出来
    void mydlg::OnMouseMove(UINT nFlags, CPoint point) 
    {
    if(m_bDrag)
    {
    RECT lastrect, currect;
    lastrect.top = m_LBDnPoint.y > m_LastPoint.y ? m_LastPoint.y : m_LBDnPoint.y;
    lastrect.left = m_LBDnPoint.x > m_LastPoint.x ? m_LastPoint.x : m_LBDnPoint.x;
    lastrect.right = m_LBDnPoint.x > m_LastPoint.x ? m_LBDnPoint.x : m_LastPoint.x;
    lastrect.bottom = m_LBDnPoint.y > m_LastPoint.y ? m_LBDnPoint.y : m_LastPoint.y;
    currect.top = m_LBDnPoint.y > point.y ? point.y : m_LBDnPoint.y;
    currect.left = m_LBDnPoint.x > point.x ? point.x : m_LBDnPoint.x;
    currect.right = m_LBDnPoint.x > point.x ? m_LBDnPoint.x : point.x;
    currect.bottom = m_LBDnPoint.y > point.y ? m_LBDnPoint.y : point.y; SIZE sz;
    sz.cx = 1;
    sz.cy = 1; 
    CDC *pdc = GetDlgItem(IDC_Picture)->GetDC();
    //CDC::FromHandle(g_hBitmap.GetDC());  
    pdc->DrawDragRect(&currect, m_DragRectSize, &lastrect, m_DragRectSize, NULL, NULL);
    ReleaseDC(pdc); m_LastPoint = point;
    }

    CDialogEx::OnMouseMove(nFlags, point);
    }