Originally posted by minesweeper
Can I take this opportunity to ask about static variables please?
I am creating my first WinAPI program in the form of a game of battleships. I have created a grid of square bitmaps and I wish the user to click on the square he/she wishes to fire at and then click a button to fire. When the user clicks on the square, the WM_LBUTTONDOWN message is handled and the coordinates of the cursor position are stored in a globally defined integer for use by WndProc() once the user clicks the "Fire" button. If this integer were declared inside WndProc() as a static integer would it have the same effect (i.e. contain the data given to it during the last WndProc() call)? What about if (as I often do) I initialise the integer to 0 at the beginning of WndProc()? Will it revert to 0 every time WndProc() is called?
Thanks
I think you are referring to the initialization of the static as in:
Code:
static int coord_x = 0;
static int coord_y = 0;
and the answer is nope. Only when the program first starts. Static in this case is much like a global in that it exists for the length of the program. The initialization does not happen every time in.