picture控件中显示图片后,然后把程序最小化后再恢复显示,怎么图片不显示了,请问改怎么写啊,谢谢

lj1006 2008-06-11 04:54:33
void CView0::DrawUserPhoto(int x, int y, CDC *pDC)
{
if(!m_hPhotoBitmap) return;

HBITMAP OldBitmap;

CWnd *pWnd = GetDlgItem(IDC_PICTURE);
CRect rect;
pWnd->GetClientRect(&rect);
pDC = pWnd->GetDC();

CDC MemDC;



MemDC.CreateCompatibleDC(pDC);
OldBitmap=(HBITMAP)MemDC.SelectObject(m_hPhotoBitmap);



CBitmap bitmap;
BITMAP bmp;
bitmap.Attach(m_hPhotoBitmap);
bitmap.GetBitmap(&bmp);




pDC->StretchBlt(x,y,rect.Width(),rect.Height(),&MemDC,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);

MemDC.SelectObject(OldBitmap);

}

void CView0::OnPaint()
{
CPaintDC dc(this); // device context for painting

if (IsIconic())
{
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
//dc.DrawIcon(x, y, m_hIcon);
}
else
{
CWnd *pWnd = GetDlgItem(IDC_PICTURE);
CRect rect;
pWnd->GetClientRect(&rect);
DrawUserPhoto(rect.left,rect.top,&dc);
CView::OnPaint();
}
}

以上是图片显示代码,请问该怎么修改啊,谢谢
...全文
215 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lj1006 2008-06-12
  • 打赏
  • 举报
回复
解决了,谢谢各位
lj1006 2008-06-12
  • 打赏
  • 举报
回复
我发现是
CBitmap bitmap;
BITMAP bmp;
bitmap.Attach(a);
bitmap.GetBitmap(&bmp);

pDC->StretchBlt(x,y,rect.Width(),rect.Height(),&MemDC,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);//动态显示图片

这段代码出了问题,如果把这段代码换成
pDC->BitBlt(x,y,rect.Width(),rect.Height(),&MemDC,0,0,SRCCOPY);//静态显示图片

就没问题了,那么用StretchBlt该怎么写啊
lj1006 2008-06-12
  • 打赏
  • 举报
回复
我就是响应WM_PAINT消息来显示啊,我是从书上刚学着写的,不知道错在哪里了
cnzdgs 2008-06-11
  • 打赏
  • 举报
回复
响应WM_PAINT消息来显示,不然一刷新就没有了。
palmax 2008-06-11
  • 打赏
  • 举报
回复
楼主,你想做什么?
OnPaint函数里
DrawUserPhoto(rect.left,rect.top,&dc); 你已经把CDC指针传了进去,在DrawUserPhoto函数里,你又给pDC重新赋值:pDC = pWnd->GetDC(); 你到底是什么意思,看不懂!
lj1006 2008-06-11
  • 打赏
  • 举报
回复
那改怎么写啊,谢谢
闪破风浪 2008-06-11
  • 打赏
  • 举报
回复
刷新了没有重绘制。。。。。。

15,979

社区成员

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

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