问个MFC这中图形控件显示图片问题
来源:百度知道 编辑:UC知道 时间:2024/09/22 20:27:57
以下是我在OnInitDialog中的代码:IDB_BG1:图片资源ID
CStatic *pStatic = (CStatic *)GetDlgItem(IDC_PIC);
CRect rect;
pStatic->GetClientRect(&rect);
HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, "IDB_BG1", IMAGE_BITMAP, rect.right,
rect.bottom, LR_CREATEDIBSECTION);
pStatic->ModifyStyle(0xF, SS_BITMAP);
pStatic->SetBitmap(hBitmap);
UpdateData(false);
请教下,这样我用位图资源ID作为LoadImage第二个参数,为啥没有图片?
我从文件中加载图片是可以的:
HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, "bg1.bmp", IMAGE_BITMAP, rect.right, rect.bottom, LR_LOADFROMFILE|LR_CREATEDIBSECTION);
但是一定要pStatic->ModifyStyle(0xF, SS_BITMAP);
为啥这个函数一定要,没有这个的话不行?
哪位大哥能跟我说一下。。。。。。。。。。。。。。。。。。。。
CStatic *pStatic = (CStatic *)GetDlgItem(IDC_PIC);
CRect rect;
pStatic->GetClientRect(&rect);
HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, "IDB_BG1", IMAGE_BITMAP, rect.right,
rect.bottom, LR_CREATEDIBSECTION);
pStatic->ModifyStyle(0xF, SS_BITMAP);
pStatic->SetBitmap(hBitmap);
UpdateData(false);
请教下,这样我用位图资源ID作为LoadImage第二个参数,为啥没有图片?
我从文件中加载图片是可以的:
HBITMAP hBitmap = (HBITMAP)LoadImage(NULL, "bg1.bmp", IMAGE_BITMAP, rect.right, rect.bottom, LR_LOADFROMFILE|LR_CREATEDIBSECTION);
但是一定要pStatic->ModifyStyle(0xF, SS_BITMAP);
为啥这个函数一定要,没有这个的话不行?
哪位大哥能跟我说一下。。。。。。。。。。。。。。。。。。。。
第一个问题 MSDN
If the firstparameter is NULL and the last parameter omits the LR_LOADFROMFILE value。If the last parameter includes the LR_LOADFROMFILE value, lpszName is the name of the file that contains the image.
即为第一个参数是nULL时,第二个参数默认为载入的图像名而不是位图资源名
要使用位图资源可以将第一个参数设为AfxGetInstanceHandle()
第二个问题IDC_PIC是pictiure控件?
它默认的是是Frame类型,不显示图片