1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
bool makebitmap(LPCWSTR szFileName, HDC hWinDC, int bmposx, int bmposy, int sizex, int sizey)
{
HBITMAP hBitmap;
hBitmap = (HBITMAP)::LoadImage(NULL, szFileName, IMAGE_BITMAP, 0, 0,
LR_LOADFROMFILE);
if(hBitmap == NULL)
{
MessageBox(NULL, _T("Loadimage failed"), _T("Error"), MB_OK);
return FALSE;
}
HDC hLocalDC;
hLocalDC = CreateCompatibleDC(hWinDC);
if(hLocalDC == NULL)
{
MessageBox(NULL, _T("Device context creation failed"), _T("Error"), MB_OK);
return FALSE;
}
BITMAP qBitmap;
int iReturn = GetObject(reinterpret_cast<HGDIOBJ>(hBitmap), sizeof(BITMAP),
reinterpret_cast<LPVOID>(&qBitmap));
if (!iReturn)
{
MessageBox(NULL, _T("GetObject failed"), _T("Error"), MB_OK);
return FALSE;
}
HBITMAP hOldBmp = (HBITMAP)SelectObject(hLocalDC, hBitmap);
if(hOldBmp == NULL)
{
MessageBox(NULL, _T("Holdbmp failed"), _T("Error"), MB_OK);
return FALSE;
}
BOOL qRetBlit = BitBlt(hWinDC, bmposx, bmposy, qBitmap.bmWidth, qBitmap.bmHeight,
hLocalDC, 0, 0, SRCCOPY);
if (!qRetBlit)
{
MessageBox(NULL, _T("Blit failed"), _T("Error"), MB_OK);
return FALSE;
}
SelectObject (hLocalDC, hOldBmp);
DeleteDC(hLocalDC);
DeleteObject(hBitmap);
return TRUE;
}
| |