要求在视图中单击鼠标左键,在单击处输出点击处的坐标,当窗口大小改变或移动时,视图输出不变,我在view类添加一个如下的鼠标左健响应函数,但不知道该怎么样才能实现“当窗口大小改变或移动时,视图输出不变”,请大家指教,小弟在此先谢谢了
void CEx3_4View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
Location=point;
CString str;
str.Format("this=%d,%d",Location.x,Location.y);
CClientDC dc(this);
dc.TextOut(Location.x,Location.y,str); CView::OnLButtonDown(nFlags, point);
}
void CEx3_4View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
Location=point;
CString str;
str.Format("this=%d,%d",Location.x,Location.y);
CClientDC dc(this);
dc.TextOut(Location.x,Location.y,str); CView::OnLButtonDown(nFlags, point);
}
CString str;
str.Format("this=%d,%d",Location.x,Location.y);
dc.TextOut(Location.x,Location.y,str);
那个OnPaint 函数在哪了啊?是不是也是自己定义一个OnPaint函数?我刚学习vc,不明白,请你说详细点好吗?
str.Format("this=%d,%d",Location.x,Location.y);
dc.TextOut(Location.x,Location.y,str);这段代码只能放在OnLButtonDown()函数中才能有正确的预期结果,我不明白为什么?
void CExcelView::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CString str;
str.Format("this=%d,%d",Location.x,Location.y);
dc.TextOut(Location.x,Location.y,str);
// Do not call CFormView::OnPaint() for painting messages
}
楼上几位的意见,我都试了,都不行,都是Location的值传不过去,始终0
只能放在OnLButtonDown()函数中才正确,可是放在这个函数中不能重绘窗口
感谢楼上几位的意见,小弟感激不尽
Invalidate();使窗口立即重画,就可以看到输出了
Invalidate();使窗口立即重画,就可以看到输出了