对话框重绘失败

qinqinhao 2008-05-14 11:31:03
在Onpaint中调用

CWnd *pWnd;
pWnd = GetDlgItem(IDC_Img);
ShowBitmap(pWnd);

然后再ShowBitmap中填充Img区域,再拷贝一个位图,但是位图重绘有问题。
另外,怎么得到对话框的hInstance来load位图,可以这么用吗?
hBmp=LoadBitmap(theApp.m_hInstance,"MyBitmap");


BOOL ShowBitmap::ShowBitmap(CWnd *pWnd)
{
HANDLE hBmp;
HDC hBitmapDC;
HDC hMemDC;
PAINTSTRUCT PtrStr;
int bitmapWidth=266;
int bitmapHeight=64;
HGDIOBJ prevObject;
HBRUSH fill;
HDC hdcRect;

CRect rect;

pWnd->GetClientRect(&rect);

hdcRect=::GetDC(pWnd->m_hWnd);
fill=CreateSolidBrush(0xFFFFFF); // Select white brush
prevObject=SelectObject(hdcRect,fill);
FillRect(hdcRect,&rect,fill); // Paint white rect
SelectObject(hdcRect,prevObject);
DeleteObject(fill);
::ReleaseDC(pWnd->m_hWnd,hdcRect);

hBmp=LoadBitmap(theApp.m_hInstance,"MyBitmap");
hBitmapDC=::BeginPaint(pWnd->m_hWnd,&PtrStr);
hMemDC=CreateCompatibleDC(hBitmapDC);
SelectObject(hMemDC,hBmp);

//Place Bitmap in center of paint area
BitBlt(hBitmapDC,
rect.left, // x
rect.top, // y
bitmapWidth, // width
bitmapHeight, // height
hMemDC,0,0,SRCCOPY);
DeleteDC(hMemDC);
::EndPaint(pWnd->m_hWnd,&PtrStr);

return true;
}
...全文
61 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
cnzdgs 2008-05-14
  • 打赏
  • 举报
回复
hBmp=LoadBitmap(theApp.m_hInstance,"MyBitmap");这样就可以,有什么问题?
用BeginPaint得到的DC,不需要再GetDC;重绘时要根据PAINTSTRUCT中的参数,不要一律重绘,也不需要每次都Load位图。
快乐鹦鹉 2008-05-14
  • 打赏
  • 举报
回复
LoadBitmap(::AfxGetInstanceHandle(),"MyBitmap");
疯石头 2008-05-14
  • 打赏
  • 举报
回复
帮顶。。。

15,979

社区成员

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

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