HBITMAP谁用过

wawagua 2011-10-22 02:47:41
HBITMAP hBitmap = (HBITMAP)::LoadImage(NULL,lpszName,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
把hBitmap设为全局变量,在一个OPEN的按钮中打用上面一句打开,在OnPaint()里面用这个hBitmap来画图为什么画不出来
...全文
244 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
QQ515311445 2011-10-25
  • 打赏
  • 举报
回复
程序LoadImage一次之后,因为if ( !m_hBitmap )的判断导致以后都不会进入LoadImage,所以不会有图
鑫森淼焱垚 2011-10-24
  • 打赏
  • 举报
回复
或者点按钮后有没有触发OnPaint。
最有可能就是绘图部分代码问题
buyong 2011-10-24
  • 打赏
  • 举报
回复
你先看看LoadImage返回值对不对吧。
[Quote=引用 9 楼 wawagua 的回复:]
引用 5 楼 schlafenhamster 的回复:
在OnPaint()里面:
如果 m_hBitmap = NULL( 须初始化为NULL)
if ( !m_hBitmap ) /* HBITMAP */ m_hBitmap = (HBITMAP)::LoadImage(NULL,lpszName,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
else
{/……
[/Quote]
wawagua 2011-10-24
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 schlafenhamster 的回复:]
在OnPaint()里面:
如果 m_hBitmap = NULL( 须初始化为NULL)
if ( !m_hBitmap ) /* HBITMAP */ m_hBitmap = (HBITMAP)::LoadImage(NULL,lpszName,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
else
{// do others
}
[/Quote]
不是的,我是想用loadimage后把图放m_hBitmap里,弄成全局,不用每次都去打开图
schlafenhamster 2011-10-24
  • 打赏
  • 举报
回复
if ( !m_hBitmap )不是一次吗?
尘雨 2011-10-23
  • 打赏
  • 举报
回复
检查你用的哪个设备场景,去selectobject(hBitmap)。如果设备场景不对,或者没选进入,那么肯定不会画出来,
战在春秋 2011-10-23
  • 打赏
  • 举报
回复
类似这样的问题,最好是单步调试,最好先检查下LoadImage函数调用是否成功,可能是找不到图象文件的存放位置。
gameslq 2011-10-23
  • 打赏
  • 举报
回复
1。确定下LoadImage是否加载图片资源成功了
2。如果hBitmap 定义成全局的,它不会自动释放,除非程序结束
schlafenhamster 2011-10-23
  • 打赏
  • 举报
回复
在OnPaint()里面:
如果 m_hBitmap = NULL( 须初始化为NULL)
if ( !m_hBitmap ) /* HBITMAP */ m_hBitmap = (HBITMAP)::LoadImage(NULL,lpszName,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
else
{// do others
}
zhao1zhong6 2011-10-23
  • 打赏
  • 举报
回复
肯定不会释放,你先检查一下加载是否成功。
  • 打赏
  • 举报
回复
你的代码是怎么写的
wawagua 2011-10-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 shiliangsl0115 的回复:]
// load IDB_BITMAP1 from our resources
CBitmap bmp;
if (bmp.LoadBitmap(IDB_BITMAP1))
{
// Get the size of the bitmap
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);

// Create an in……
[/Quote]不是,我是问为什么在onpaint里打不开传进去的HBITMAP,画不了图,是不是他自动释放了
小石头0115 2011-10-22
  • 打赏
  • 举报
回复
// load IDB_BITMAP1 from our resources
CBitmap bmp;
if (bmp.LoadBitmap(IDB_BITMAP1))
{
// Get the size of the bitmap
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);

// Create an in-memory DC compatible with the
// display DC we're using to paint
CDC dcMemory;
dcMemory.CreateCompatibleDC(pDC);

// Select the bitmap into the in-memory DC
CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp);

// Find a centerpoint for the bitmap in the client area
CRect rect;
GetClientRect(&rect);
int nX = rect.left + (rect.Width() - bmpInfo.bmWidth) / 2;
int nY = rect.top + (rect.Height() - bmpInfo.bmHeight) / 2;

// Copy the bits from the in-memory DC into the on-
// screen DC to actually do the painting. Use the centerpoint
// we computed for the target offset.
pDC->BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory,
0, 0, SRCCOPY);

dcMemory.SelectObject(pOldBitmap);
}
else
TRACE0("ERROR: Where's IDB_BITMAP1?\n");


转化,你懂的
CBitmap::FromHandle

static CBitmap* PASCAL FromHandle( HBITMAP hBitmap );

19,468

社区成员

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

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