VC對話框初始時,Picture Control顯示BMP圖片:
BOOL CLoginDog::OnInitDialog() { CDialog::OnInitDialog(); HBITMAP hBitmap; //添加登陸窗口中的圖片 //關聯圖片ID hBitmap =(HBITMAP)LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BITMAP_LOGIN_PIC), IMAGE_BITMAP,0,0, LR_LOADMAP3DCOLORS); CStatic *pStatic=(CStatic *)GetDlgItem(IDC_STATIC_PIC); //獲得指向靜態控件的指針 pStatic->ModifyStyle(0xF,SS_BITMAP|SS_CENTERIMAGE); //設置靜態控件的樣式,使其位圖 居中 pStatic->SetBitmap(hBitmap); //設置靜態控件顯示位圖 return TRUE; }
SetBitmap定義如下:
// uBmpResource:圖片ID; uCtrlResource: Picture控件 ID void SetBitmap(UINT uBmpResource, UINT uCtrlResource) { HBITMAP hBitmap; CStatic *pStatic = (CStatic *)GetDlgItem(uCtrlResource); hBitmap = (HBITMAP)LoadImage( AfxGetInstanceHandle(), MAKEINTRESOURCE(uBmpResource), IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS); pStatic->ModifyStyle(0xF, SS_BITMAP); pStatic->SetBitmap(hBitmap); }