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 / chap24 / patron / client.cpp < prev    next >
C/C++ Source or Header  |  1995-05-03  |  5KB  |  208 lines

  1. /*
  2.  * CLIENT.CPP
  3.  * Patron Chapter 24
  4.  *
  5.  * Implementation of the CPatronClient class that just makes sure
  6.  * we get a CPatronDoc on doc creation and that we initialize fully.
  7.  *
  8.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  9.  *
  10.  * Kraig Brockschmidt, Microsoft
  11.  * Internet  :  kraigb@microsoft.com
  12.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  13.  */
  14.  
  15.  
  16. #include "patron.h"
  17.  
  18.  
  19. /*
  20.  * CPatronClient::CPatronClient
  21.  * CPatronClient::~CPatronClient
  22.  *
  23.  * Constructor Parameters:
  24.  *  hInst           HINSTANCE of the application.
  25.  *  pFR             PCFrame to the frame object.
  26.  */
  27.  
  28. CPatronClient::CPatronClient(HINSTANCE hInst, PCFrame pFR)
  29.     : CClient(hInst, pFR)
  30.     {
  31.     return;
  32.     }
  33.  
  34.  
  35. CPatronClient::~CPatronClient(void)
  36.     {
  37.     return;
  38.     }
  39.  
  40.  
  41.  
  42.  
  43.  
  44. /*
  45.  * CPatronClient::CreateCDocument
  46.  *
  47.  * Purpose:
  48.  *  Constructs a new document specific to the application.
  49.  *
  50.  * Parameters:
  51.  *  None
  52.  *
  53.  * Return Value:
  54.  *  PCDocument      Pointer to the new document object.
  55.  */
  56.  
  57. PCDocument CPatronClient::CreateCDocument(void)
  58.     {
  59.     return (PCDocument)(new CPatronDoc(m_hInst, m_pFR, m_pAdv));
  60.     }
  61.  
  62.  
  63.  
  64. /*
  65.  * CPatronClient::SetMenu
  66.  *
  67.  * Purpose:
  68.  *  Changes the frame-level menu, isolating the rest of the
  69.  *  application from MDI/SDI considerations.
  70.  *
  71.  * Parameters:
  72.  *  hWndFrame       HWND of the frame window.
  73.  *  hMenu           HMENU to set in the frame for the current
  74.  *                  document.
  75.  *  hMenuWin        HMENU of the window menu.
  76.  *
  77.  * Return Value:
  78.  *  None
  79.  */
  80.  
  81. void CPatronClient::SetMenu(HWND hWndFrame, HMENU hMenu
  82.     , HMENU hMenuWin)
  83.     {
  84.    #ifdef MDI
  85.      MDISETMENU(m_hWnd, hMenu, hMenuWin);
  86.      MDIREFRESHMENU(m_hWnd);
  87.    #else
  88.     if (NULL!=hMenu)
  89.         ::SetMenu(hWndFrame, hMenu);
  90.    #endif
  91.  
  92.     DrawMenuBar(hWndFrame);
  93.     return;
  94.     }
  95.  
  96.  
  97.  
  98.  
  99.  
  100. /*
  101.  * CPatronClient::MoveWithoutFamily
  102.  *
  103.  * Purpose:
  104.  *  This specific in-place activation function applies moves the
  105.  *  client window but to leave all child windows within it exactly
  106.  *  where they are to keep in-place objects in the same absolute
  107.  *  screen position.
  108.  *
  109.  * Parameters:
  110.  *  prc             LPRECT containing the new space for the client
  111.  *  dx, dy          ints specifying how much to move the client
  112.  *
  113.  * Return Value:
  114.  *  None
  115.  */
  116.  
  117. void CPatronClient::MoveWithoutFamily(LPRECT prc, int dx, int dy)
  118.     {
  119.     RECT        rc;
  120.     HWND        hWndFrame;
  121.     HWND        hWnd;
  122.     POINT       pt;
  123.  
  124.     hWndFrame=GetParent(m_hWnd);
  125.     SendMessage(hWndFrame, WM_SETREDRAW, FALSE, 0L);
  126.  
  127.     ShowWindow(m_hWnd, SW_HIDE);
  128.     SetWindowPos(m_hWnd, NULL, prc->left, prc->top
  129.         , prc->right-prc->left, prc->bottom-prc->top
  130.         , SWP_NOZORDER | SWP_NOACTIVATE);
  131.  
  132.     //Move all children of the client
  133.     hWnd=GetWindow(m_hWnd, GW_CHILD);
  134.  
  135.     while (NULL!=hWnd)
  136.         {
  137.         GetWindowRect(hWnd, &rc);
  138.         SETPOINT(pt, rc.left, rc.top);
  139.         ScreenToClient(m_hWnd, &pt);
  140.  
  141.         if (pt.x!=dx && pt.y!=dy && !IsZoomed(hWnd))
  142.             {
  143.             //Move window in the opposite direction as the client
  144.             SetWindowPos(hWnd, NULL, pt.x-dx, pt.y-dy
  145.                 , rc.right-rc.left, rc.bottom-rc.top
  146.                 , SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
  147.             }
  148.  
  149.         hWnd=GetWindow(hWnd, GW_HWNDNEXT);
  150.         }
  151.  
  152.     SendMessage(hWndFrame, WM_SETREDRAW, TRUE, 0L);
  153.     ShowWindow(m_hWnd, SW_SHOW);
  154.  
  155.     return;
  156.     }
  157.  
  158.  
  159.  
  160. /*
  161.  * CPatronClient::CallContextHelpOnDocuments
  162.  *
  163.  * Purpose:
  164.  *  Calls IOleInPlaceUIWindow->ContextSensitiveHelp for each
  165.  *  document window as required in an MDI container.  This does
  166.  *  nothing in SDI.
  167.  *
  168.  * Parameters:
  169.  *  fEnterMode      BOOl to pass to the documents
  170.  *
  171.  * Return Value:
  172.  *  None
  173.  */
  174.  
  175. void CPatronClient::CallContextHelpOnDocuments(BOOL fEnterMode)
  176.     {
  177.     LPOLEINPLACEUIWINDOW    pUIWin;
  178.     HWND                    hWndT;
  179.     PCPatronDoc             pDoc;
  180.  
  181.     //Loop through the documents calling their functions.
  182.     hWndT=GetWindow(m_hWnd, GW_CHILD);
  183.  
  184.     for ( ; hWndT; hWndT=GetWindow(hWndT, GW_HWNDNEXT))
  185.         {
  186.         //Skip if icon title window
  187.         if (NULL!=GetWindow(hWndT, GW_OWNER))
  188.             continue;
  189.  
  190.         pDoc=(PCPatronDoc)SendMessage(hWndT, DOCM_PDOCUMENT
  191.             , 0, 0L);
  192.  
  193.         if (NULL==pDoc)
  194.             continue;
  195.  
  196.         pDoc->QueryInterface(IID_IOleInPlaceUIWindow
  197.             , (PPVOID)&pUIWin);
  198.  
  199.         if (NULL==pUIWin)
  200.             continue;
  201.  
  202.         pUIWin->ContextSensitiveHelp(fEnterMode);
  203.         pUIWin->Release();
  204.         }
  205.  
  206.     return;
  207.     }
  208.