我在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);问题在哪里?
{
// 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);问题在哪里?
解决方案 »
- winpcap + ppp
- UPD程序查错(我没找到问题,请高手帮忙)
- 大家给想个办法!?????
- 请问SetMapMode()在哪里做更好?它的有效区域是什么?
- 请问如何编程实现硬盘格式化
- 有没有做过截取网络数据包的程序高手,有钱赚!高手请进。
- 调用音频压缩(G729a.lib)时出错,请教?
- 请教VC++高手:如何做出像VC++中自定义加速键那样的程序,要求用户按下想定义的键,即在编辑框中显示其VIRTKEY或ASCII码
- 求助!(我想给出所有分,但系统不让!)
- 软件发布: 学籍管理系统 ,免费,欢迎指教 (vc )
- 请问在Visual Studio2005下开发MFC程序的时候,如何单元测试?
- BitSpirit 和 BitComet中的种子市场是什么原理啊
{
// TODO: Add your message handler code here and/or call default
m_mouseupx=point.x;
m_mouseupy=point.y;
Invalidate();//加上
CStatic::OnLButtonUp(nFlags, point);
}
dc.StretchBlt(0 ,0 ,rect.Width()-10,rect.Height()-10 ,&MemDC,0,0,rect.Width(),rect.Height() ,SRCCOPY);
倒是有些反应
{
// TODO: Add your message handler code here and/or call default
m_mousemovex=point.x;
m_mousemovey=point.y;
Invalidate();//加上
CStatic::OnMouseMove(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);
}
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;
{
// 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);
}
这样可以吗?可是整个区域都变成白色了,图像没有了,怎么办?
{
CRect rcClient;
GetClientRect(rcClient);
pDC->FillSolidRect(rcClient, m_crBkgnd); return TRUE;
}
我把整个程序都贴出来:
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);
}
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;
}
void CMyStatic::OnLButtonDown(UINT nFlags, CPoint point)
void CMyStatic::OnLButtonUp(UINT nFlags, CPoint point)
void CMyStatic::OnMouseMove(UINT nFlags, CPoint point)
这些三个函数,看看图像是否可以显示出来.
把这句改成
dc.StretchBlt(0 ,0 ,rect.Width(),rect.Height(),&MemDC,0,0,rect.Width(),rect.Height() ,SRCCOPY);
就可以
{
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;
}
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);
图像可以就不能正常显示了,图像没有了。
真的是好奇怪啊?
要不你先关闭工程,然后删除工程“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);
我又把mousedown ,mouseup,mousemove 加上了,但是无论怎么鼠标拖动图像就是没反应?
我猜想原因是不是:我是在重载的CMyStatic类中使用的mousedown(),mouseup(),mousemove()这几个函数,并且如果在视图里面这几个函数是可以的,所以我怀疑是不是这里出了问题呢?谢谢
它是使用CStatic控件来实现超级链接的功能。
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);或许试试直接将图像填充整个控件,然后改变的是控件的大小。
http://dev.yesky.com/110/2226610_1.shtml 从这篇文章中,我发现你可以要重载这个:
UINT CStaticLink::OnNcHitTest(CPoint point)
{
return HTCLIENT;
}