我在Onpaint()函数里面绘制了一个位图,我用以下程序怎么没反应呢?void CMyStatic::OnLButtonDown(UINT nFlags, CPoint point) 
{
// TODO: Add your message handler code here and/or call default
m_mousedownx=point.x;
m_mousedowny=point.y;
CStatic::OnLButtonDown(nFlags, point);
}void CMyStatic::OnLButtonUp(UINT nFlags, CPoint point) 
{
// TODO: Add your message handler code here and/or call default
m_mouseupx=point.x;
m_mouseupy=point.y;
CStatic::OnLButtonUp(nFlags, point);
}void CMyStatic::OnMouseMove(UINT nFlags, CPoint point) 
{
// TODO: Add your message handler code here and/or call default
m_mouseupx=point.x;
m_mouseupy=point.y;
CStatic::OnMouseMove(nFlags, point);
}
Onpaint(0函数里面:dc.StretchBlt(0  ,0 ,rect.Width()-(m_mousemovex-m_mousedownx),rect.Height()-(m_mousemovey-m_mousedowny) ,&MemDC,0,0,rect.Width(),rect.Height() ,SRCCOPY);问题在哪里?

解决方案 »

  1.   

    void CMyStatic::OnLButtonUp(UINT nFlags, CPoint point) 
    {
        // TODO: Add your message handler code here and/or call default
        m_mouseupx=point.x;
        m_mouseupy=point.y;
        Invalidate();//加上
        CStatic::OnLButtonUp(nFlags, point);
    }
      

  2.   

    如果换成
    dc.StretchBlt(0  ,0 ,rect.Width()-10,rect.Height()-10 ,&MemDC,0,0,rect.Width(),rect.Height() ,SRCCOPY);
    倒是有些反应
      

  3.   

    你在OnMouseMove里面赋值的不对,应该是对m_mousemovex和m_mousemovey赋值,再一个应该加上更新绘图的函数Invalidate();void CMyStatic::OnMouseMove(UINT nFlags, CPoint point) 
    {
        // TODO: Add your message handler code here and/or call default
        m_mousemovex=point.x;
        m_mousemovey=point.y;
        Invalidate();//加上
        CStatic::OnMouseMove(nFlags, point);
    }
      

  4.   

    对不起,那个地方没看清,不过还是不行。
    void CMyStatic::OnMouseMove(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    m_mousemovex=point.x;
    m_mousemovey=point.y;
    //m_addx=m_mousemovex-m_mousedownx;
    //m_addy=m_mousemovey-m_mousedowny;
    Invalidate();//加上
    CStatic::OnMouseMove(nFlags, point);
    }
      

  5.   

    为什么我把这句
    dc.StretchBlt(0  ,0 ,rect.Width()-(m_mousemovex-m_mousedownx),rect.Height()-(m_mousemovey-m_mousedowny) ,&MemDC,0,0,rect.Width(),rect.Height() ,SRCCOPY);
    改成
    dc.StretchBlt(0  ,0 ,rect.Width()-m_addx,rect.Height()-m_addy ,&MemDC,0,0,rect.Width(),rect.Height() ,SRCCOPY);
    图像就没有了呢?
    其中初始值:
    m_addx=10;m_addy=10;
    在onmousemove()里面赋值:
    m_addx=m_mousemovex-m_mousedownx;
    m_addy=m_mousemovey-m_mousedowny;
      

  6.   

    试试重载一下WM_ERASEBKGND消息,使用默认的刷子来填充整个客户区。
      

  7.   

    BOOL CMyStatic::OnEraseBkgnd(CDC* pDC) 
    {
    // TODO: Add your message handler code here and/or call default
    CRect   rect; 
    GetWindowRect(&rect); 
    pDC->FillSolidRect(0,0,rect.Width(),rect.Height(),RGB(255,255,255));
    return CStatic::OnEraseBkgnd(pDC);
    }
    这样可以吗?可是整个区域都变成白色了,图像没有了,怎么办?
      

  8.   

    BOOL CMyStatic::OnEraseBkgnd(CDC* pDC) 
    {
    CRect rcClient;
    GetClientRect(rcClient);
    pDC->FillSolidRect(rcClient, m_crBkgnd); return TRUE;
    }
      

  9.   

    m_crBkgnd是定义的颜色吗?还是没有用
    我把整个程序都贴出来:
    void CMyStatic::OnPaint() 
    {
    CNetWatcherViewerView *pView=(CNetWatcherViewerView *)((CMainFrame *)AfxGetMainWnd())->GetActiveView() ;
    CPaintDC dc(this); // device context for painting
    CNetWatcherViewerDoc* pDoc = (CNetWatcherViewerDoc*)((CView*)GetParent())->GetDocument();
        if( pDoc->m_bRecvFlag){
    DrawCurve(dc);
    }
    } void CMyStatic::DrawCurve(CPaintDC& dc)
    { CNetWatcherViewerDoc* pDoc = (CNetWatcherViewerDoc*)((CView*)GetParent())->GetDocument();
    CNetWatcherViewerView *pView=(CNetWatcherViewerView *)((CMainFrame *)AfxGetMainWnd())->GetActiveView() ;
        int tmpx,tmpy,tmp1,tmp2;
    double tmpfft;
    UINT i;
    CString ctrText;
    int ptr1=0,ptr2=0,ptr3=0,ptr4=0,ptr5=0,ptr6=0,ptr7=0,ptr8=0;
    CDC MemDC;
    CBitmap MemBitmap;
    MemDC.CreateCompatibleDC(&dc);
    //建立一个与屏幕显示兼容的位图
        CRect   rect; 
        GetWindowRect(&rect); 
    //this->GetParent() ->GetDocument();
    //MemBitmap.CreateCompatibleBitmap(&dc,300,300);
    MemBitmap.CreateCompatibleBitmap(&dc,rect.Width (),rect.Height ());
    //将位图选入到内存显示设备中
    CBitmap *pOldBit=MemDC.SelectObject(&MemBitmap);
    CPen newPen(PS_ENDCAP_ROUND , 1, RGB(0,78,115));
    CPen newPen0(PS_DOT  , 1, RGB(0,78,115)); CPen* pOldPen = MemDC.SelectObject(&newPen);
    //绘图
    MemDC.FillSolidRect(0,0,rect.Width(),rect.Height(),RGB(230,230,230));
    MemDC.SetTextColor(RGB(0,78,115));
    MemDC.SetBkMode(TRANSPARENT); ///字体
    ////////////////////
        LOGFONT lf;
        MemDC.GetCurrentFont()->GetLogFont(&lf);
        
    MemDC.MoveTo(80,0);//纵坐标
    MemDC.LineTo(80, rect.Height());
        if((m_channel1_button==TRUE)||(m_channel2_button==TRUE)||(m_channel3_button==TRUE)||(m_channel4_button==TRUE)||(m_channel5_button==TRUE)||(m_channel6_button==TRUE)||(m_channel7_button==TRUE)||(m_channel8_button==TRUE))//点击之后增加坐标
    {
         for (i=0;i<4;i++)//坐标轴上部分
    {
         MemDC.MoveTo(80,10+(rect.Height()-20)*i/8);
         ctrText.Format("%d", 1048576*(4-i));
         MemDC.TextOut(28,5+(rect.Height()-20)*i/8,ctrText);
             MemDC.LineTo(85,10+(rect.Height()-20)*i/8);
    }        ctrText.Format("%d", 0);//原点
        MemDC.TextOut(70,5+(rect.Height()-20)*i/8,ctrText); for (i=5;i<9;i++)//坐标轴下部分
    {
         MemDC.MoveTo(80,10+(rect.Height()-20)*i/8);
         ctrText.Format("%d", 1048576*(4-i));
         MemDC.TextOut(20,5+(rect.Height()-20)*i/8,ctrText);
             MemDC.LineTo(85,10+(rect.Height()-20)*i/8);
    }
    for(i=1;i<8;i++)
    { MemDC.MoveTo(80+(rect.Width()-80)*i/8,rect.Height()/2);
    ctrText.Format("%d", 2048*i);
    MemDC.TextOut(62+(rect.Width()-80)*i/8, rect.Height()/2, ctrText);
    MemDC.LineTo(80+(rect.Width()-80)*i/8,rect.Height()/2-4);

    }
    } MemDC.SelectObject(newPen0);///////////通道
        ctrText.Format("通道%d",m_uiChannelIndex);
        MemDC.TextOut(20,rect.Height ()/2-6, ctrText);
    MemDC.SelectObject(newPen);////////横坐标
    MemDC.MoveTo(80,rect.Height ()/2);
    MemDC.LineTo (rect.Width(),rect.Height()/2);    /////////////////////画图
    //m_uiShowChannelID=channelIndex;
    switch(m_uiChannelIndex)
    {
    case 1:
    if(pView->m_uiShowChannelID[0]==1)
    {
    {
         pOldPen = MemDC.SelectObject(&newPen1);
         if(pDoc->m_uiShowType[pView->m_uiShowChannelID[0]-1]==1)
    {
         MemDC.MoveTo(80,rect.Height()/2);
         ptr1 = 0;
         for(i=0;i<pDoc->m_iOrgDatalen[pView->m_uiShowChannelID[0]-1];i++)
    {
         ptr1++;
         tmpx = (ptr1*(rect.Width()-80)/(pDoc->m_iOrgDatalen[pView->m_uiShowChannelID[0]-1])) + 80;//2304
                            tmpy = rect.Height() - ((int)((float)pChannel1_Buf[i]*256.0*rect.Height()/9437184.0)+rect.Height()/2);//36864
            MemDC.LineTo(tmpx,tmpy);
    }

    }
             else
    {
         MemDC.MoveTo(80,rect.Height()/2);
         ptr1 = 0;
         for(i=0;i<pDoc->m_iOrgDatalen[pView->m_uiShowChannelID[0]-1];i+=2)
    {
         ptr1++;
         tmpx = (ptr1*(rect.Width()-80)/(pDoc->m_iOrgDatalen[pView->m_uiShowChannelID[0]-1])) + 80;//2304
         tmpfft = sqrt((double)pChannel1_Buf[i]*(double)pChannel1_Buf[i] + (double)pChannel1_Buf[i+1]*(double)pChannel1_Buf[i+1])/pDoc->m_iOrgDatalen[pView->m_uiShowChannelID[0]-1]*256;
         tmpy = rect.Height() - ((int)(tmpfft*256*(rect.Height())/9437184.0) + rect.Height()/2);//36864
         //MemDC.MoveTo(tmpx,m_iClientH-100);
         MemDC.LineTo(tmpx,tmpy);
    }
    }
    }
    }
        break;
    /////////////////////剩下的是2-8//////////////////////////////////
     
    //dc.BitBlt(0  ,0 ,rect.Width(),rect.Height() ,&MemDC,0,0,SRCCOPY);
    dc.StretchBlt(0  ,0 ,rect.Width()-m_addx,rect.Height()-m_addy,&MemDC,0,0,rect.Width(),rect.Height() ,SRCCOPY);
    MemDC.SelectObject(pOldPen);
    MemBitmap.DeleteObject();
    MemDC.DeleteDC();
    }void CMyStatic::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    m_mousedownx=point.x;
    m_mousedowny=point.y;
    //Invalidate();//加上
    CStatic::OnLButtonDown(nFlags, point);
    }void CMyStatic::OnLButtonUp(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    m_mouseupx=point.x;
    m_mouseupy=point.y;
    Invalidate();//加上 
    CStatic::OnLButtonUp(nFlags, point);
    }void CMyStatic::OnMouseMove(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    m_mousemovex=point.x;
    m_mousemovey=point.y;
    m_addx=m_mousemovex-m_mousedownx;
    m_addy=m_mousemovey-m_mousedowny;
    Invalidate();//加上
    CStatic::OnMouseMove(nFlags, point);
    }BOOL CMyStatic::OnEraseBkgnd(CDC* pDC) 
    {
    // TODO: Add your message handler code here and/or call default
    CRect   rect; 
    GetWindowRect(rect); 
    pDC->FillSolidRect(rect,RGB(255,255,255));
    //return TRUE;
    return FALSE;
    //return CStatic::OnEraseBkgnd(pDC);
    }
      

  10.   

    填充客户区,而不是整个窗口. CRect rcClient; 
    GetClientRect(rcClient); //不是GetWindowRect(rect); 
    m_crBkgnd是颜色定义,可以直接使用白色: RGB(255, 255, 255)最后要返回TRUE.BOOL CMyStatic::OnEraseBkgnd(CDC* pDC) 

    CRect rcClient; 
    GetClientRect(rcClient); 
    pDC->FillSolidRect(rcClient, RGB(255, 255, 255)); return TRUE; 
    }
      

  11.   

    先试试删除:
    void CMyStatic::OnLButtonDown(UINT nFlags, CPoint point) 
    void CMyStatic::OnLButtonUp(UINT nFlags, CPoint point) 
    void CMyStatic::OnMouseMove(UINT nFlags, CPoint point) 
    这些三个函数,看看图像是否可以显示出来.
      

  12.   

    dc.StretchBlt(0  ,0 ,rect.Width()-m_addx,rect.Height()-m_addy,&MemDC,0,0,rect.Width(),rect.Height() ,SRCCOPY);
    把这句改成
    dc.StretchBlt(0  ,0 ,rect.Width(),rect.Height(),&MemDC,0,0,rect.Width(),rect.Height() ,SRCCOPY);
    就可以
      

  13.   

    确实不太明白,你可以看看我的一个进度条控件的代码:void CProgressEx::OnPaint() 
    {
    CPaintDC dc(this);    CRect rcErase, rcClient;
    int nLower, nUpper, nPos;
    CBitmap bmNew, *pbmOld = NULL;
    CDC memdc;
    double dbFinish; //使用内存DC缓冲所绘制的图像。
    if (!memdc.CreateCompatibleDC(&dc))
    return;
        GetClientRect(rcClient);
    bmNew.CreateCompatibleBitmap(&dc, rcClient.Width(), rcClient.Height());
    pbmOld = memdc.SelectObject(&bmNew);     ........省略一些无关的代码..........
    //先使用渐变色填充整个客户区域,然后使用背景色填充要擦除的区域。
    GradientFillRect(&memdc, rcClient);
    memdc.FillSolidRect(rcErase, m_crBkgnd); //将内存DC中的图象复制进度条控件中。
    dc.BitBlt(rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), &memdc, rcClient.left, rcClient.top, SRCCOPY);
    memdc.SelectObject(pbmOld);
    }BOOL CProgressEx::OnEraseBkgnd(CDC* pDC) 
    {
    CRect rcClient;
    GetClientRect(rcClient);
    pDC->FillSolidRect(rcClient, m_crBkgnd); return TRUE;
    }
      

  14.   

    现在我删掉了
    void CMyStatic::OnLButtonDown(UINT nFlags, CPoint point) 
    void CMyStatic::OnLButtonUp(UINT nFlags, CPoint point) 
    void CMyStatic::OnMouseMove(UINT nFlags, CPoint point) 
    然后设定初始值:
    m_addx=10;m_addy=10;
    然后测试发现:
    情况(1):
    dc.StretchBlt(0  ,0 ,rect.Width(),rect.Height(),&MemDC,0,0,rect.Width(),rect.Height() ,SRCCOPY);
    图像可以正常显示。
    情况(2):
    dc.StretchBlt(0  ,0 ,rect.Width()-10,rect.Height()-10,&MemDC,0,0,rect.Width(),rect.Height() ,SRCCOPY);
    图像也可以正常显示。
    情况(3):
    dc.StretchBlt(0  ,0 ,rect.Width()-m_addx,rect.Height(),&MemDC,0,0,rect.Width(),rect.Height() ,SRCCOPY);
    图像可以也正常显示。
    情况(4):
    dc.StretchBlt(0  ,0 ,rect.Width,rect.Height()-m_addy,&MemDC,0,0,rect.Width(),rect.Height() ,SRCCOPY);
    图像可以就不能正常显示了,图像没有了。
    真的是好奇怪啊?
      

  15.   

    你确定没有其它的地方修改了m_addy的值?是这是代码这里错了:rect.Width => rect.Width()?请将工程ReBuild一下(不是仅仅使用F7编译)。
      

  16.   

    上面那个是粘贴的时候的粘错了,应该是rect.Width()。但是问题也不是这里,我用搜索搜了一下,没有在什么地方修改m_addy的值!Build是F7,那ReBuild是那个键?
      

  17.   

    “编译”菜单中的"Rebuild All"。
      

  18.   

    我的是VC6,你的版本是?
    要不你先关闭工程,然后删除工程“Debug”子目录下的所有文件,再按F7键也能重新编译。还可以作以下尝试:
    int nTemp = m_addy; <-在这里断点,查看nTemp的值是否为10。
    //int nTemp = 10;dc.StretchBlt(0  ,0 ,rect.Width(),rect.Height()- nTemp,&MemDC,0,0,rect.Width(),rect.Height() ,SRCCOPY);
      

  19.   

    多谢你的提醒,现在图像能够显示了。
    我又把mousedown ,mouseup,mousemove 加上了,但是无论怎么鼠标拖动图像就是没反应?
      

  20.   

    我通过设置断点发现,程序根本就没有执行到mousedown(),mouseup(),mousemove()!!!
    我猜想原因是不是:我是在重载的CMyStatic类中使用的mousedown(),mouseup(),mousemove()这几个函数,并且如果在视图里面这几个函数是可以的,所以我怀疑是不是这里出了问题呢?谢谢
      

  21.   

    这几个消息应该是运行的,或许你到Google上找一下“CStaticLink”类,
    它是使用CStatic控件来实现超级链接的功能。
      

  22.   

    我只是想说CStaticLink也有重载相关的消息,这三个函数应该可以运行的,或许你看看这个类后可以从中找到一些解决方法:
    http://www.codeguru.com/forum/archive/index.php/t-163600.html//这行会将图像向下移,而不是缩小。
    dc.StretchBlt(0  ,0 ,rect.Width()-m_addx,rect.Height()-m_addy,&MemDC,0,0,rect.Width(),rect.Height() ,SRCCOPY);或许试试直接将图像填充整个控件,然后改变的是控件的大小。
      

  23.   

    还是这个CStaticLink类,查看这篇文章: 
    http://dev.yesky.com/110/2226610_1.shtml 从这篇文章中,我发现你可以要重载这个: 
    UINT CStaticLink::OnNcHitTest(CPoint point) 

     return HTCLIENT;