为什么在OnDraw()函数里BitBlt后没有效果?

xincheng2008 2009-07-25 09:31:45
代码如下:
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP1);

CDC dcC;
dcC.CreateCompatibleDC(pDC);

dcC.SelectObject(&bitmap);

CRect rect;
GetClientRect(&rect);
pDC->BitBlt(0,0,rect.Width(),rect.Height(),&dcC,0,0,SRCCOPY);
上述代码编译无错,但是运行后什么反映都没有,请问是怎么回事??我重新建立了一个工程,只将将代码拷贝过去,别的什么代码也不添加,运行后就可以显示,但是在我的程序中就不显示任何东西,请高手指教!
...全文
157 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
supconsupcon 2009-07-25
  • 打赏
  • 举报
回复
1 你的图片的高度真的是rect.Height()吗?宽度真的是rect.Width()吗?
2 如果你的图片和窗口大小不一致,那就用StretchBlt进行贴图,或者xSrc和ySrc传入图片的高度和宽度
BOOL BitBlt (
int x,
int y,
int nWidth,
int nHeight,
CDC* pSrcDC,
int xSrc,
int ySrc,
DWORD dwRop );
Parameters
x
The logical x-coordinate of the upper-left corner of the destination rectangle.
y
The logical y-coordinate of the upper-left corner of the destination rectangle.
nWidth
The width, in logical units, of the destination rectangle and source bitmap.
nHeight
The height, in logical units, of the destination rectangle and source bitmap.
pSrcDC
Pointer to a CDC object that identifies the device context from which the bitmap is copied. It must be NULL if dwRop specifies a raster operation that does not include a source.
xSrc
The logical x-coordinate of the upper-left corner of the source bitmap.
ySrc
The logical y-coordinate of the upper-left corner of the source bitmap.
dwRop
The raster operation to perform. Raster-operation codes define how the GDI combines colors in output operations that involve a brush, a possible source bitmap, and a destination bitmap.
3 请确认你的bitmap已经load成功了
快乐鹦鹉 2009-07-25
  • 打赏
  • 举报
回复
那你就比较你的工程和你说OK的另一个工程的区别吧。既然这段代码没有问题,那等于我们没有任何可判断的基础了。
xincheng2008 2009-07-25
  • 打赏
  • 举报
回复
ondraw中只有这几个代码了
快乐鹦鹉 2009-07-25
  • 打赏
  • 举报
回复
不知道你的程序还干了些其它什么事啊。OnDraw中还有其它内容么?
beautyloveme 2009-07-25
  • 打赏
  • 举报
回复
加个断点,看看是不是根本没有调用OnDraw,如果没有调用肯定是你程序其它的地方作了处理了。
jiajia876 2009-07-25
  • 打赏
  • 举报
回复
OnDraw没有被调用,加个断点试试~
arong1234 2009-07-25
  • 打赏
  • 举报
回复
怀疑你的DC所对应的上下文根本没有无效区域,或者你的OnDraw根本没有被调用
你确信这段代码被调用了么?
不知道你是否需要看看这个先:
http://blog.vckbase.com/arong/archive/2005/02/28/3325.html
tiger波波 2009-07-25
  • 打赏
  • 举报
回复
Invalidate();

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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