Results 1 to 9 of 9

Thread: refresh window

  1. #1

    Thread Starter
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802

    refresh window

    Hi!
    How do I refresh my window after I've bitblt:ed to it to show any changes I've made (i.e. moved a sprite)?

    Thanks in advance
    //Tobbe McCain
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    use a double buffer, do changes on the off screen dc, and then blit them altogether on the window
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    I do that allready. And I know that the void that does the drawing is called, the problem is that nothing is drawed to the window. I call the void in WM_PAINT and it works just fine, but when I try to call it in a while loop it just doesn't draw to the window...
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You don't use the same code to react to WM_PAINT and do any in-between drawing. For in-between drawing BeginPaint won't work.
    You should use GetDC instead.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    In WM_PAINT I have BeginPaint and then I have a function that does the drawing and then EndPaint. In my loop I just call the function that does the drawing. And I use GetDC in that function.
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Hmmm...

    Still sounds like a clipping area problem.
    Does the drawing function simply blit the back buffer to the screen or does it do anything else?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  7. #7

    Thread Starter
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    In WM_CREATE I have
    Code:
    g_hdc = GetDC(hwnd);
    GetClientRect(hwnd, &g_rcClient);
    And then I call
    Code:
    DrawBall(g_hdc, &g_rcClient);
    in my function that looks like:
    Code:
    void DrawBall(HDC hdc, RECT* prc)
    {
    	HDC hdcBuffer = CreateCompatibleDC(hdc);
    	HBITMAP hbmBuffer = CreateCompatibleBitmap(hdc, prc->right, prc->bottom);
    	HBITMAP hbmOldBuffer = (HBITMAP)SelectObject(hdcBuffer, hbmBuffer);
    
    	HDC hdcMem = CreateCompatibleDC(hdc);
    	HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, g_hbmMask);
    
    	FillRect(hdcBuffer, prc, (HBRUSH)GetStockObject(WHITE_BRUSH));
    
    	BitBlt(hdcBuffer, g_ballInfo.x, g_ballInfo.y, g_ballInfo.width, g_ballInfo.height, hdcMem, 0, 0, SRCAND);
    
    	SelectObject(hdcMem, g_hbmBall);
    	BitBlt(hdcBuffer, g_ballInfo.x, g_ballInfo.y, g_ballInfo.width, g_ballInfo.height, hdcMem, 0, 0, SRCPAINT);
    
    	BitBlt(hdc, 0, 0, prc->right, prc->bottom, hdcBuffer, 0, 0, SRCCOPY);
    	
    	//Clean up
    	SelectObject(hdcMem, hbmOld);
    	DeleteDC(hdc);
    
    	SelectObject(hdcBuffer, hbmOldBuffer);
    	DeleteDC(hdcBuffer);
    	DeleteObject(hbmBuffer);
    }
    I know it's not the fastest way to do it but it will have to do untill I get it working. I just copied the code from the tutorial over at www.winprog.net
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  8. #8
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Hmm...

    Looks ok. A few things:
    You should not take for granted that the client rect will range from (0,0) to (x,y), so to get the width and height you should calculate
    int width = prc->right - prc->left;
    int height = prc->bottom - prc->top;

    And are you sure you specified CS_OWNDC for the class style when registering the window class? If you want to store the HDC in a global variable you have to do that, else the handle will become invalid.

    You might also want to try doing a single blit instead of the mask blit, just to test if that causes the error (unlikely if it, as you said, works for WM_PAINT).
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  9. #9

    Thread Starter
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    Now it works, sort of...
    i added CS_OWNDC and in "//Clean up" I changed DeleteDC(hdc) to DeleteDC(hdcMem)... And this works. But now I've tried to move the code out of the function and just put it straight in to my code and I thought that it would be a mather of copy and paste with some small changes but as it turned out it wasn't... Now when I BitBlt my buffer to the screen my sprite that used to be multi-color is now all black, it looks as if I only BitBlt the mask... and I think that is what happens because if I comment out the line that SRCANDs the mask I just get a blank screen. What can cause this? If I SRCCOPY my sprite all I get is a black square...
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width