BitBlt

This is a discussion on BitBlt within the Windows Programming forums, part of the Platform Specific Boards category; Hi This time I am trying to develop some little app. which is able to work a little with images ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    162

    BitBlt

    Hi
    This time I am trying to develop some little app. which is able to work a little with images mainly BMP format.

    Code:
    HDC hDC;
    HDC hOffScreenDC;
    PAINTSTRUCT ps;
    (object _pPic;)
    
    InvalidateRect(hWnd, NULL, TRUE);
    hDC = BeginPaint(hWnd, &ps);
    _pPic->Draw(hOffScreenDC);
    BitBlt(hDC, 0, 0, 640, 480, hOffScreenDC, 0, 0, SRCCOPY);
    EndPaint(hWnd, &ps);
    ReleaseDC(hWnd, hDC);
    I would like to avoid the annoying flashing the client rect while it is being redrawn when I for eg. move a bitmap.

    I saw a programme which used the BitBlt() and it worked without any problem... Mine code does not work, can you tell me why? The code is not correct is it?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It looks like you are redrawing it every time - that will make it flash.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    InvalidateRect() generates a WM_PAINT msg.

    BeginPaint() gets the invalid rect and HDC ect. It also makes the rect 'valid'.

    EndPaint() will clean up the DC, no need to ReleaseDC() it.

    The paint struct contains a RECT you can use to limit the area redrawn (will speed up the paint).

    Look at WM_ERASEBKGND (IIRC return non zero to show you have processed the msg and do ot want the background redrawn again). This will reduce flicker.


    So you can not call InvalidateRect() in a WM_PAINT (it will do nothing or create an infinte loop).

    When you want a paint (in response to some other message) use

    InvalidateRect()//set invalid rect, generate WM_PAINT msg
    UpdateWindow()//post WM_PAINT msg directly to the window/dialog callback (not OS message queue).
    Last edited by novacain; 10-04-2007 at 11:19 PM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    162
    So I modified a bit my previous code and it started to work...

    Code:
    hOffScreenDC = CreateCompatibleDC(GetDC(hWnd));
    hOffScreenBitmap = CreateCompatibleBitmap(GetDC(hWnd), x, y);
    SelectObject(hOffScreenDC, hOffScreenBitmap);
    HDC hDC = GetDC(hWnd);
    BitBlt(hDC, 0, 0, x y, hOffScreenDC, 0, 0, SRCCOPY);
    Of course this code does not come from only one function but the base of the redrawing is hidden in this code...

    Even thou thx for help

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21