README.md

December 5, 2022 ยท View on GitHub

Load a BMP from a file

Description

This is a simple, easy to use function that shows how to load a bitmap from a file then bitblit it to a window.

More Info

Submitted On
ByJay
LevelBeginner
User Rating4.2 (25 globes from 6 users)
CompatibilityC++ (general), Microsoft Visual C++
CategoryGraphics/ Sound
WorldC / C++
Archive File

Source Code

//load bmp
int LoadBitmapFile(char* FileName, int x, int y, HWND hwnd)
{
BITMAP bm;
HDC hdc = GetDC(hwnd);
BitHandle = (HBITMAP)LoadImage(NULL, FileName, IMAGE_BITMAP, 0,0, LR_LOADFROMFILE);
if(BitHandle == NULL)
{
MessageBox(0, "Error loading the specified bitmap", "Program Error!",
MB_ICONERROR | MB_SYSTEMMODAL | MB_OK);
}
HDC dc = CreateCompatibleDC(hdc);
SelectObject(dc, BitHandle);
GetObject(BitHandle, sizeof(BITMAP), &bm);
BitBlt(hdc, x, y, bm.bmWidth, bm.bmHeight, dc, 0,0, SRCCOPY);
ReleaseDC(hwnd, hdc);
return(0);
}
/* to load a bmp simple call the function as follows : LoadBitmapFile("bitmap.bmp",50,50,hwnd);
hope this helps */