EVC中picturebox绘图后刷新的问题,在VC6.0下没问题,EVC4.0下即使强制重绘也不显示,请各位大侠帮忙看看。

zhzhq800204 2008-05-27 03:16:26
软件通过串口读取数据,然后根据数据绘制图形。由于界面大小受限制,所以PictureBox有时会不显示,显示时就绘制图形。简单代码如下:

void CZongHeCeLiang::OnPaint()
{
CPaintDC cdc(this); // device context for painting
CPaintDC dc(&m_xlt);
CBrush* pNewBrush;
CBrush* pOldBrush;
CString strdy,strdl,strtemp;
float fltdy,fltdl,jiaodu1,jiaodu2,jiaodu3;
CPoint m_center;
BOOL m_paintyn;
pNewBrush=new CBrush;

CRect rect,rect2;
CWnd *m_pic=GetDlgItem(IDC_lbXLT);
m_pic->GetWindowRect(&rect);
m_left=0;
m_top=0;
m_height=rect.Height();
m_width=rect.Width();
m_right=rect.left+rect.Width();
m_bottom=rect.top+rect.Height();
m_center.x=(m_left+m_right)/2;
m_center.y=(m_top+m_height)/2;
m_center_x=m_center.x;
m_center_y=m_center.y;

if( pNewBrush->CreateSolidBrush( RGB(0,0,0)))
{
pOldBrush = dc.SelectObject( pNewBrush );
dc.Rectangle(m_left,m_top,m_right,m_bottom);
m_r=100;
dc.SelectObject( pOldBrush );
delete pNewBrush;
}//绘制背景,还有其他代码,由于较多就不写了,能说明问题就可以。

}

程序启动后绘制背景。

//显示picturebox控件

void CZongHeCeLiang::OnButton1()
{
// TODO: Add your control notification handler code here
m_xlt.ShowWindow(1);
}

//刷新,强制重绘
void CZongHeCeLiang::OnBtnRefresh()
{
Invalidate();
}

//隐藏picturebox控件

void CZongHeCeLiang::OnBtnEnd()
{
m_xlt.ShowWindow(0);
}

问题出在picturebox控件重新显示后,即使我强制重绘,picturebox上也没有图形。但是相同的代码在VC6.0里没有问题。请各位帮我看看哪里的问题???
...全文
248 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lenux 2008-05-28
  • 打赏
  • 举报
回复
RedrawWindow
用这个试试?
sunrain_hjb 2008-05-28
  • 打赏
  • 举报
回复
In Windows CE, you have to pass a valid RECT pointer in the lpRect parameter. Windows 98 and Windows NT invalidate and redraw the entire window if the lpRect parameter is set to NULL. This is not supported in Windows CE.

看看这个。
zhzhq800204 2008-05-28
  • 打赏
  • 举报
回复
谢谢楼上的两位,用sunrain_hjb的方法就可以了。但是我发现一个问题,这种方法中,窗体一直处于绘制状态。我理解的窗体只有发生变化时才会出现重绘,楼上的能解释下吗。谢谢。
sunrain_hjb 2008-05-28
  • 打赏
  • 举报
回复
GetDlgItem(IDC_STATIC_PIC)->InvalidateRect(FALSE);
GetDlgItem(IDC_STATIC_PIC)->GetParent()->RedrawWindow(NULL,NULL,RDW_UPDATENOW |RDW_ALLCHILDREN);

供参考~~~

19,502

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 嵌入开发(WinCE)
社区管理员
  • 嵌入开发(WinCE)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧