/******************************************************************************/
/*                                                                            */
/*  CB_IMAGE - Callback for the IMAGE window                                  */
/*                                                                            */
/******************************************************************************/

#define STRICT
#include <windows.h>
#include <commctrl.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include "const.h"
#include "classes.h"
#include "funcdefs.h"
#include "lin.rh"
#include "extern.h"

extern "C"

LRESULT CALLBACK ImageWndProc ( HWND hwnd , UINT message ,
                                WPARAM wParam , LPARAM lParam )
{
   MDICREATESTRUCT *mcsptr ;
   Image *imgptr ;

   switch (message) {
       
      case WM_CREATE:

/*
   We now put the image pointer in the extra space that we reserved when the
   image window class was registered.  We reserved sizeof(Image *) bytes.
*/
         mcsptr = (MDICREATESTRUCT *)(((CREATESTRUCT *)lParam)->lpCreateParams);
         imgptr = (Image *) mcsptr->lParam ;
         SetWindowLongPtr ( hwnd , 0 , (LONG_PTR) imgptr ) ; // Save for future reference
         return 0 ;

      case WM_SIZE :
         InvalidateRect ( hwnd , NULL , TRUE ) ;
         break ; // We break, not return, because this must be processed
                 // by DefMDIChildProc () according to Petzold pg. 906

      case WM_PAINT :
         imgptr = (Image *) GetWindowLongPtr ( hwnd , 0 ) ; // See WM_CREATE above
         imgptr->draw ( hwnd , 0 ) ;
         return 0 ;

//      case WM_CLOSE:
//         SendMessage ( hwndClient , WM_MDIDESTROY , (WPARAM) hwndVortex , 0 ) ;
//         hwndVortex = NULL ;
//         delete lin_img ;
//         return 0 ;

      case WM_DESTROY:
         imgptr = (Image *) GetWindowLongPtr ( hwnd , 0 ) ; // Image ptr
         if (imgptr != NULL)
            delete imgptr ;
         return 0 ;
      }

    return DefMDIChildProc ( hwnd , message , wParam , lParam ) ;
}
