mfc位图显示问题,求教!

qq_36242660 2016-12-20 04:12:51
我在mfc单文档中,创建一个按钮控件与picture控件,通过按钮浏览本地图片,使图片可以在picture控件上显示,但是当窗口发生变化时,位图就不见了,在onpaint中进行重绘时不行,好像时先重绘了图片,然后在是控件,结果就把图片覆盖掉了,求帮忙,谢谢!
void CMyView::OnPaint() 
{CPaintDC dc(this);
CStatic *pstatic=(CStatic*)GetDlgItem(IDR_PICTURE);
CRect m_rect2;
pstatic->GetClientRect(&m_rect2);
StretchDIBits(pstatic->GetDC()->GetSafeHdc(),m_rect2.left,m_rect2.top,m_rect2.Width(),
m_rect2.Height(), 0,0,BitmapInfo.biWidth,BitmapInfo.biHeight,BmpData,bitmapinfo,DIB_RGB_COLORS,SRCCOPY);
...全文
177 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq_36242660 2016-12-22
  • 打赏
  • 举报
回复
[quote=引用 8 楼 schlafenhamster 的回复:] void CMyView::OnPaint() { CVew::OnPaint(); CStatic *pstatic=(CStatic*)GetDlgItem(IDR_PICTURE); pstatic->UpdateWindow(); CRect m_rect2; pstatic->GetClientRect(&m_rect2); CDC *pDC=pstatic->GetDC(); StretchDIBits(pDC()->GetSafeHdc(),m_rect2.left,m_rect2.top,m_rect2.Width(), m_rect2.Height(), 0,0,BitmapInfo.biWidth,BitmapInfo.biHeight,BmpData,bitmapinfo,DIB_RGB_COLORS,SRCCOPY); ReleaseDC(pDC);[/quotx 谢谢
schlafenhamster 2016-12-21
  • 打赏
  • 举报
回复
void CMyView::OnPaint() { CVew::OnPaint(); CStatic *pstatic=(CStatic*)GetDlgItem(IDR_PICTURE); pstatic->UpdateWindow(); CRect m_rect2; pstatic->GetClientRect(&m_rect2); CDC *pDC=pstatic->GetDC(); StretchDIBits(pDC()->GetSafeHdc(),m_rect2.left,m_rect2.top,m_rect2.Width(), m_rect2.Height(), 0,0,BitmapInfo.biWidth,BitmapInfo.biHeight,BmpData,bitmapinfo,DIB_RGB_COLORS,SRCCOPY); ReleaseDC(pDC);
Eleven 2016-12-21
  • 打赏
  • 举报
回复
引用 3 楼 qq_36242660 的回复:
picture是所创建的控件,怎么找他的onpaint呢,
picture关联一个CStatic的派生类对象,在该派生类添加处理WM_PAINT消息处理,在该OnPaint函数中绘制图形。
qq_36242660 2016-12-21
  • 打赏
  • 举报
回复
引用 5 楼 schlafenhamster 的回复:
不要 CPaintDC dc(this); 先调用 CVew::OnPaint();
如果不用他的话,窗口发生变化时,其他控件如按钮控件都会不见,位图是可以显示
schlafenhamster 2016-12-21
  • 打赏
  • 举报
回复
不要 CPaintDC dc(this); 先调用 CVew::OnPaint();
qq_36242660 2016-12-20
  • 打赏
  • 举报
回复
这个已经在onpaint重新调用了,但是好像是先重绘显示了位图,然后就显示控件,结果给覆盖掉了
qq_36242660 2016-12-20
  • 打赏
  • 举报
回复
picture是所创建的控件,怎么找他的onpaint呢,
Eleven 2016-12-20
  • 打赏
  • 举报
回复
重写CStatic类,添加WM_PAINT消息处理,在OnPaint函数中绘制图形。
mlqxj35674 2016-12-20
  • 打赏
  • 举报
回复
在picture控件上显示图片,自然应该在picture控件的onpain里绘图。你在主视图的onpain里往picture上绘,不合理

15,980

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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