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 / chap18 / cosmo1.0 / olemisc.c < prev    next >
C/C++ Source or Header  |  1995-05-03  |  5KB  |  203 lines

  1. /*
  2.  * OLEMISC.C
  3.  *
  4.  * Functions without another approprate home:
  5.  *  MenuEmbeddingSet
  6.  *  OLEClientNotify
  7.  *  FOLEReleaseWait
  8.  *
  9.  * Copyright(c) Microsoft Corp. 1992-1994 All Rights Reserved
  10.  * Win32 version, January 1994
  11.  */
  12.  
  13. #ifdef MAKEOLESERVER
  14.  
  15. #include <windows.h>
  16. #include <ole.h>
  17. #include "cosmo.h"
  18. #include "oleglobl.h"
  19.  
  20.  
  21.  
  22. /*
  23.  * MenuEmbeddingSet
  24.  *
  25.  * Purpose:
  26.  *  Modifies the main menu of the application to change "Save" to "Update"
  27.  *  and to change "Exit" to "Exit & return to xx."  Alternately, this
  28.  *  function can change the menus back to the original state, reverting
  29.  *  "Update" to "Save" and setting the Exit item back to plain "Exit."
  30.  *
  31.  * Parameters:
  32.  *  hWnd            HWND of the window with the menu.
  33.  *  pszClient       LPSTR to the client name.
  34.  *  fOLE            BOOL indiciating if we are to set for OLE or to normal.
  35.  *                  If setting to normal, pszClient can be NULL.
  36.  *
  37.  * Return Value:
  38.  *  None.
  39.  *
  40.  */
  41.  
  42. void WINAPI MenuEmbeddingSet(HWND hWnd, LPSTR pszClient, BOOL fOLE)
  43.     {
  44.     HMENU       hMenu;
  45.     char        szTemp[130];
  46.     LPSTR       pszT;
  47.  
  48.     hMenu=GetMenu(pGlob->hWnd);
  49.  
  50.     //Change the File/Save menu to File/Update <client> or vice-versa
  51.     if (fOLE)
  52.         wsprintf(szTemp, rgpsz[IDS_UPDATE], pszClient);
  53.     else
  54.         lstrcpy(szTemp, rgpsz[IDS_SAVE]);
  55.  
  56.     ModifyMenu(hMenu, IDM_FILESAVE, MF_STRING, IDM_FILESAVE, szTemp);
  57.  
  58.  
  59.     //Change the File/Save As menu to File/Save Copy As or vice-versa.
  60.     pszT=(fOLE) ? rgpsz[IDS_SAVECOPYAS] : rgpsz[IDS_SAVEAS];
  61.     ModifyMenu(hMenu, IDM_FILESAVEAS, MF_STRING, IDM_FILESAVEAS, pszT);
  62.  
  63.  
  64.     //Change "Exit" to "Exit & return to xx" or vice-versa.
  65.     if (fOLE)
  66.         wsprintf(szTemp, rgpsz[IDS_EXITANDRETURN], pszClient);
  67.     else
  68.         lstrcpy(szTemp, rgpsz[IDS_EXIT]);
  69.  
  70.     ModifyMenu(hMenu, IDM_FILEEXIT, MF_STRING, IDM_FILEEXIT, szTemp);
  71.     return;
  72.     }
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79. /*
  80.  * OLEClientNotify
  81.  *
  82.  * Purpose:
  83.  *  Performs a direct function call to the single callback in the
  84.  *  client that is communicating with this server application.
  85.  *  This is the only point where there is direct communication
  86.  *  between the two applciations.
  87.  *
  88.  * Parameters:
  89.  *  pObj            LPCOSMOOBJECT that contains a pClient pointer to an
  90.  *                  LPOLECLIENT that holds a pointer to the OLECLIENTVTBL
  91.  *                  that holds a pointer to the CallBack function.
  92.  *  iMsg            UINT, message to send, such as OLE_CLOSED.
  93.  *
  94.  * Return Value:
  95.  *  None.
  96.  */
  97.  
  98. void WINAPI OLEClientNotify(LPCOSMOOBJECT pObj, UINT iMsg)
  99.     {
  100.     LPOLECLIENT     pClient;
  101.     LPOLECLIENTVTBL pvt;
  102.  
  103.     if (NULL==pObj)
  104.         return;
  105.  
  106.     pClient=pObj->pClient;
  107.  
  108.     if (NULL==pClient)
  109.         return;
  110.  
  111.     pvt=pClient->lpvtbl;
  112.  
  113.     if (NULL==pvt)
  114.         return;
  115.  
  116.     (pvt->CallBack)(pClient, iMsg, (LPOLEOBJECT)pObj);
  117.     return;
  118.     }
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125. /*
  126.  * FOLEReleaseWait
  127.  *
  128.  * Purpose:
  129.  *  Enters a Peek/Translate/Dispatch message loop to process all messages
  130.  *  to the application until a release flag has been sent.  The application
  131.  *  calls this routine whenever it is required to wait until conversations
  132.  *  for OLE have terminated.
  133.  *
  134.  *  Some of the messages processed may be DDE messages (for OLE 1.x) that
  135.  *  are eventually passed to OLESVR which eventually calls the ServerRelease
  136.  *  function (see OLESVR.C).  ServerRelease modifies a BOOL flag indicating
  137.  *  that the server is released.
  138.  *
  139.  *  Therefore we can watch a particular memory location (*pf)
  140.  *  and only exit when that flag is set.
  141.  *
  142.  * Parameters:
  143.  *  pf              BOOL FAR * to the flag to wait on.
  144.  *  lhSvr           LONG for the OLE server
  145.  *
  146.  * Return Value:
  147.  *  BOOL            Contents of *pf.
  148.  *
  149.  */
  150.  
  151. BOOL WINAPI FOLEReleaseWait(BOOL FAR *pf, LONG lhSvr)
  152.     {
  153.     MSG        msg;
  154.  
  155.     *pf=FALSE;
  156.  
  157.     while (FALSE==*pf)
  158.         {
  159.         /*
  160.          * We use PeekMessage here to make a point about power
  161.          * management and ROM Windows--GetMessage, when there's
  162.          * no more messages, will correctly let the system go into
  163.          * a low-power idle state.  PeekMessage by itself will not.
  164.          * If you do background processing in a PeekMessage loop like
  165.          * this, and there's no background processing to be done,
  166.          * then you MUST call WaitMessage to duplicate the idle
  167.          * state like GetMessage.
  168.          */
  169.  
  170.         if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
  171.             {
  172.             /*
  173.              * We will not see WM_QUIT in the middle of the
  174.              * application since this application MUST call
  175.              * PostQuitMessage to get it in the queue.  Therefore we
  176.              * don't even worry about it.
  177.              */
  178.  
  179.             TranslateMessage (&msg);
  180.             DispatchMessage (&msg);
  181.             }
  182.         else
  183.             {
  184.             /*
  185.              * If the application has some background processing
  186.              * to do, it should perform a piece of it here.  Otherwise
  187.              * you MUST call WaitMessage or you'll screw up ROM-Windows
  188.              * power-management.
  189.              */
  190.  
  191.             WaitMessage();
  192.             }
  193.         }
  194.  
  195.     return *pf;
  196.     }
  197.  
  198.  
  199.  
  200.  
  201.  
  202. #endif //MAKEOLESERVER
  203.