Thread: Using BitBlt

  1. #1
    Programmer Frantic-'s Avatar
    Join Date
    Dec 2004

    Using BitBlt

    I read up on this at MSDN and im confused about how to use it. Ive gotten every other function I need to get a bitmap on the screen accept this one. Can you please explain to me how to use it?

    BOOL BitBlt(
      HDC hdcDest, // handle to destination DC
      int nXDest,  // x-coord of destination upper-left corner
      int nYDest,  // y-coord of destination upper-left corner
      int nWidth,  // width of destination rectangle
      int nHeight, // height of destination rectangle
      HDC hdcSrc,  // handle to source DC
      int nXSrc,   // x-coordinate of source upper-left corner
      int nYSrc,   // y-coordinate of source upper-left corner
      DWORD dwRop  // raster operation code

  2. #2
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    First off, BitBlt is simply a block transfer, you are simply copying a hunk of data from one area to another area, so if (simplifying device contexts) hdcSrc is a bitmap and hdcDest is a window, you copy your bitmap to your window.

    hdcDest is where you want your bitmap to be drawn, for example on a window:
    HDC hdc = GetDC ( hWnd ) ;
    ReleaseDC ( hWnd, hdc ) ;

    nXDest and nYDest is where on hdc you want your bitmap to be drawn, x and y (in pixels) with the topleft as the origin.

    nWidth and nHeight are how wide and high you want your bitmap to be when drawn onto hdc, these will be your bitmap's width and height values.

    hdcSrc is a dc for the bitmap you want to draw, for example:
    HDC hdcMem = CreateCompatibleDC ( hdc );
    HBITMAP hbmOld = SelectObject ( hdcMem, hTheBitmap );

    nXSrc and nYSrc are the topleft x and y on hdcSrc you want to copy from to hdcDest, these will be 0 (assuming you want your whole image).

    dwRop is kind of what you want to happen. For example you can or pictures and and pictures together, you probably want SRCCOPY, this simply copies hdcSrc to hdcDest.

  3. #3
    Programmer Frantic-'s Avatar
    Join Date
    Dec 2004
    Ok im still a bit confused on the hdcSrc

    HBITMAP hmainbg = LoadBitmap(hmaininstance,"test.bmp");
    HDC hmaindc = GetDC(hmainwnd);

  4. #4

  5. #5
    in case you need more speed (for animations or if the user
    is allowed to zoom in realtime) use DrawDibDraw instead:

    BOOL DrawDibDraw(
      HDRAWDIB hdd,             
      HDC hdc,                  
      int xDst,                 
      int yDst,                 
      int dxDst,                
      int dyDst,                
      LPVOID lpBits,            
      int xSrc,                 
      int ySrc,                 
      int dxSrc,                
      int dySrc,                
      UINT wFlags               
    this function belongs to Video for Windows.
    all you got to do is change your bitmap data from top-down-RGB
    to bottom-up-BGR and add the DrawDibOpen and DrawDibClose calls.

    example wndproc could look like this:

    hdib = DrawDibOpen();
    HDC hdc = GetDC( hwnd );
    DrawDibDraw( hdib, hdc, ... );
    ReleaseDC( hwnd, hdc );
    DrawDibClose( hdib );

    DrawDib at MSDN:

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BitBlt()
    By Gordon in forum Windows Programming
    Replies: 2
    Last Post: 05-29-2008, 01:38 AM
  2. Which BitBlt Raster Op?
    By SMurf in forum Windows Programming
    Replies: 1
    Last Post: 03-01-2006, 01:52 PM
  3. another BitBlt question..
    By btq in forum Windows Programming
    Replies: 6
    Last Post: 10-11-2002, 05:28 PM
  4. bitblt
    By canine in forum Windows Programming
    Replies: 3
    Last Post: 07-10-2002, 01:17 AM
  5. Problems with BitBlt
    By Isometric in forum Windows Programming
    Replies: 6
    Last Post: 02-05-2002, 09:20 PM
Website Security Test