The name "static" may seem to imply that it is constant, but this is not true. What it means is that there is only ONE instance of the variable in your whole address space. Any calls to the variable, from any instance of the class, go to the same memory location. This is useful in saving memory if something does not change between instances of a class.
Another use of it is in non-member functions. If you need to retain data between calls to a function, declare a variable as static:
Code:
LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
static int counter;
switch (msg)
{
case WM_CREATE:
counter=0;
break;
case WM_LBUTTONDOWN:
counter++;
break;
default:
break;
}
return DefWindowProc(hwnd,msg,wParam,lParam);
}
In that case, even if the function is called multiple times, only one instance of 'counter' will be created. Therefore, during each call, it retains the same value it had before.