方法一:
1. 为Picture 控件添加一个控件变量m_cPicture;
2. 在OnInitDialog 函数中添加:
BOOL CDialogJog::OnInitDialog() { HBITMAP hbmp; hbmp = (HBITMAP)LoadImage(AfxGetInstanceHandle(),_T("jog.bmp"),IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); //设置静态控件的样式,使其可以使用位图,并试位标显示使居中 m_cPicture.ModifyStyle(0xF,SS_BITMAP|SS_CENTERIMAGE); m_cPicture.SetBitmap((HBITMAP)hbmp); }
方法二:
不为Picture 控件添加控件变量:
BOOL CLoginDog::OnInitDialog() { CDialog::OnInitDialog(); //添加登陆窗口中的图片 HBITMAP hBitmap; //关联图片ID hBitmap =(HBITMAP)LoadImage(AfxGetInstanceHandle(), _T("jog.bmp"), IMAGE_BITMAP,0,0, LR_LOADMAP3DCOLORS); //获得指向静态控件的指针 CStatic *pStatic=(CStatic *)GetDlgItem(IDC_STATIC_PIC);//控件ID //设置静态控件的样式,使其可以使用位图,并试位标显示使居中 pStatic->ModifyStyle(0xF,SS_BITMAP|SS_CENTERIMAGE); //设置静态控件显示位图 pStatic->SetBitmap(hBitmap); return TRUE; }
参考:http://www.mamicode.com/info-detail-350138.html