You're using this rect in two different ways. And the ways you're using it are incompatible.
1 2 3 4
|
case _wl:
rc.left -= 5;
rc.right -= 5;
break;
|
Here, you are moving the rect to the left 5 pixels.
This makes sense as long as:
1) you're using 'right' to represent the right side of the rect (and not using it as the width). If you're using it as the width, this will also make the window 5 pixels skinnier.
2) 'rc' represents the window's position on the desktop.
The problem is... other areas of your code are not abiding by the above 2 points.
Specifically:
|
MoveWindow(_hWnd, rc.left, rc.top, rc.right, rc.bottom, true);
|
Here, you are using rc.right as the width, and not as the right side.
And:
BitBlt(_hDC, rc.left, rc.top, rc.right, rc.bottom, _mdc, 0, 0, SRCCOPY);
Here, you are using rc as coords relative to
the client area and not the
desktop area.
Again, if you want to just blit to your window, you blit to 0,0. It doesn't matter where your window is on the desktop, 0,0 is always the upper left corner of your window (the client area)
So you have to make up your mind. How do you want rc to behave?
EDIT:
The whole client area thing is goofy, so let me try to explain more clearly. Here's a pic to help:
http://i52.tinypic.com/2hda7ir.png
The client area is the part of the window that you draw to. It's most of the window, minus any menu bar, title bar, border, etc. From the looks of your snake game window, you didn't have any of those things on your window, so the client area is the same as your window area.
The coords you give BitBlt are
relative to the client area. So if you blit your offscreen DC to coord 10,10 -- the top and leftmost 10 pixels of your window will have nothing in them (garbage). What's more, the right and bottom-most 10 pixels of your DC will fall outside the client area and will not be visible.
The coords you get from GetClientRect area also relative to the client area. GetClientRect will always give you 0,0 for top and left, and will also give you the client width and height in right and bottom members.
On the other hand... the coords you give MoveWindow are relative
to the desktop. So you can't use the same coords for both MoveWindow and BitBlt (at least not without some translation).