|
-
Nov 17th, 2002, 05:42 AM
#1
Thread Starter
Fanatic Member
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
-
Nov 17th, 2002, 09:31 AM
#2
transcendental analytic
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.
-
Nov 18th, 2002, 02:45 AM
#3
Thread Starter
Fanatic Member
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
-
Nov 18th, 2002, 05:44 AM
#4
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.
-
Nov 18th, 2002, 06:15 AM
#5
Thread Starter
Fanatic Member
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
-
Nov 18th, 2002, 08:11 AM
#6
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.
-
Nov 18th, 2002, 01:20 PM
#7
Thread Starter
Fanatic Member
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
-
Nov 19th, 2002, 07:07 AM
#8
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.
-
Nov 20th, 2002, 03:11 AM
#9
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|