跟随鼠标移动的线
本人利用了网上的一个类进行波形的显示,类名为COScopeCtrl,派生于CStatic,现在需要当鼠标移动到波形显示框区域(CStatic)的时候有个线跟随者鼠标移动,而且当鼠标按下时画出一条线,现在的问题时,我在COScopeCtrl类里面建立了映射OnMouseMove,而且在里面利用一变量保存了鼠标的点,m_PointMouse为成员变量
// OScopeCtrl.h : header file
//
#ifndef __OScopeCtrl_H__
#define __OScopeCtrl_H__
/////////////////////////////////////////////////////////////////////////////
// COScopeCtrl window
class COScopeCtrl : public CStatic
{
// Construction
public:
COScopeCtrl();
// Attributes
CDC m_dcGrid;
CDC m_dcPlot;
CDC m_dcCrossline;
CBitmap *m_pbitmapOldGrid;
CBitmap *m_pbitmapOldPlot;
CBitmap *m_pbitmapOldCrossline;
CBitmap m_bitmapGrid;
CBitmap m_bitmapPlot;
// CBitmap *m_pbitmapOldCrossline;
CBitmap m_bitmapCrossline;
public:
void DrawCrossline();
......
public:
CPoint m_PointMouse;
COLORREF m_crBackColor; // background color
COLORREF m_crGridColor; // grid color
COLORREF m_crPlotColor; // data color
COLORREF m_crCrosslineColor; //crossline color
......
// OScopeCtrl.cpp : implementation file//
void COScopeCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_PointMouse=point;
CStatic::OnMouseMove(nFlags, point);
}
自己编写的画线的函数
void COScopeCtrl::DrawCrossline()
{
int x,CPen *oldPen ;
CPoint w_s,w_e;
x=m_PointMouse.x;
//x=(m_rectClient.left+m_rectClient.right)/2;
w_s.x=x;
w_s.y=m_rectClient.bottom;
w_e.x=x;
w_e.y=m_rectClient.top;
if (m_dcCrossline.GetSafeHdc() != NULL)
{
// fill the cleanup area with the background
m_dcCrossline.FillRect(rectCleanUp, &m_brushBack) ;
oldPen = m_dcCrossline.SelectObject(&m_penCrossline) ;
m_dcCrossline.MoveTo (w_s) ;
m_dcCrossline.LineTo (w_e) ;
// restore the pen
m_dcCrossline.SelectObject(oldPen) ;
}
在void COScopeCtrl::OnPaint()
{
CPaintDC dc(this) ; // device context for painting
CDC memDC ;
CBitmap memBitmap ;
CBitmap* oldBitmap ; // bitmap originally found in CMemDC
// no real plotting work is performed here,
// just putting the existing bitmaps on the client
// to avoid flicker, establish a memory dc, draw to it
// and then BitBlt it to the client
memDC.CreateCompatibleDC(&dc) ;
memBitmap.CreateCompatibleBitmap(&dc, m_nClientWidth, m_nClientHeight) ;
oldBitmap = (CBitmap *)memDC.SelectObject(&memBitmap) ;
//DrawCrossline();
if (memDC.GetSafeHdc() != NULL)
{
// first drop the grid on the memory dc
memDC.BitBlt(0, 0, m_nClientWidth, m_nClientHeight,
&m_dcGrid, 0, 0, SRCCOPY) ;
// now add the plot on top as a "pattern" via SRCPAINT.
// works well with dark background and a light plot
memDC.BitBlt(0, 0, m_nClientWidth, m_nClientHeight,
&m_dcPlot, 0, 0, SRCPAINT) ; //SRCPAINT
// memDC.BitBlt(0, 0, m_nClientWidth, m_nClientHeight,
// &m_dcCrossline, 0, 0, SRCPAINT) ;
memDC.MoveTo(m_PointMouse.x,m_rectPlot.top);
memDC.LineTo(m_PointMouse.x,m_rectPlot.bottom);
memDC.BitBlt(0, 0, m_nClientWidth, m_nClientHeight,
&m_dcCrossline, 0, 0, SRCPAINT) ; //SRCPAINT
// finally send the result to the display
dc.BitBlt(0, 0, m_nClientWidth, m_nClientHeight,
&memDC, 0, 0, SRCCOPY) ;
}
memDC.SelectObject(oldBitmap) ;
} //
memDC.MoveTo(m_PointMouse.x,m_rectPlot.top);
memDC.LineTo(m_PointMouse.x,m_rectPlot.bottom);是用来尝试的划线的,主要用来检测鼠标的点值是否传递回来,当采用固定的点x为上下边框的一半时,可以画出来一条直线,现在是感觉在mousemove函数里面的值并没有传递m_PointMouse,用单步调试时在onmuosemove里面加入MessageBox("是否真的结束?","message",MB_YESNO);也有对话框弹出,将断点直接设置 m_PointMouse=point;时也有值,而画出的线还是m_PointMouse=0;时的值(m_PointMouse在构造函数被初始化为0),感觉onmuosemove的执行在划线之后,
请各位大侠帮忙看看什么问题,怎么解决,小弟非常感谢啊!