Thread: Using BitBlt

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

    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?

    Code:
    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
    Posts
    357
    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
    Posts
    114
    Ok im still a bit confused on the hdcSrc

    Code:
    HBITMAP hmainbg = LoadBitmap(hmaininstance,"test.bmp");
    HDC hmaindc = GetDC(hmainwnd);
    CreateCompatibleDC(hmaindc);
    SelectObject(hmaindc,hmainbg);
    BitBlt(hmaindc,0,0,325,300,hmaindc,0,0,SRCCOPY);

  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:

    Code:
    BOOL DrawDibDraw(
      HDRAWDIB hdd,             
      HDC hdc,                  
      int xDst,                 
      int yDst,                 
      int dxDst,                
      int dyDst,                
      LPBITMAPINFOHEADER lpbi,  
      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:


    WM_CREATE:
    Code:
    hdib = DrawDibOpen();
    WM_PAINT:
    Code:
    HDC hdc = GetDC( hwnd );
    DrawDibDraw( hdib, hdc, ... );
    ReleaseDC( hwnd, hdc );
    WM_DESTROY:
    Code:
    DrawDibClose( hdib );

    DrawDib at MSDN:
    http://msdn.microsoft.com/library/de...ng_drawdib.asp

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, 12: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, 04:28 PM
  4. bitblt
    By canine in forum Windows Programming
    Replies: 3
    Last Post: 07-10-2002, 12:17 AM
  5. Problems with BitBlt
    By Isometric in forum Windows Programming
    Replies: 6
    Last Post: 02-05-2002, 09:20 PM