BITMAPINFOHEADER 的问题

x21iaomi 2012-12-20 02:39:56
单文档MFC页面上放置picture控件,动态加入图片,自动适应图片控件大小,初始化函数如下
BOOL pic::OnInitDialog() 
{
CDialog::OnInitDialog();
if( m_bmp.m_hObject != NULL )
m_bmp.DeleteObject();
HBITMAP hbmp = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),"c://12.bmp", IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_LOADFROMFILE);
if( hbmp == NULL )
return FALSE;
m_bmp.Attach( hbmp );
DIBSECTION ds;
BITMAPINFOHEADER &bminfo = ds.dsBmih;
m_bmp.GetObject( sizeof(ds), &ds );
int cx= "bminfo".biWidth;
int cy= "bminfo".biHeight;
CRect rect;
GetDlgItem(IDC_PICTURE)->GetWindowRect(&rect);
ScreenToClient(&rect);
GetDlgItem(IDC_PICTURE)->MoveWindow(rect.left,rect.top,cx,cy,true);
return TRUE; // return TRUE unless you set the focus to a control
}
,运行时,提示错误
error C2228: left of '.biWidth' must have class/struct/union type
error C2228: left of '.biHeight' must have class/struct/union type
什么问题啊,怎样解决啊??
...全文
403 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
x21iaomi 2012-12-20
  • 打赏
  • 举报
回复
问题解决,以下两句就可以实现
	HBITMAP hbmp=::LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BITMAP1));
	m_Picture.SetBitmap(hbmp); 
谢谢楼上各位!!
快乐鹦鹉 2012-12-20
  • 打赏
  • 举报
回复
你不会调试程序?
x21iaomi 2012-12-20
  • 打赏
  • 举报
回复
引用 11 楼 happyparrot 的回复:
你这样写后,看看hBmp是不是空的?
怎样看?运行时窗口上picture控件的地方什么都不显示
快乐鹦鹉 2012-12-20
  • 打赏
  • 举报
回复
你这样写后,看看hBmp是不是空的?
x21iaomi 2012-12-20
  • 打赏
  • 举报
回复
引用 6 楼 happyparrot 的回复:
看你的代码,改成这样也行: int cx= bminfo.biWidth; int cy= bminfo.biHeight;
大哥,帮人帮到底吧,代码中的这句
	HBITMAP hbmp = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),"12.bmp", IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_LOADFROMFILE);
需要把12.bmp图片放到程序的文件夹中,我想使用LoatBitmap,直接从程序资源中加载位图。把上句改成
HBITMAP hbmp = ::LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BITMAP1));
	m_Picture.SetBitmap(hbmp); 
m_Picture是CStatic型的picture控件,type类型bitmap。为什么图片显示不出来呢?
x21iaomi 2012-12-20
  • 打赏
  • 举报
回复
引用 7 楼 tiger9991 的回复:
你这代码是抄来的吧?? 怎么会出现双引号呢? 去掉双引号就可以了
嗯,程序中要用到,自己建个demo试验下。
x21iaomi 2012-12-20
  • 打赏
  • 举报
回复
引用 6 楼 happyparrot 的回复:
看你的代码,改成这样也行: int cx= bminfo.biWidth; int cy= bminfo.biHeight;
刚试了一下,去掉双引号就行了。int cy= ds.dsBm.bmHeight;这样的写法也行……
看不见的裂痕 2012-12-20
  • 打赏
  • 举报
回复
你这代码是抄来的吧?? 怎么会出现双引号呢? 去掉双引号就可以了
快乐鹦鹉 2012-12-20
  • 打赏
  • 举报
回复
看你的代码,改成这样也行: int cx= bminfo.biWidth; int cy= bminfo.biHeight;
快乐鹦鹉 2012-12-20
  • 打赏
  • 举报
回复
兄弟,看清楚一点,我写的是bmWidth,不是biWidth。唉。
x21iaomi 2012-12-20
  • 打赏
  • 举报
回复
引用 3 楼 happyparrot 的回复:
int cx= ds.dsBm.bmWidth; int cy= ds.dsBm.bmHeight;
error C2039: 'biWidth' : is not a member of 'tagBITMAP'
biHight也是类似的错误
快乐鹦鹉 2012-12-20
  • 打赏
  • 举报
回复
int cx= ds.dsBm.bmWidth; int cy= ds.dsBm.bmHeight;
x21iaomi 2012-12-20
  • 打赏
  • 举报
回复
引用 1 楼 happyparrot 的回复:
m_bmp.GetObject( sizeof(ds), &ds ); int cx= "bminfo".biWidth; int cy= "bminfo".biHeight; 改为: m_bmp.GetObject( sizeof(ds), &ds ); int cx= d……
error C2039: 'biWidth' : is not a member of 'tagDIBSECTION'
error C2039: 'biHeight' : is not a member of 'tagDIBSECTION'
改后提示如上错误
快乐鹦鹉 2012-12-20
  • 打赏
  • 举报
回复
m_bmp.GetObject( sizeof(ds), &ds ); int cx= "bminfo".biWidth; int cy= "bminfo".biHeight; 改为: m_bmp.GetObject( sizeof(ds), &ds ); int cx= ds.biWidth; int cy= ds.biHeight; 怎么会用"bminfo"呢???

15,976

社区成员

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

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