单文档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什么问题啊,怎样解决啊??
{
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什么问题啊,怎样解决啊??
int cx= "bminfo".biWidth;
int cy= "bminfo".biHeight;
改为:
m_bmp.GetObject( sizeof(ds), &ds );
int cx= ds.biWidth;
int cy= ds.biHeight;
怎么会用"bminfo"呢???
error C2039: 'biHeight' : is not a member of 'tagDIBSECTION'改后提示如上错误
int cy= ds.dsBm.bmHeight;
int cx= bminfo.biWidth;
int cy= bminfo.biHeight;
需要把12.bmp图片放到程序的文件夹中,我想使用LoatBitmap,直接从程序资源中加载位图。把上句改成HBITMAP hbmp = ::LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BITMAP1));
m_Picture.SetBitmap(hbmp); m_Picture是CStatic型的picture控件,type类型bitmap。为什么图片显示不出来呢?
m_Picture.SetBitmap(hbmp); 谢谢楼上各位!!