MFC picture控件 鼠标响应 各位大侠: 帮帮小妹,我想实现picture控件的鼠标响应,就是在打开的图像上移动鼠标,可以得到或显示出picture控件中打开图像的坐标信息。(基于对话框的) 我的C++和MFC学的实在不好,帮帮我吧~~ 多谢啦!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 本帖最后由 VisualEleven 于 2012-12-28 16:26:50 编辑 不知道你要哪种效果1.直接弄个Label,放在Picture Control旁边。OnMouseMove事件里面触发,每次修改Label的值,可以在窗体的PretranslateMessage里面截获,判断如果再Picture的Rect之中(PtInRect函数)则修改Label的值。2.如果想在Picture上面显示的话,可以用CToolTipCtrl,我个人一般用cpptooltips(开源控件) 我添加了 但是不知道为什么没反应。我是这样做的: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); } }不知道对不 请大侠指点。 你的OnMouseMove是对话框的,不是控件的,事件要在自定义控件类中写 在那个设计界面,设置pic控件的属性Notify为TRUE就可以接收到mouse move msg了 谢谢大家 我已经解决了~~不能用opencv直接读图,然后实现鼠标移动响应~~ 问一下,你这个不能用opencv直接读图是啥意思啊? 你好,我也是基于对话框处理图片的,加载完图像后想在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);} 求ftp免费空间: 对话框接收消息的问题 ? 毕业,卖书,兼散分 CListBox 内容显示问题 鼠标点击信息 如何绘制非矩形标题兰 opengl 与 vc++结合问题 如何设置控件的字体?特急请教! 关于memDC和bitmap,急 昨天的问题仍未解决,请帮帮忙! VC如何让图标跟随鼠标移动 一个关于MFC下框架打印问题
OnMouseMove事件里面触发,每次修改Label的值,可以在窗体的PretranslateMessage里面截获,判断如果再Picture的Rect之中(PtInRect函数)则修改Label的值。
2.如果想在Picture上面显示的话,可以用CToolTipCtrl,我个人一般用cpptooltips(开源控件)
我添加了 但是不知道为什么没反应。我是这样做的:
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);
} }
不知道对不 请大侠指点。
事件要在自定义控件类中写
下面是我鼠标按下和移动的代码,弹起的代码没有贴出来
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);
}