CBitmap m_bmp; HBITMAP hBitmap5; hBitmap5 = (HBITMAP)::LoadImage( NULL, "res//0x00304EE6.bmp", // 图片全路径 IMAGE_BITMAP, // 图片格式 0,0, LR_LOADFROMFILE|LR_CREATEDIBSECTION); // 注意LR_LOADFROMFILE //获取加载的位图信息 m_bmp.Attach(hBitmap5); DIBSECTION ds; BITMAPINFOHEADER &bminfo = ds.dsBmih; m_bmp.GetObject(sizeof(ds),&ds); int cx = bminfo.biWidth; //获取图像宽度 int cy = bminfo.biHeight; //获取图像高度 //调整图像大小符合空间要求,使得其正好显示一张图片 CRect rect; GetDlgItem(IDC_STATIC_1)->GetWindowRect(&rect); ScreenToClient(&rect); GetDlgItem(IDC_STATIC_1)->MoveWindow(rect.left,rect.top,cx,cy,true); //调整大小 CPaintDC dc2(GetDlgItem(IDD_VINCENT1)); CRect rcclient; GetDlgItem(IDC_STATIC_1)->GetClientRect(&rcclient); CDC memdc; memdc.CreateCompatibleDC(&dc2); CBitmap bitmap; bitmap.CreateCompatibleBitmap(&dc2,rcclient.Width(),rcclient.Height()); memdc.SelectObject(&bitmap); CWnd::DefWindowProc(WM_PAINT,(WPARAM)memdc.m_hDC,0); CDC maskdc; maskdc.CreateCompatibleDC(&dc2); CBitmap maskbitmap; maskbitmap.CreateBitmap(rcclient.Width(),rcclient.Height(),1,1,NULL); maskdc.SelectObject(&maskbitmap); maskdc.BitBlt(0,0,rcclient.Width(),rcclient.Height(),&memdc,rcclient.left,rcclient.top,SRCCOPY); CBrush brush; brush.CreatePatternBrush(&m_bmp); dc2.FillRect(rcclient,&brush); dc2.BitBlt(rcclient.left,rcclient.top,rcclient.Width(),rcclient.Height(),&memdc,rcclient.left,rcclient.top,SRCPAINT);