有两种方法:
1 静态加载,定义资源IDB_BITMAP1 BITMAP "相对路径"
2动态加载,用::LoadImage()API然后CBitmap::Attach()即可
LoadBitmap是从EXE、DLL文件中加载,不是从硬盘加载!
DrawPicture(hwnd)
{
PAINTSTRUCT ps;
HDC hdc;
HDC hdcmem;
HBITMAP hBm;
BITMAP bm;
//hBm=::LoadBitmap(NULL,"D:\\Test.bmp");
//hBm=::LoadBitmap(IDB_BITMAP1);
//hBm=::LoadBitmap("D:\\Test.bmp");
//HINSTANCE hInst=GetModuleHandle(this);
hBm = (HBITMAP)LoadImage(NULL,"d:\\Test.bmp",IMAGE_BITMAP,640,480,LR_LOADFROMFILE);
//hBm=::LoadBitmap(GetModuleHandle(this),MAKEINTRESOURCE(IDB_BITMAP1));
//获取位图尺寸
GetObject(hBm,sizeof(BITMAP),(LPVOID)&bm);
hdc=GetDC(hwnd);
hdcmem=CreateCompatibleDC(hdc);
ReleaseDC(hwnd,hdc);
hdc=BeginPaint(hwnd,&ps);
SelectObject(hdcmem,hBm); //将位图选入内存设备环境中
BitBlt(hdc,180,90,bm.bmWidth,bm.bmHeight,hdcmem,0,0,SRCCOPY);
EndPaint(hwnd,&ps);
DeleteObject(&hBm);
DeleteDC(hdcmem);
}