title: win32 / opengl and callback functions.. how are they structured?
body: <p>I'm working on a win32 c/cpp project involving openGL. I'm just starting and had a few basic questions regarding how a standard win32 program works. Following a tutorial, I made the winmain create a new window, enable openGL for the window, and then enter the main loop where if there are messages, the program handles them, and otherwise, the program moves onto drawing openGL animations. Following that, I simply shut down openGL and destroy the window. I'm not too confused about what's happening in here, but this is where I get lost:</p>
  
  <pre><code>LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
  
  
  switch (message)
  {
  
  case WM_CREATE:
      return 0;
  
  case WM_CLOSE:
      PostQuitMessage( 0 );
      return 0;
  
  case WM_DESTROY:
      return 0;
  
  case WM_KEYDOWN:
      switch ( wParam )
      {
  
      case VK_ESCAPE:
          PostQuitMessage(0);
          return 0;
  
      }
      return 0;
  
  default:
      return DefWindowProc( hWnd, message, wParam, lParam );
  
  }
  </code></pre>
  
  <p>though I do see in the winmain that I register this function to my window class via</p>
  
  <pre><code>wc.lpfnWndProc = WndProc;
  </code></pre>
  
  <p>How exactly does this process work? Can someone explain the pipeline to me - as the winmain method runs, it goes onto drawing the opengl animation, but as soon as a key is pressed, it enters message handling... and then what? How does my winmain method communicate with the WndProc method? What's actually happening from the machine's point of view?</p>