home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / activedocument / doserver / oledocvw.cpp < prev    next >
C/C++ Source or Header  |  1997-06-23  |  20KB  |  818 lines

  1. /**************************************************************************
  2.    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  3.    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  4.    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  5.    PARTICULAR PURPOSE.
  6.  
  7.    Copyright 1997 Microsoft Corporation.  All Rights Reserved.
  8. **************************************************************************/
  9.  
  10. /**************************************************************************
  11.  
  12.    File:          OleDocVw.cpp
  13.    
  14.    Description:   COleDocumentView implementation.
  15.  
  16. **************************************************************************/
  17.  
  18. /**************************************************************************
  19.    #include statements
  20. **************************************************************************/
  21.  
  22. #include "OleDocVw.h"
  23. #include <windowsx.h>
  24.  
  25. /**************************************************************************
  26.  
  27.    COleDocumentView::COleDocumentView()
  28.  
  29. **************************************************************************/
  30.  
  31. COleDocumentView::COleDocumentView(COleDocument *pOleDoc)
  32. {
  33. OutputDebugString(TEXT("COleDocumentView's constructor\n"));
  34.  
  35. m_pInPlaceSite = NULL;
  36. m_pInPlaceFrame = NULL;
  37. m_pInPlaceUIWindow = NULL;
  38. m_hwndView = NULL;
  39. m_fUIActive = FALSE;
  40. m_fInPlaceActive = FALSE;
  41. m_hSharedMenu = NULL;
  42. m_hOleMenu = NULL;
  43.  
  44. m_pOleDoc = pOleDoc;
  45.  
  46. CreateViewWindow();
  47. }
  48.  
  49. /**************************************************************************
  50.  
  51.    COleDocumentView::~COleDocumentView()
  52.  
  53. **************************************************************************/
  54.  
  55. COleDocumentView::~COleDocumentView()
  56. {
  57. OutputDebugString(TEXT("COleDocumentView's destructor\n"));
  58.  
  59. if(m_pInPlaceFrame)
  60.    m_pInPlaceFrame->Release();
  61.  
  62. if(m_pInPlaceUIWindow)
  63.    m_pInPlaceUIWindow->Release();
  64.  
  65. if(m_pInPlaceSite)
  66.    m_pInPlaceSite->Release();
  67. }
  68.  
  69. ///////////////////////////////////////////////////////////////////////////
  70. //
  71. // IUnknown Implementation
  72. //
  73.  
  74. /**************************************************************************
  75.  
  76.    COleDocumentView::QueryInterface
  77.  
  78. **************************************************************************/
  79.  
  80. STDMETHODIMP COleDocumentView::QueryInterface(  REFIID riid, 
  81.                                                 LPVOID *ppReturn)
  82. {
  83. OutputDebugString(TEXT("COleDocumentView::QueryInterface\n"));
  84.  
  85. return m_pOleDoc->QueryInterface(riid, ppReturn);
  86. }                                             
  87.  
  88. /**************************************************************************
  89.  
  90.    COleDocumentView::AddRef
  91.  
  92. **************************************************************************/
  93.  
  94. STDMETHODIMP_(DWORD) COleDocumentView::AddRef()
  95. {
  96. OutputDebugString(TEXT("COleDocumentView::AddRef\n"));
  97.  
  98. return m_pOleDoc->AddRef();
  99. }
  100.  
  101.  
  102. /**************************************************************************
  103.  
  104.    COleDocumentView::Release
  105.  
  106. **************************************************************************/
  107.  
  108. STDMETHODIMP_(DWORD) COleDocumentView::Release()
  109. {
  110. OutputDebugString(TEXT("COleDocumentView::Release\n"));
  111.  
  112. return m_pOleDoc->Release();
  113. }
  114.  
  115. /**************************************************************************
  116.  
  117.    COleDocumentView::SetInPlaceSite()
  118.    
  119. **************************************************************************/
  120.  
  121. STDMETHODIMP COleDocumentView::SetInPlaceSite(IOleInPlaceSite *pNewSite)
  122. {
  123. OutputDebugString(TEXT("COleDocumentView::SetInPlaceSite\n"));
  124.  
  125. //clean up previous site if it exists
  126. if(m_pInPlaceSite)
  127.    {
  128.    if(m_fUIActive)
  129.       {
  130.       DeactivateUI();
  131.       }
  132.    
  133.    if(m_fInPlaceActive)
  134.       {
  135.       DeactivateInPlace();
  136.       }
  137.    
  138.    if(m_pInPlaceFrame)
  139.       {
  140.       m_pInPlaceFrame->Release();
  141.       m_pInPlaceFrame = NULL;
  142.       }
  143.    
  144.    if(m_pInPlaceUIWindow)
  145.       {
  146.       m_pInPlaceUIWindow->Release();
  147.       m_pInPlaceUIWindow = NULL;
  148.       }
  149.    
  150.    m_pInPlaceSite->Release();
  151.    m_pInPlaceSite = NULL;
  152.    }
  153.  
  154. m_pInPlaceSite = pNewSite;
  155.  
  156. if(m_pInPlaceSite)
  157.    {
  158.    m_pInPlaceSite->AddRef();
  159.  
  160.    RECT  rcClip;
  161.  
  162.    m_FrameInfo.cb = sizeof(m_FrameInfo);
  163.    
  164.    m_pInPlaceSite->GetWindowContext(   &m_pInPlaceFrame,
  165.                                        &m_pInPlaceUIWindow,
  166.                                        &m_Rect,
  167.                                        &rcClip,
  168.                                        &m_FrameInfo);
  169.    }
  170.  
  171. return S_OK;
  172. }
  173.  
  174. /**************************************************************************
  175.  
  176.    COleDocumentView::GetInPlaceSite()
  177.    
  178. **************************************************************************/
  179.  
  180. STDMETHODIMP COleDocumentView::GetInPlaceSite(IOleInPlaceSite **ppInPlaceSite)
  181. {
  182. OutputDebugString(TEXT("COleDocumentView::GetInPlaceSite\n"));
  183.  
  184. HRESULT  hr = E_FAIL;
  185.  
  186. *ppInPlaceSite = m_pInPlaceSite;
  187.  
  188. if(*ppInPlaceSite)
  189.    {
  190.    (*ppInPlaceSite)->AddRef();
  191.    hr = S_OK;
  192.    }
  193.  
  194. return hr;
  195. }
  196.  
  197. /**************************************************************************
  198.  
  199.    COleDocumentView::GetDocument()
  200.    
  201. **************************************************************************/
  202.  
  203. STDMETHODIMP COleDocumentView::GetDocument(IUnknown **ppUnk)
  204. {
  205. OutputDebugString(TEXT("COleDocumentView::GetDocument\n"));
  206.  
  207. *ppUnk = m_pOleDoc;
  208.  
  209. if(*ppUnk)
  210.    (*ppUnk)->AddRef();
  211.  
  212. return S_OK;
  213. }
  214.  
  215. /**************************************************************************
  216.  
  217.    COleDocumentView::SetRect()
  218.    
  219. **************************************************************************/
  220.  
  221. STDMETHODIMP COleDocumentView::SetRect(LPRECT pRect)
  222. {
  223. OutputDebugString(TEXT("COleDocumentView::SetRect - "));
  224.  
  225. if(!pRect)
  226.    return E_INVALIDARG;
  227.  
  228. m_Rect = *pRect;
  229.  
  230. TCHAR szText[MAX_PATH];
  231. wsprintf(szText, TEXT("%d, %d, %d, %d\n"), m_Rect.left, m_Rect.top, m_Rect.right, m_Rect.bottom);
  232. OutputDebugString(szText);
  233.  
  234. MoveWindow(m_hwndView, m_Rect.left, m_Rect.top, m_Rect.right, m_Rect.bottom, TRUE);
  235.  
  236. return S_OK;
  237. }
  238.  
  239. /**************************************************************************
  240.  
  241.    COleDocumentView::GetRect()
  242.    
  243. **************************************************************************/
  244.  
  245. STDMETHODIMP COleDocumentView::GetRect(LPRECT pRect)
  246. {
  247. OutputDebugString(TEXT("COleDocumentView::GetRect\n"));
  248.  
  249. if(!pRect)
  250.    return E_INVALIDARG;
  251.  
  252. *pRect = m_Rect;
  253.  
  254. return S_OK;
  255. }
  256.  
  257. /**************************************************************************
  258.  
  259.    COleDocumentView::SetRectComplex()
  260.    
  261. **************************************************************************/
  262.  
  263. STDMETHODIMP COleDocumentView::SetRectComplex(  LPRECT prcView, 
  264.                                                 LPRECT prcHScroll, 
  265.                                                 LPRECT prcVScroll, 
  266.                                                 LPRECT prcSizeBox)
  267. {
  268. OutputDebugString(TEXT("COleDocumentView::SetRectComplex\n"));
  269.  
  270. return E_NOTIMPL;
  271. }
  272.  
  273. /**************************************************************************
  274.  
  275.    COleDocumentView::Show()
  276.    
  277. **************************************************************************/
  278.  
  279. STDMETHODIMP COleDocumentView::Show(BOOL bShow)
  280. {
  281. OutputDebugString(TEXT("COleDocumentView::Show\n"));
  282.  
  283. if(bShow)
  284.    {
  285.    //if the object is not in-place active, make it that way
  286.    if(!m_fInPlaceActive)
  287.       ActivateInPlace();
  288.  
  289.    //show the window
  290.    BringWindowToTop(m_hwndView);
  291.    ShowWindow(m_hwndView, SW_SHOW);
  292.    UpdateWindow(m_hwndView);
  293.    }
  294. else
  295.    {
  296.    //if the object is UI active, make remove that state
  297.    if(m_fUIActive)
  298.       DeactivateUI();
  299.  
  300.    //hide the window
  301.    ShowWindow(m_hwndView, SW_HIDE);
  302.    }
  303.  
  304. return S_OK;
  305. }
  306.  
  307. /**************************************************************************
  308.  
  309.    COleDocumentView::UIActivate()
  310.    
  311. **************************************************************************/
  312.  
  313. STDMETHODIMP COleDocumentView::UIActivate(BOOL bActivate)
  314. {
  315. OutputDebugString(TEXT("COleDocumentView::UIActivate\n"));
  316.  
  317. if(bActivate)
  318.    {
  319.    return ActivateUI();
  320.    }
  321.  
  322. return DeactivateUI();
  323. }
  324.  
  325. /**************************************************************************
  326.  
  327.    COleDocumentView::ActivateUI()
  328.    
  329. **************************************************************************/
  330.  
  331. STDMETHODIMP COleDocumentView::ActivateUI()
  332. {
  333. OutputDebugString(TEXT("COleDocumentView::ActivateUI\n"));
  334.  
  335. //set the active object
  336. //either one of these could be good
  337. if(m_pInPlaceFrame)
  338.    {
  339.    m_pInPlaceFrame->SetActiveObject(m_pOleDoc->m_pOleInPlaceActiveObject, NULL);
  340.    }
  341.  
  342. if(m_pInPlaceUIWindow)
  343.    {
  344.    m_pInPlaceUIWindow->SetActiveObject(m_pOleDoc->m_pOleInPlaceActiveObject, NULL);
  345.    }
  346.       
  347. if(m_pInPlaceSite)
  348.    {
  349.    m_fUIActive = TRUE;
  350.  
  351.    ActivateInPlace();
  352.       
  353.    m_pInPlaceSite->OnUIActivate();
  354.  
  355.    MergeMenus();
  356.  
  357.    SetFocus(m_hwndView);
  358.    }
  359.  
  360. return S_OK;
  361. }
  362.  
  363. /**************************************************************************
  364.  
  365.    COleDocumentView::DeactivateUI()
  366.    
  367. **************************************************************************/
  368.  
  369. STDMETHODIMP COleDocumentView::DeactivateUI()
  370. {
  371. OutputDebugString(TEXT("COleDocumentView::DeactivateUI\n"));
  372.  
  373. m_fUIActive = FALSE;
  374.    
  375. RemoveMenus();
  376.       
  377. //remove the active object
  378. //either one of these could be good
  379. if(m_pInPlaceFrame)
  380.    {
  381.    m_pInPlaceFrame->SetActiveObject(NULL, NULL);
  382.    }
  383.  
  384. if(m_pInPlaceUIWindow)
  385.    {
  386.    m_pInPlaceUIWindow->SetActiveObject(NULL, NULL);
  387.    }
  388.  
  389. if(m_pInPlaceSite)
  390.    {
  391.    m_pInPlaceSite->OnUIDeactivate(FALSE);
  392.    }
  393.  
  394. return S_OK;
  395. }
  396.  
  397. /**************************************************************************
  398.  
  399.    COleDocumentView::Open()
  400.    
  401. **************************************************************************/
  402.  
  403. STDMETHODIMP COleDocumentView::Open(void)
  404. {
  405. OutputDebugString(TEXT("COleDocumentView::Open\n"));
  406.  
  407. return S_OK;
  408. }
  409.  
  410. /**************************************************************************
  411.  
  412.    COleDocumentView::CloseView()
  413.    
  414. **************************************************************************/
  415.  
  416. STDMETHODIMP COleDocumentView::CloseView(DWORD dwReserved)
  417. {
  418. OutputDebugString(TEXT("COleDocumentView::CloseView\n"));
  419.  
  420. SetInPlaceSite(NULL);
  421.  
  422. return S_OK;
  423. }
  424.  
  425. /**************************************************************************
  426.  
  427.    COleDocumentView::SaveViewState()
  428.    
  429. **************************************************************************/
  430.  
  431. STDMETHODIMP COleDocumentView::SaveViewState(IStream *pStream)
  432. {
  433. OutputDebugString(TEXT("COleDocumentView::SaveViewState\n"));
  434.  
  435. return E_NOTIMPL;
  436. }
  437.  
  438. /**************************************************************************
  439.  
  440.    COleDocumentView::ApplyViewState()
  441.    
  442. **************************************************************************/
  443.  
  444. STDMETHODIMP COleDocumentView::ApplyViewState(IStream *pStream)
  445. {
  446. OutputDebugString(TEXT("COleDocumentView::ApplyViewState\n"));
  447.  
  448. return E_NOTIMPL;
  449. }
  450.  
  451. /**************************************************************************
  452.  
  453.    COleDocumentView::Clone()
  454.    
  455. **************************************************************************/
  456.  
  457. STDMETHODIMP COleDocumentView::Clone(IOleInPlaceSite *pIPSite, IOleDocumentView **ppView)
  458. {
  459. OutputDebugString(TEXT("COleDocumentView::Clone\n"));
  460.  
  461. *ppView = NULL;
  462.  
  463. return E_NOTIMPL;
  464. }
  465.  
  466. /**************************************************************************
  467.  
  468.    COleDocumentView::ActivateInPlace()
  469.    
  470. **************************************************************************/
  471.  
  472. STDMETHODIMP COleDocumentView::ActivateInPlace()
  473. {
  474. OutputDebugString(TEXT("COleDocumentView::ActivateInPlace\n"));
  475.  
  476. m_fInPlaceActive = TRUE;
  477.  
  478. if(m_pInPlaceSite) 
  479.    {
  480.    // tell the site we are in-place activating
  481.    m_pInPlaceSite->OnInPlaceActivate();
  482.  
  483.    HWND  hwndParent;
  484.    m_pInPlaceSite->GetWindow(&hwndParent);
  485.    SetParent(m_hwndView, hwndParent);
  486.  
  487.    //show the view
  488.    Show(TRUE);
  489.    }
  490.  
  491. return S_OK;
  492. }
  493.  
  494. /**************************************************************************
  495.  
  496.    COleDocumentView::DeactivateInPlace()
  497.    
  498. **************************************************************************/
  499.  
  500. STDMETHODIMP COleDocumentView::DeactivateInPlace()
  501. {
  502. OutputDebugString(TEXT("COleDocumentView::InPlaceDeactivate\n"));
  503.  
  504. //UI deactivate, if necessary and hide the view window
  505. Show(FALSE);
  506.  
  507. m_fInPlaceActive = FALSE;
  508.  
  509. if(m_pInPlaceSite) 
  510.    {
  511.    // tell the site we are in-place deactivating
  512.    m_pInPlaceSite->OnInPlaceDeactivate();
  513.    }
  514.  
  515. //set the parent to NULL
  516. SetParent(m_hwndView, GetDesktopWindow());
  517.  
  518. return S_OK;
  519. }
  520.  
  521. /**************************************************************************
  522.  
  523.    COleDocumentView::CreateDocWindow()
  524.    
  525. **************************************************************************/
  526.  
  527. STDMETHODIMP COleDocumentView::CreateViewWindow()
  528. {
  529. OutputDebugString(TEXT("COleDocumentView::CreateViewWindow\n"));
  530.  
  531. WNDCLASS wc;
  532.  
  533. //if our window class has not been registered, then do so
  534. if(!GetClassInfo(g_hInst, VIEW_CLASS_NAME, &wc))
  535.    {
  536.    ZeroMemory(&wc, sizeof(wc));
  537.    wc.style          = CS_HREDRAW | CS_VREDRAW;
  538.    wc.lpfnWndProc    = (WNDPROC)ViewWndProc;
  539.    wc.cbClsExtra     = 0;
  540.    wc.cbWndExtra     = 0;
  541.    wc.hInstance      = g_hInst;
  542.    wc.hIcon          = NULL;
  543.    wc.hCursor        = LoadCursor(NULL, IDC_ARROW);
  544.    wc.hbrBackground  = (HBRUSH)(COLOR_WINDOW + 1);
  545.    wc.lpszMenuName   = NULL;
  546.    wc.lpszClassName  = VIEW_CLASS_NAME;
  547.    
  548.    if(!RegisterClass(&wc))
  549.       return E_FAIL;
  550.    }
  551.  
  552. m_hwndView = CreateWindowEx(  WS_EX_CLIENTEDGE,
  553.                               VIEW_CLASS_NAME,
  554.                               NULL,
  555.                               WS_CHILD | WS_CLIPSIBLINGS,
  556.                               0,
  557.                               0,
  558.                               0,
  559.                               0,
  560.                               GetDesktopWindow(),
  561.                               NULL,
  562.                               g_hInst,
  563.                               (LPVOID)this);
  564.                            
  565. if(!m_hwndView)
  566.    {
  567.    DWORD dwError = GetLastError();
  568.    return E_FAIL;
  569.    }
  570.  
  571. return S_OK;
  572. }
  573.  
  574. /**************************************************************************
  575.  
  576.    COleDocumentView::ViewWndProc()
  577.    
  578. **************************************************************************/
  579.  
  580. LRESULT CALLBACK COleDocumentView::ViewWndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
  581. {
  582. COleDocumentView  *pThis = (COleDocumentView*)GetWindowLong(hWnd, GWL_USERDATA);
  583.  
  584. switch (uMessage)
  585.    {
  586.    case WM_NCCREATE:
  587.       {
  588.       LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
  589.       pThis = (COleDocumentView*)(lpcs->lpCreateParams);
  590.       SetWindowLong(hWnd, GWL_USERDATA, (LONG)pThis);
  591.       }
  592.       break;
  593.  
  594.    case WM_CREATE:
  595.       return pThis->OnCreate();
  596.    
  597.    case WM_COMMAND:
  598.       return pThis->OnCommand(   GET_WM_COMMAND_ID(wParam, lParam), 
  599.                                  GET_WM_COMMAND_CMD(wParam, lParam), 
  600.                                  GET_WM_COMMAND_HWND(wParam, lParam));
  601.  
  602.    case WM_PAINT:
  603.       return pThis->OnPaint();
  604.    
  605.    case WM_INITMENUPOPUP:
  606.       return pThis->UpdateMenu((HMENU)wParam);
  607.    
  608.    }
  609.  
  610. return DefWindowProc(hWnd, uMessage, wParam, lParam);
  611. }
  612.  
  613. /**************************************************************************
  614.  
  615.    COleDocumentView::OnCreate()
  616.    
  617. **************************************************************************/
  618.  
  619. LRESULT COleDocumentView::OnCreate(void)
  620. {
  621. return 0;
  622. }
  623.  
  624. /**************************************************************************
  625.  
  626.    COleDocumentView::OnCommand()
  627.    
  628. **************************************************************************/
  629.  
  630. LRESULT COleDocumentView::OnCommand(UINT uID, UINT uCmd, HWND hwndCmd)
  631. {
  632. switch(uID)
  633.    {
  634.    case IDM_RED:
  635.       m_pOleDoc->m_Color = RED_COLOR;
  636.       InvalidateRect(m_hwndView, NULL, TRUE);
  637.       UpdateWindow(m_hwndView);
  638.       m_pOleDoc->m_fDirty = TRUE;
  639.       break;
  640.  
  641.    case IDM_GREEN:
  642.       m_pOleDoc->m_Color = GREEN_COLOR;
  643.       InvalidateRect(m_hwndView, NULL, TRUE);
  644.       UpdateWindow(m_hwndView);
  645.       m_pOleDoc->m_fDirty = TRUE;
  646.       break;
  647.  
  648.    case IDM_BLUE:
  649.       m_pOleDoc->m_Color = BLUE_COLOR;
  650.       InvalidateRect(m_hwndView, NULL, TRUE);
  651.       UpdateWindow(m_hwndView);
  652.       m_pOleDoc->m_fDirty = TRUE;
  653.       break;
  654.  
  655.    }
  656.  
  657. return 0;
  658. }
  659.  
  660. /**************************************************************************
  661.  
  662.    COleDocumentView::OnPaint()
  663.    
  664. **************************************************************************/
  665.  
  666. LRESULT COleDocumentView::OnPaint(void)
  667. {
  668. PAINTSTRUCT ps;
  669.  
  670. BeginPaint(m_hwndView, &ps);
  671.  
  672. RECT  rc;
  673. HBRUSH hBrush = CreateSolidBrush(m_pOleDoc->m_Color);
  674. GetClientRect(m_hwndView, &rc);
  675.  
  676. FillRect(ps.hdc, &rc, hBrush);
  677.  
  678. DeleteObject(hBrush);
  679.  
  680. EndPaint(m_hwndView, &ps);
  681.  
  682. return 0;
  683. }
  684.  
  685. /**************************************************************************
  686.  
  687.    COleDocumentView::MergeMenus()
  688.    
  689. **************************************************************************/
  690.  
  691. BOOL COleDocumentView::MergeMenus(void)
  692. {
  693. if(!m_hSharedMenu)
  694.    {
  695.    //  Create the menu resource
  696.    m_hSharedMenu = CreateMenu();
  697.  
  698.    ZeroMemory(&m_mgw, sizeof(m_mgw));
  699.    
  700.    // have the contaner insert its menus
  701.    if(SUCCEEDED(m_pInPlaceFrame->InsertMenus(m_hSharedMenu, &m_mgw)))
  702.       {
  703.       int   nFirstGroup = (int) m_mgw.width[0];
  704.       HMENU hMenu,
  705.             hSubMenu;
  706.       TCHAR szText[MAX_PATH];
  707.  
  708.       hMenu = LoadMenu(g_hInst, MAKEINTRESOURCE(IDR_COLOR_MENU));
  709.       hSubMenu = GetSubMenu(hMenu, 0);
  710.  
  711.       //get the menu item's text
  712.       GetMenuString(hMenu, 0, szText, ARRAYSIZE(szText), MF_BYPOSITION);
  713.    
  714.       // insert the server menus
  715.       InsertMenu( m_hSharedMenu, 
  716.                   nFirstGroup, 
  717.                   MF_BYPOSITION | MF_POPUP, 
  718.                   (UINT)hSubMenu, 
  719.                   szText);
  720.  
  721.       //update the OLEMENUGROUPWIDTHS structure
  722.       m_mgw.width[1] += 1;
  723.       m_mgw.width[3] += 0;
  724.       m_mgw.width[5] += 0;
  725.       }
  726.    else
  727.       {
  728.       // Destroy the menu resource
  729.       DestroyMenu(m_hSharedMenu);
  730.       m_hSharedMenu = NULL;
  731.       }
  732.    }
  733.  
  734. if(!m_hOleMenu)
  735.    {
  736.    // tell OLE to create the menu descriptor
  737.    m_hOleMenu = OleCreateMenuDescriptor(m_hSharedMenu, &m_mgw);
  738.    }
  739.  
  740. m_pInPlaceFrame->SetMenu(m_hSharedMenu, m_hOleMenu, m_hwndView);
  741.  
  742. return TRUE;
  743. }
  744.  
  745. /**************************************************************************
  746.  
  747.    COleDocumentView::RemoveMenus()
  748.    
  749. **************************************************************************/
  750.  
  751. BOOL COleDocumentView::RemoveMenus(void)
  752. {
  753. if(m_hSharedMenu)
  754.    {
  755.    int   nFirstGroup = (int) m_mgw.width[0];
  756.  
  757.    m_pInPlaceFrame->SetMenu(NULL, NULL, NULL);
  758.  
  759.    // remove the menus that we added
  760.    RemoveMenu(m_hSharedMenu, nFirstGroup, MF_BYPOSITION);
  761.  
  762.    // have the container remove its menus
  763.    m_pInPlaceFrame->RemoveMenus(m_hSharedMenu);
  764.  
  765.    // Destroy the menu resource
  766.    DestroyMenu(m_hSharedMenu);
  767.  
  768.    m_hSharedMenu = NULL;
  769.    }
  770.  
  771. if(m_hOleMenu)
  772.    {
  773.    // destroy the menu descriptor
  774.    OleDestroyMenuDescriptor(m_hOleMenu);
  775.  
  776.    m_hOleMenu = NULL;
  777.    }
  778.  
  779. return TRUE;
  780. }
  781.  
  782. /**************************************************************************
  783.  
  784.    COleDocumentView::UpdateMenu()
  785.    
  786. **************************************************************************/
  787.  
  788. BOOL COleDocumentView::UpdateMenu(HMENU hMenu)
  789. {
  790. UINT  uCheck;
  791.  
  792. switch(m_pOleDoc->m_Color)
  793.    {
  794.    case RED_COLOR:
  795.       uCheck = IDM_RED;
  796.       break;
  797.  
  798.    case GREEN_COLOR:
  799.       uCheck = IDM_GREEN;
  800.       break;
  801.  
  802.    case BLUE_COLOR:
  803.       uCheck = IDM_BLUE;
  804.       break;
  805.  
  806.    default:
  807.       uCheck = 0;
  808.       break;
  809.    }
  810.  
  811. return CheckMenuRadioItem( hMenu, 
  812.                            IDM_RED, 
  813.                            IDM_BLUE, 
  814.                            uCheck, 
  815.                            MF_BYCOMMAND);
  816. }
  817.  
  818.