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 / framer / framer.h < prev    next >
C/C++ Source or Header  |  1997-08-12  |  6KB  |  225 lines

  1. /*
  2.  * FRAMER.H
  3.  * Document Objects Framer
  4.  * Definitions of classes, constants, etc.
  5.  * Includes in-line implementation of CHourGlass, CWindow
  6.  *
  7.  * Copyright (c)1995-1997 Microsoft Corporation, All Rights Reserved
  8.  */
  9.  
  10.  
  11. #ifndef _FRAMER_H_
  12. #define _FRAMER_H_
  13.  
  14. #define INC_OLE2
  15. #include <docobj.h>
  16.  
  17.  
  18. #include <tchar.h>
  19. #ifdef UNICODE
  20. #include <wchar.h>
  21. #endif
  22.  
  23. extern "C"
  24.     {
  25.     #include <commdlg.h>
  26.     }
  27.  
  28.  
  29. #include "resource.h"
  30.  
  31.  
  32. //DeleteInterfaceImp calls 'delete' and NULLs the pointer
  33. #define DeleteInterfaceImp(p)\
  34.             {\
  35.             if (NULL!=p)\
  36.                 {\
  37.                 delete p;\
  38.                 p=NULL;\
  39.                 }\
  40.             }
  41.  
  42.  
  43. //ReleaseInterface calls 'Release' and NULLs the pointer
  44. #define ReleaseInterface(p)\
  45.             {\
  46.             IUnknown *pt=(IUnknown *)p;\
  47.             p=NULL;\
  48.             if (NULL!=pt)\
  49.                 pt->Release();\
  50.             }
  51.  
  52.  
  53.  
  54. class CHourglass;
  55. class CFrame;
  56. class CSite;
  57.  
  58.  
  59. /**
  60.  ** CFrame encapsulates a main application window
  61.  **/
  62.  
  63. //FRAMEWIN.CPP:  Standard window procedure and AboutProc
  64. LRESULT APIENTRY FrameWndProc(HWND, UINT, WPARAM, LPARAM);
  65. LRESULT APIENTRY ClientWndProc(HWND, UINT, WPARAM, LPARAM);
  66. BOOL    APIENTRY AboutProc(HWND, UINT, WPARAM, LPARAM);
  67.  
  68. #define CBFRAMEWNDEXTRA     sizeof(LONG)
  69. #define FRAMEWL_STRUCTURE   0
  70.  
  71. #define CBCLIENTWNDEXTRA    sizeof(LONG)
  72. #define CLIENTWL_STRUCTURE  0
  73.  
  74. #define SZCLASSFRAME        TEXT("Frame")
  75. #define SZCLASSCLIENT       TEXT("Client")
  76.  
  77.  
  78. //FRAME.CPP:  Frame object that creates a main window
  79.  
  80. class CFrame : public IOleInPlaceFrame, public IOleCommandTarget
  81.     {
  82.     //Let our window procedure look in our private variables.
  83.     friend LRESULT APIENTRY FrameWndProc(HWND, UINT, WPARAM, LPARAM);
  84.     friend LRESULT APIENTRY ClientWndProc(HWND, UINT, WPARAM, LPARAM);
  85.  
  86.     protected:
  87.         HINSTANCE       m_hInst;            //Task instance
  88.         HWND            m_hWnd;             //Window handle of the window
  89.         ULONG           m_cRef; 
  90.  
  91.         HINSTANCE       m_hInstPrev;        //WinMain parameters
  92.         LPTSTR          m_pszCmdLine;
  93.         int             m_nCmdShow;        
  94.  
  95.         HMENU          *m_phMenu;           //Popup menu handles
  96.         HACCEL          m_hAccel;           //Accelerators
  97.         HWND            m_hWndClient;       //Client area window
  98.  
  99.         BOOL            m_fInitialized;     //OleInitialize called?
  100.         IStorage       *m_pIStorage;        //Temp file for all needs
  101.         DWORD           m_dwIDCounter;      //For site IDs
  102.  
  103.         //For menu merging
  104.         HMENU           m_hMenuOrg;         //Original menu
  105.         HMENU           m_hMenuTop;            //Currently shown menu
  106.         HMENU            m_hMenuHelp;        //Special Help menu
  107.         BOOL            m_fUsingOurHelp;    //Help menu in use?
  108.         BOOL            m_fInObjectHelp;    //Object's menu found?
  109.         BOOL            m_fOurMenuShowing;  //Our menu up?        
  110.  
  111.         //Other object needs
  112.         BOOL            m_fHaveObject;      //For menu enabling
  113.         HWND            m_hWndObj;            //UI Active object
  114.  
  115.         class CSite    *m_pSite;            //Site holding object        
  116.         BORDERWIDTHS    m_bwIP;             //In-place tool allocations
  117.         BOOL            m_fInContextHelp;   //In context help mode?
  118.  
  119.         IOleInPlaceActiveObject *m_pIOleIPActiveObject;
  120.  
  121.     protected:
  122.         BOOL    RegisterAllClasses(void);        
  123.         LRESULT OnCommand(HWND, WPARAM, LPARAM);        
  124.         BOOL    OpenDialog(LPTSTR, UINT);
  125.         BOOL    CreateObject(LPTSTR);
  126.         void    ResizeClientWindow(UINT, UINT, UINT, UINT);
  127.  
  128.     public:
  129.         CFrame(HINSTANCE, HINSTANCE, LPSTR, int);
  130.         ~CFrame(void);
  131.  
  132.         inline HINSTANCE Instance(void)
  133.             { return m_hInst; }
  134.  
  135.         inline HWND      Window(void)
  136.             { return m_hWnd; }        
  137.  
  138.         inline HACCEL    Accelerators(void)
  139.             { return m_hAccel; }        
  140.         
  141.         BOOL    Init(UINT, int, int, int, int);
  142.         WPARAM  MessageLoop(void);
  143.         void    Close();        
  144.  
  145.         //Shared IUnknown implementation
  146.         STDMETHODIMP         QueryInterface(REFIID, void **);
  147.         STDMETHODIMP_(ULONG) AddRef(void);
  148.         STDMETHODIMP_(ULONG) Release(void);
  149.  
  150.         //IOleInPlaceFrame implementation
  151.         STDMETHODIMP         GetWindow(HWND *);
  152.         STDMETHODIMP         ContextSensitiveHelp(BOOL);
  153.         STDMETHODIMP         GetBorder(LPRECT);
  154.         STDMETHODIMP         RequestBorderSpace(LPCBORDERWIDTHS);
  155.         STDMETHODIMP         SetBorderSpace(LPCBORDERWIDTHS);
  156.         STDMETHODIMP         SetActiveObject(LPOLEINPLACEACTIVEOBJECT
  157.                                  , LPCOLESTR);
  158.         STDMETHODIMP         InsertMenus(HMENU, LPOLEMENUGROUPWIDTHS);
  159.         STDMETHODIMP         SetMenu(HMENU, HOLEMENU, HWND);
  160.         STDMETHODIMP         RemoveMenus(HMENU);
  161.         STDMETHODIMP         SetStatusText(LPCOLESTR);
  162.         STDMETHODIMP         EnableModeless(BOOL);
  163.         STDMETHODIMP         TranslateAccelerator(LPMSG, WORD);
  164.  
  165.         //IOleCommandTarget
  166.         STDMETHODIMP QueryStatus(const GUID *pguidCmdGroup, ULONG cCmds
  167.             , OLECMD prgCmds[], OLECMDTEXT *pCmdText);
  168.         
  169.         STDMETHODIMP Exec(const GUID *pguidCmdGroup, DWORD nCmdID
  170.             , DWORD nCmdexecopt, VARIANTARG *pvaIn, VARIANTARG *pvaOut);            
  171.     };
  172.  
  173.  
  174. typedef CFrame *PCFrame;
  175.  
  176.  
  177.  
  178. /**
  179.  ** CHourglass:  Manages the hourglass and mouse capture
  180.  **/
  181.  
  182. class CHourglass
  183.     {
  184.     protected:
  185.         HWND            m_hWndCapture;      //Window with capture
  186.         HCURSOR         m_hCur;             //Cursor held.
  187.  
  188.     public:
  189.         CHourglass(void)
  190.             {
  191.             m_hCur=SetCursor(LoadCursor(NULL, IDC_WAIT));
  192.             m_hWndCapture=NULL;
  193.             return;
  194.             }
  195.  
  196.         CHourglass(HWND hWnd)
  197.             {
  198.             m_hCur=SetCursor(LoadCursor(NULL, IDC_WAIT));
  199.  
  200.             if (NULL!=hWnd)
  201.                 {
  202.                 m_hWndCapture=hWnd;
  203.                 SetCapture(hWnd);
  204.                 }
  205.  
  206.             return;
  207.             }
  208.  
  209.         ~CHourglass(void)
  210.             {
  211.             if (NULL!=m_hWndCapture)
  212.                 ReleaseCapture();
  213.  
  214.             SetCursor(m_hCur);
  215.             return;
  216.             }
  217.     };
  218.  
  219. typedef CHourglass *PCHourglass;
  220.  
  221.  
  222. #include "site.h"
  223.  
  224. #endif //_FRAMER_H_
  225.