home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / inole2 / classlib / docwin.cpp < prev    next >
C/C++ Source or Header  |  1995-05-03  |  3KB  |  109 lines

  1. /*
  2.  * DOCWIN.CPP
  3.  * Sample Code Class Libraries
  4.  *
  5.  * Window procedure for document windows.
  6.  *
  7.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  8.  *
  9.  * Kraig Brockschmidt, Microsoft
  10.  * Internet  :  kraigb@microsoft.com
  11.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  12.  */
  13.  
  14.  
  15. #include <windows.h>
  16. #include "classlib.h"
  17.  
  18.  
  19. /*
  20.  * DocumentWndProc
  21.  *
  22.  * Purpose:
  23.  *  Document window class that contains a polyline but does not own
  24.  *  things like the gizmobar.
  25.  *
  26.  *  We handle all commands from menus and gizmobars as well as
  27.  *  notifications from the polyline itself.  The frame window
  28.  *  just makes sure that commands and such are dispatched here
  29.  *  as necessary, especially in an MDI case.
  30.  */
  31.  
  32. LRESULT APIENTRY DocumentWndProc(HWND hWnd, UINT iMsg
  33.     , WPARAM wParam, LPARAM lParam)
  34.     {
  35.     PCDocument      pDoc;
  36.     BOOL            fOK=FALSE;
  37.     LPARAM          lTemp;
  38.     LRESULT         lRet;
  39.  
  40.     pDoc=(PCDocument)GetWindowLong(hWnd, DOCWL_STRUCTURE);
  41.  
  42.     if (NULL!=pDoc)
  43.         {
  44.         //Call the hook and return its value if it tells us to.
  45.         if (pDoc->FMessageHook(hWnd, iMsg, wParam, lParam, &lRet))
  46.             return lRet;
  47.         }
  48.  
  49.  
  50.     switch (iMsg)
  51.         {
  52.         case WM_CREATE:
  53.             /*
  54.              * Save our object pointer with this window.  We have to
  55.              * do this inside this message since we don't get the
  56.              * MDICREATESTRUCT anywhere else.
  57.              */
  58.  
  59.             lTemp=(LPARAM)((LPCREATESTRUCT)lParam)->lpCreateParams;
  60.             pDoc=(PCDocument)(((LPMDICREATESTRUCT)lTemp)->lParam);
  61.             SetWindowLong(hWnd, DOCWL_STRUCTURE, (LONG)pDoc);
  62.             break;
  63.  
  64.  
  65.         case WM_CLOSE:
  66.             //Tell our main window to close us
  67.             if (NULL!=pDoc->m_pAdv)
  68.                 pDoc->m_pAdv->OnCloseRequest(pDoc);
  69.  
  70.             break;
  71.  
  72.  
  73.         case WM_QUERYENDSESSION:
  74.             return TRUE;    //Right now we can always close.
  75.  
  76.  
  77.         case DOCM_PDOCUMENT:
  78.             //Return our object pointer
  79.             return (LONG)pDoc;
  80.  
  81.         case WM_MDIACTIVATE:
  82.             /*
  83.              * NEWMDIACTIVE isolates wParam/lParam differences
  84.              * between Win16 and Win32.
  85.              */
  86.             if (0!=NEWMDIACTIVE && NULL!=pDoc->m_pAdv)
  87.                 pDoc->m_pAdv->OnActivate(pDoc);
  88.  
  89.             break;
  90.  
  91.         case WM_MENUSELECT:
  92.             {
  93.             PCStatusLine    pSL;
  94.  
  95.             pSL=pDoc->m_pFR->StatusLine();
  96.  
  97.             if (NULL!=pSL)
  98.                 pSL->MenuSelect(wParam, lParam);
  99.  
  100.             }
  101.             break;
  102.  
  103.         default:
  104.             return DEFDOCUMENTPROC(hWnd, iMsg, wParam, lParam);
  105.         }
  106.  
  107.     return 0L;
  108.     }
  109.