How to replace invalidate with a function that goes to OnDraw without deleting the screen pictures

StackOverflow https://stackoverflow.com/questions/23274554

  •  09-07-2023
  •  | 
  •  

Question

Hi this is my first post on stack overflow.
I am using visual studio 2006 with mfc to build a snake game.Im trying to make it so when you press an arrow (left) the snake goes the direction of that arrow (left) until the snakes dies(hits a wall,himself) or the player presses another button.

Now I need some help with going from a function to OnDraw without deleting the stuff on the screen.

Also i want to know, how to make it so that when the program is in a middle of a function that is going call another function and at a point before the other function is called you press a button,the function continues till the moment that the other function is called but does not call the function instead it goes to OnKeyDown?

Was it helpful?

Solution

OnDraw is required to redraw the whole window because that window might have just been uncovered, or un-minimized. If you want to ignore that basic Windows requirement then just make yourself a DrawMore function and use CClientDC to get a DC to use to draw more.

Your other question implies an incorrect design. Do something in response to a message, then return to MFC so it can get keys, mouse, etc. messages. Your program has to be message-driven. To keep things moving along even when there is no keystroke you can use a timer (SetTimer, handle WM_TIMER messages).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top