各位大神好,我用PreTranslateMessage(MSG* pMsg)写了个消息处理函数,但是为什么鼠标弹起的消息不能响应呢?
就是鼠标弹起后,没有去执行鼠标弹起的处理函数,代码如下:
BOOL CNewStatic::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
CPoint point;
point.x=LOWORD(pMsg->lParam);
point.y=HIWORD(pMsg->lParam);
if(pMsg->message==WM_LBUTTONDOWN)
{
KEYDOWN=TRUE;
cvCopy(org,img);//为了备份现有文件
sprintf(temp,"(%d,%d)",point.x,point.y);
pre_pt = cvPoint(point.x,point.y);
cvPutText(img,temp, pre_pt, &font, cvScalar(0,0, 0, 255));
cvCircle( img, pre_pt, 3,cvScalar(255,0,0,0) ,CV_FILLED, CV_AA, 0 );
RRDrawPicToHDC(img);
cvCopy(img,tmp);
Sleep(100);
}
else if(pMsg->message==WM_MOUSEMOVE)
{
if(KEYDOWN==TRUE)
{
cvCopy(tmp,img);
sprintf(temp,"(%d,%d)",point.x,point.y);
cur_pt = cvPoint(point.x,point.y);
cvPutText(img,temp, cur_pt, &font, cvScalar(0,0, 0, 255));
cvRectangle(img, pre_pt, cur_pt, cvScalar(0,255,0,0), 1, 8, 0 );
RRDrawPicToHDC(img);
}
if(KEYDOWN==FALSE)
{
cvCopy(tmp,img);
sprintf(temp,"(%d,%d)",point.x,point.y);
cur_pt = cvPoint(point.x,point.y);
cvPutText(img,temp, cur_pt, &font, cvScalar(0,0, 0, 255));
////RRDrawPicToHDC(img);
} }
else if(pMsg->message==WM_LBUTTONUP)
{
KEYDOWN=FALSE;
cvCopy(tmp,img);
sprintf(temp,"(%d,%d)",point.x,point.y);
cur_pt = cvPoint(point.x,point.y);
cvPutText(img,temp, cur_pt, &font, cvScalar(0,0, 0, 255));
cvCircle( img, cur_pt, 3,cvScalar(255,0,0,0) ,CV_FILLED, CV_AA, 0 );
cvRectangle( img, pre_pt, cur_pt, cvScalar(0,255,0,0), 1, 8, 0 );
RRDrawPicToHDC(img);
cvCopy(tmp,img);
int width=abs(pre_pt.x-cur_pt.x);
int height=abs(pre_pt.y-cur_pt.y);
aaa=width;//截取的图像宽度
bbb=height;//截取的图像高度
if(width==0 || height==0)
{
return 0;
}
dst=cvCreateImage(cvSize(width,height),org->depth,org->nChannels);
CvRect rect;
if(pre_pt.x<cur_pt.x && pre_pt.y<cur_pt.y)
{
rect=cvRect(pre_pt.x,pre_pt.y,width,height);
}
else if(pre_pt.x>cur_pt.x && pre_pt.y<cur_pt.y)
{
rect=cvRect(cur_pt.x,pre_pt.y,width,height);
}
else if(pre_pt.x>cur_pt.x && pre_pt.y>cur_pt.y)
{
rect=cvRect(cur_pt.x,cur_pt.y,width,height);
}
else if(pre_pt.x<cur_pt.x && pre_pt.y>cur_pt.y)
{
rect=cvRect(pre_pt.x,cur_pt.y,width,height);
}
cvSetImageROI(org,rect);
cvCopy(org,dst);
cvNamedWindow("sunlu",CV_WINDOW_AUTOSIZE);
cvShowImage("sunlu",dst);
cvResetImageROI(org);
cvSaveImage("D:\\第一次截取的图像.bmp",dst);
}
return CStatic::PreTranslateMessage(pMsg);
}
但是当我删掉鼠标移动消息之后就可以响应鼠标左键弹起消息,请问是什么原因啊》
就是鼠标弹起后,没有去执行鼠标弹起的处理函数,代码如下:
BOOL CNewStatic::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
CPoint point;
point.x=LOWORD(pMsg->lParam);
point.y=HIWORD(pMsg->lParam);
if(pMsg->message==WM_LBUTTONDOWN)
{
KEYDOWN=TRUE;
cvCopy(org,img);//为了备份现有文件
sprintf(temp,"(%d,%d)",point.x,point.y);
pre_pt = cvPoint(point.x,point.y);
cvPutText(img,temp, pre_pt, &font, cvScalar(0,0, 0, 255));
cvCircle( img, pre_pt, 3,cvScalar(255,0,0,0) ,CV_FILLED, CV_AA, 0 );
RRDrawPicToHDC(img);
cvCopy(img,tmp);
Sleep(100);
}
else if(pMsg->message==WM_MOUSEMOVE)
{
if(KEYDOWN==TRUE)
{
cvCopy(tmp,img);
sprintf(temp,"(%d,%d)",point.x,point.y);
cur_pt = cvPoint(point.x,point.y);
cvPutText(img,temp, cur_pt, &font, cvScalar(0,0, 0, 255));
cvRectangle(img, pre_pt, cur_pt, cvScalar(0,255,0,0), 1, 8, 0 );
RRDrawPicToHDC(img);
}
if(KEYDOWN==FALSE)
{
cvCopy(tmp,img);
sprintf(temp,"(%d,%d)",point.x,point.y);
cur_pt = cvPoint(point.x,point.y);
cvPutText(img,temp, cur_pt, &font, cvScalar(0,0, 0, 255));
////RRDrawPicToHDC(img);
} }
else if(pMsg->message==WM_LBUTTONUP)
{
KEYDOWN=FALSE;
cvCopy(tmp,img);
sprintf(temp,"(%d,%d)",point.x,point.y);
cur_pt = cvPoint(point.x,point.y);
cvPutText(img,temp, cur_pt, &font, cvScalar(0,0, 0, 255));
cvCircle( img, cur_pt, 3,cvScalar(255,0,0,0) ,CV_FILLED, CV_AA, 0 );
cvRectangle( img, pre_pt, cur_pt, cvScalar(0,255,0,0), 1, 8, 0 );
RRDrawPicToHDC(img);
cvCopy(tmp,img);
int width=abs(pre_pt.x-cur_pt.x);
int height=abs(pre_pt.y-cur_pt.y);
aaa=width;//截取的图像宽度
bbb=height;//截取的图像高度
if(width==0 || height==0)
{
return 0;
}
dst=cvCreateImage(cvSize(width,height),org->depth,org->nChannels);
CvRect rect;
if(pre_pt.x<cur_pt.x && pre_pt.y<cur_pt.y)
{
rect=cvRect(pre_pt.x,pre_pt.y,width,height);
}
else if(pre_pt.x>cur_pt.x && pre_pt.y<cur_pt.y)
{
rect=cvRect(cur_pt.x,pre_pt.y,width,height);
}
else if(pre_pt.x>cur_pt.x && pre_pt.y>cur_pt.y)
{
rect=cvRect(cur_pt.x,cur_pt.y,width,height);
}
else if(pre_pt.x<cur_pt.x && pre_pt.y>cur_pt.y)
{
rect=cvRect(pre_pt.x,cur_pt.y,width,height);
}
cvSetImageROI(org,rect);
cvCopy(org,dst);
cvNamedWindow("sunlu",CV_WINDOW_AUTOSIZE);
cvShowImage("sunlu",dst);
cvResetImageROI(org);
cvSaveImage("D:\\第一次截取的图像.bmp",dst);
}
return CStatic::PreTranslateMessage(pMsg);
}
但是当我删掉鼠标移动消息之后就可以响应鼠标左键弹起消息,请问是什么原因啊》
解决方案 »
- Vista/windows7 电源管理-〉调节显示器亮度
- 你好,请教一个问题:如何在CStatic标签上显示图片.
- typedef CMap<UINT,UINT,CCgiStat*,CCgiStat*&> CMapCgiStat; CCgiStat*&代表什么意思?
- 如果不用GDI+,只用GDI,用渐进色填充一个圆形区域?
- 结构体中带CArray<>模版的应用问题
- vc中这么多字符类型有什么区别呀?char、TCHAR、char *、const char *、LPSTR、LPCSTR、LPCTSTR、CString、CStdString、BSTR、_bstr_t...
- 紧急求助……CTreeCtrl的使用
- csdn页面的问题???
- 哪有解非线性方程的算法,能解出全部根的,比如三次的,谢了(内空)
- 一个c的小问题,贴到这里来。
- vfw,opencv,directshow
- VFW的摄像头USB接口
void CNewStatic::RRDrawPicToHDC(IplImage* shishi)
{
CDC *pDC = this->GetDC();
HDC hDC = pDC->GetSafeHdc();
CRect rect;
this->GetClientRect(&rect);
CvvImage cimg;
cimg.CopyOf(shishi);
cimg.DrawToHDC(hDC,&rect);
ReleaseDC(pDC);
}
void CNewStatic::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
Sleep(100);
KEYDOWN=FALSE;
cvCopy(tmp,img);
sprintf(temp,"(%d,%d)",point.x,point.y);
cur_pt = cvPoint(point.x,point.y);
cvPutText(img,temp, cur_pt, &font, cvScalar(0,0, 0, 255));
cvCircle( img, cur_pt, 3,cvScalar(255,0,0,0) ,CV_FILLED, CV_AA, 0 );
cvRectangle( img, pre_pt, cur_pt, cvScalar(0,255,0,0), 1, 8, 0 );
RRDrawPicToHDC(img);
cvCopy(tmp,img);
int width=abs(pre_pt.x-cur_pt.x);
int height=abs(pre_pt.y-cur_pt.y);
aaa=width;//截取的图像宽度
bbb=height;//截取的图像高度
if(width==0 || height==0)
{
AfxMessageBox("error");
}
dst=cvCreateImage(cvSize(width,height),org->depth,org->nChannels);
CvRect rect;
if(pre_pt.x<cur_pt.x && pre_pt.y<cur_pt.y)
{
rect=cvRect(pre_pt.x,pre_pt.y,width,height);
}
else if(pre_pt.x>cur_pt.x && pre_pt.y<cur_pt.y)
{
rect=cvRect(cur_pt.x,pre_pt.y,width,height);
}
else if(pre_pt.x>cur_pt.x && pre_pt.y>cur_pt.y)
{
rect=cvRect(cur_pt.x,cur_pt.y,width,height);
}
else if(pre_pt.x<cur_pt.x && pre_pt.y>cur_pt.y)
{
rect=cvRect(pre_pt.x,cur_pt.y,width,height);
}
cvSetImageROI(org,rect);
cvCopy(org,dst);
cvNamedWindow("sunlu",CV_WINDOW_AUTOSIZE);
cvShowImage("sunlu",dst);
cvResetImageROI(org);
cvSaveImage("D:\\第一次截取的图像.bmp",dst); 可是开始时鼠标左键按下能响应,按下左键时移动也能响应,再弹起鼠标时就不能响应,有点类似于失去鼠标焦点,但我又没有更改鼠标焦点,为什么会这样啊?还有会不会是消息阻塞啊
Sleep(100);
CStatic::OnLButtonUp(nFlags, point);
}void CNewStatic::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(nFlags & MK_LBUTTON==MK_LBUTTON)
{
cvCopy(tmp,img);
sprintf(temp,"(%d,%d)",point.x,point.y);
cur_pt = cvPoint(point.x,point.y);
cvPutText(img,temp, cur_pt, &font, cvScalar(0,0, 0, 255));
cvRectangle(img, pre_pt, cur_pt, cvScalar(0,255,0,0), 1, 8, 0 );
RRDrawPicToHDC(img);
}
else
{
cvCopy(tmp,img);
sprintf(temp,"(%d,%d)",point.x,point.y);
cur_pt = cvPoint(point.x,point.y);
cvPutText(img,temp, cur_pt, &font, cvScalar(0,0, 0, 255));
RRDrawPicToHDC(img);
}
CStatic::OnMouseMove(nFlags, point);
}*/void CNewStatic::RRDrawPicToHDC(IplImage* shishi)
{
CDC *pDC = this->GetDC();
HDC hDC = pDC->GetSafeHdc();
CRect rect;
this->GetClientRect(&rect);
CvvImage cimg;
cimg.CopyOf(shishi);
cimg.DrawToHDC(hDC,&rect);
ReleaseDC(pDC); /* BITMAPINFO* bi =(BITMAPINFO *) new BYTE[sizeof(BITMAPINFOHEADER)];
bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi->bmiHeader.biWidth = rect.Width();
bi->bmiHeader.biHeight = rect.Height();
bi->bmiHeader.biBitCount = 24;
bi->bmiHeader.biPlanes = 1;
bi->bmiHeader.biCompression = BI_RGB;
bi->bmiHeader.biSizeImage = 0;
bi->bmiHeader.biXPelsPerMeter = 0;
bi->bmiHeader.biYPelsPerMeter = 0;
bi->bmiHeader.biClrUsed = 0;
bi->bmiHeader.biClrImportant = 0;
//SetStretchBltMode(hDC,HALFTONE);
this->OnPaint();
::StretchDIBits(hDC,0,0,rect.Width(),rect.Height(),
0,0,rect.Width(),rect.Height(),(CONST VOID *)shishi->imageData,(BITMAPINFO*)bi,
DIB_RGB_COLORS,SRCCOPY);
ReleaseDC(pDC);*/}