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

  1. /*
  2.  * CLIENT.CPP
  3.  * Patron Chapter 22
  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. //CHAPTER22MOD
  65. /*
  66.  * CPatronClient::SetMenu
  67.  *
  68.  * Purpose:
  69.  *  Changes the frame-level menu, isolating the rest of the
  70.  *  application from MDI/SDI considerations.
  71.  *
  72.  * Parameters:
  73.  *  hWndFrame       HWND of the frame window.
  74.  *  hMenu           HMENU to set in the frame for the current
  75.  *                  document.
  76.  *  hMenuWin        HMENU of the window menu.
  77.  *
  78.  * Return Value:
  79.  *  None
  80.  */
  81.  
  82. void CPatronClient::SetMenu(HWND hWndFrame, HMENU hMenu
  83.     , HMENU hMenuWin)
  84.     {
  85.    #ifdef MDI
  86.      MDISETMENU(m_hWnd, hMenu, hMenuWin);
  87.      MDIREFRESHMENU(m_hWnd);
  88.    #else
  89.     if (NULL!=hMenu)
  90.         ::SetMenu(hWndFrame, hMenu);
  91.    #endif
  92.  
  93.     DrawMenuBar(hWndFrame);
  94.     return;
  95.     }
  96.  
  97.  
  98.  
  99.  
  100.  
  101. /*
  102.  * CPatronClient::MoveWithoutFamily
  103.  *
  104.  * Purpose:
  105.  *  This specific in-place activation function applies moves the
  106.  *  client window but to leave all child windows within it exactly
  107.  *  where they are to keep in-place objects in the same absolute
  108.  *  screen position.
  109.  *
  110.  * Parameters:
  111.  *  prc             LPRECT containing the new space for the client
  112.  *  dx, dy          ints specifying how much to move the client
  113.  *
  114.  * Return Value:
  115.  *  None
  116.  */
  117.  
  118. void CPatronClient::MoveWithoutFamily(LPRECT prc, int dx, int dy)
  119.     {
  120.     RECT        rc;
  121.     HWND        hWndFrame;
  122.     HWND        hWnd;
  123.     POINT       pt;
  124.  
  125.     hWndFrame=GetParent(m_hWnd);
  126.     SendMessage(hWndFrame, WM_SETREDRAW, FALSE, 0L);
  127.  
  128.     ShowWindow(m_hWnd, SW_HIDE);
  129.     SetWindowPos(m_hWnd, NULL, prc->left, prc->top
  130.         , prc->right-prc->left, prc->bottom-prc->top
  131.         , SWP_NOZORDER | SWP_NOACTIVATE);
  132.  
  133.     //Move all children of the client
  134.     hWnd=GetWindow(m_hWnd, GW_CHILD);
  135.  
  136.     while (NULL!=hWnd)
  137.         {
  138.         GetWindowRect(hWnd, &rc);
  139.         SETPOINT(pt, rc.left, rc.top);
  140.         ScreenToClient(m_hWnd, &pt);
  141.  
  142.         if (pt.x!=dx && pt.y!=dy && !IsZoomed(hWnd))
  143.             {
  144.             //Move window in the opposite direction as the client
  145.             SetWindowPos(hWnd, NULL, pt.x-dx, pt.y-dy
  146.                 , rc.right-rc.left, rc.bottom-rc.top
  147.                 , SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
  148.             }
  149.  
  150.         hWnd=GetWindow(hWnd, GW_HWNDNEXT);
  151.         }
  152.  
  153.     SendMessage(hWndFrame, WM_SETREDRAW, TRUE, 0L);
  154.     ShowWindow(m_hWnd, SW_SHOW);
  155.  
  156.     return;
  157.     }
  158.  
  159.  
  160.  
  161. /*
  162.  * CPatronClient::CallContextHelpOnDocuments
  163.  *
  164.  * Purpose:
  165.  *  Calls IOleInPlaceUIWindow->ContextSensitiveHelp for each
  166.  *  document window as required in an MDI container.  This does
  167.  *  nothing in SDI.
  168.  *
  169.  * Parameters:
  170.  *  fEnterMode      BOOl to pass to the documents
  171.  *
  172.  * Return Value:
  173.  *  None
  174.  */
  175.  
  176. void CPatronClient::CallContextHelpOnDocuments(BOOL fEnterMode)
  177.     {
  178.     LPOLEINPLACEUIWINDOW    pUIWin;
  179.     HWND                    hWndT;
  180.     PCPatronDoc             pDoc;
  181.  
  182.     //Loop through the documents calling their functions.
  183.     hWndT=GetWindow(m_hWnd, GW_CHILD);
  184.  
  185.     for ( ; hWndT; hWndT=GetWindow(hWndT, GW_HWNDNEXT))
  186.         {
  187.         //Skip if icon title window
  188.         if (NULL!=GetWindow(hWndT, GW_OWNER))
  189.             continue;
  190.  
  191.         pDoc=(PCPatronDoc)SendMessage(hWndT, DOCM_PDOCUMENT
  192.             , 0, 0L);
  193.  
  194.         if (NULL==pDoc)
  195.             continue;
  196.  
  197.         pDoc->QueryInterface(IID_IOleInPlaceUIWindow
  198.             , (PPVOID)&pUIWin);
  199.  
  200.         if (NULL==pUIWin)
  201.             continue;
  202.  
  203.         pUIWin->ContextSensitiveHelp(fEnterMode);
  204.         pUIWin->Release();
  205.         }
  206.  
  207.     return;
  208.     }
  209.  
  210.  
  211. //End CHAPTER22MOD
  212.