Ein Bitmap in ein Konsolen-Fenster laden

Hier ein Beispiel wie man Bitmaps in ein Konsolen Fenster lädt. Für diesen Code muss die gdi32.lib gelinkt werden. Deshalb bei DEV-C++ unter dem Menüpunkt "Projekt Optionen"-->"Linker Optionen" das Wort "-lgdi32" (ohne "") eingeben. Für MSV C++ tut es auch die dritte Zeile.

#include <windows.h>
#include <stdio.h>
//#pragma comment(lib,"gdi32.lib")

int LoadBmp2Console(char *szBitmap, int PosX, int PosY)
{    
  HBITMAP hBitmap = (HBITMAP)LoadImage(NULL,szBitmap,
                     IMAGE_BITMAP,0,0,LR_LOADFROMFILE); 
  if (!hBitmap) return 1; 
  
  BITMAP bmp; 
  GetObject(hBitmap,sizeof(bmp),&bmp); 
  
  HWND hwnd = FindWindow("ConsoleWindowClass",NULL);
  if (!hwnd) return 2;
    
  HDC hDC = GetDC(hwnd);   
  if (!hDC) return 3; 
  
  HDC hBitmapDC = CreateCompatibleDC(hDC); 
  if (!hBitmapDC) return 4; 
  
  SelectObject(hBitmapDC,hBitmap); 
   
  BitBlt(hDC,PosX,PosY,bmp.bmHeight,bmp.bmWidth,hBitmapDC,0,0,SRCCOPY);  
   
  DeleteObject(hBitmap); 
  ReleaseDC(hwnd,hBitmapDC); 
  ReleaseDC(hwnd,hDC);

return 0;
}

int main() 
{     
  int Status = LoadBmp2Console("bitmap.bmp",10,10);
  if(Status!=0)printf("Fehler: %i",Status);  
   
  getchar();  
  return 0; 
}