FRAMER.H
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:6k
源码类别:

Windows编程

开发平台:

Visual C++

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