⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsoframer.h

📁 主要用于打开office文档而使用. ole开发,
💻 H
📖 第 1 页 / 共 3 页
字号:
    {
        if (m_pDataAdviseHolder) // Send data change notification.
            m_pDataAdviseHolder->SendOnDataChange((IDataObject*)&m_xDataObject, NULL, 0);

        if (m_pViewAdviseSink) // Send the view change notification....
        {
            m_pViewAdviseSink->OnViewChange(DVASPECT_CONTENT, -1);
            if (m_fViewAdviseOnlyOnce) // If they asked to be advised once, kill the connection
                m_xViewObjectEx.SetAdvise(DVASPECT_CONTENT, 0, NULL);
        }
        InvalidateRect(m_hwnd, NULL, TRUE); // Ensure a full repaint...
    }

    void __fastcall GetSizeRectAfterBorder(LPRECT lprcx, LPRECT lprc)
    {
        if (lprcx) CopyRect(lprc, lprcx);
        else SetRect(lprc, 0, 0, m_Size.cx, m_Size.cy);
        if (m_fBorderStyle) InflateRect(lprc, -(4-m_fBorderStyle), -(4-m_fBorderStyle));
    }

    void __fastcall GetSizeRectAfterTitlebar(LPRECT lprcx, LPRECT lprc)
    {
        GetSizeRectAfterBorder(lprcx, lprc);
        if (m_fShowTitlebar) lprc->top += 21;
    }

    void __fastcall GetSizeRectForMenuBar(LPRECT lprcx, LPRECT lprc)
    {
        GetSizeRectAfterTitlebar(lprcx, lprc);
        lprc->bottom = lprc->top + 24;
    }

    void __fastcall GetSizeRectForDocument(LPRECT lprcx, LPRECT lprc)
    {
        GetSizeRectAfterTitlebar(lprcx, lprc);
        if (m_fShowMenuBar) lprc->top += 24; 
        if (lprc->top > lprc->bottom) lprc->top = lprc->bottom;
    }


    void __fastcall RedrawCaption()
    {
        RECT rcT;
        if ((m_hwnd) && (m_fShowTitlebar))
        {   GetClientRect(m_hwnd, &rcT); rcT.bottom = 21;
            InvalidateRect(m_hwnd, &rcT, FALSE);
        }
        if ((m_hwnd) && (m_fShowMenuBar))
        {   GetSizeRectForMenuBar(NULL, &rcT);
            InvalidateRect(m_hwnd, &rcT, FALSE);
        }
    }

	BOOL __fastcall FUseFrameHook(){return (m_lHookPolicy != dsoDisableHook);};
	BOOL __fastcall FDelayFrameHookSet(){return (m_lHookPolicy == dsoSetOnFirstOpen);};

    BOOL __fastcall FDrawBitmapOnAppDeactive(){return (!(m_lActivationPolicy & dsoKeepUIActiveOnAppDeactive));}
	BOOL __fastcall FChangeObjActiveOnFocusChange(){return (m_lActivationPolicy & dsoCompDeactivateOnLostFocus);};
    BOOL __fastcall FIPDeactivateOnCompChange(){return (m_lActivationPolicy & dsoIPDeactivateOnCompDeactive);};

 // The control window proceedure is handled through static class method.
    static STDMETHODIMP_(LRESULT) ControlWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

 // Force redaw of all child windows...
	STDMETHODIMP_(BOOL) InvalidateAllChildWindows(HWND hwnd);
	static STDMETHODIMP_(BOOL) InvalidateAllChildWindowsCallback(HWND hwnd, LPARAM lParam);

 // The variables for the control are kept private but accessible to the
 // nested classes for each interface.
private:

    ULONG                   m_cRef;				   // Reference count
    IUnknown               *m_pOuterUnknown;       // Outer IUnknown (points to m_xInternalUnknown if not agg)
    ITypeInfo              *m_ptiDispType;         // ITypeInfo Pointer (IDispatch Impl)
    EXCEPINFO              *m_pDispExcep;          // EXCEPINFO Pointer (IDispatch Impl)

    HWND                    m_hwnd;                // our window
    HWND                    m_hwndParent;          // immediate parent window
    SIZEL                   m_Size;                // the size of this control  
    RECT                    m_rcLocation;          // where we at

    IOleClientSite         *m_pClientSite;         // active client site of host containter
    IOleControlSite        *m_pControlSite;        // control site
    IOleInPlaceSite        *m_pInPlaceSite;        // inplace site
    IOleInPlaceFrame       *m_pInPlaceFrame;       // inplace frame
    IOleInPlaceUIWindow    *m_pInPlaceUIWindow;    // inplace ui window

    IAdviseSink            *m_pViewAdviseSink;     // advise sink for view (only 1 allowed)
    IOleAdviseHolder       *m_pOleAdviseHolder;    // OLE advise holder (for oleobject sinks)
    IDataAdviseHolder      *m_pDataAdviseHolder;   // OLE data advise holder (for dataobject sink)
    IDispatch              *m_dispEvents;          // event sink (we only support 1 at a time)
    IStorage               *m_pOleStorage;         // IStorage for OLE hosts.

    CDsoDocObject          *m_pDocObjFrame;        // The Embedding Class
    CDsoDocObject          *m_pServerLock;         // Optional Server Lock for out-of-proc DocObject

    OLE_COLOR               m_clrBorderColor;      // Control Colors
    OLE_COLOR               m_clrBackColor;        // "
    OLE_COLOR               m_clrForeColor;        // "
    OLE_COLOR               m_clrTBarColor;        // "
    OLE_COLOR               m_clrTBarTextColor;    // "

    BSTR                    m_bstrCustomCaption;   // A custom caption (if provided)
    HMENU                   m_hmenuFilePopup;      // The File menu popup
	HMENU                   m_hmenuDefinePopup;    // The Define menu popup [create dengll 08.07.07]
    WORD                    m_wFileMenuFlags;      // Bitflags of enabled file menu items.
	WORD                    m_wDefineMenuFlags;      // Create dengll 08.07.08
    WORD                    m_wSelMenuItem;        // Which item (if any) is selected
    WORD                    m_cMenuItems;          // Count of items on menu bar
    RECT                    m_rgrcMenuItems[DSO_MAX_MENUITEMS]; // Menu bar items
    CHAR                    m_rgchMenuAccel[DSO_MAX_MENUITEMS]; // Menu bar accelerators
    LPWSTR                  m_pwszHostName;        // Custom name for SetHostNames

    class CDsoFrameHookManager*  m_pHookManager;   // Frame Window Hook Manager Class
	LONG                    m_lHookPolicy;         // Policy on how to use frame hook for this host.
	LONG                    m_lActivationPolicy;   // Policy on activation behavior for comp focus
	HBITMAP                 m_hbmDeactive;         // Bitmap used for IPDeactiveOnXXX policies
    UINT                    m_uiSyncPaint;         // Sync paint counter for draw issues with UIDeactivateOnXXX

    unsigned int        m_fDirty:1;                // does the control need to be resaved?
    unsigned int        m_fInPlaceActive:1;        // are we in place active or not?
    unsigned int        m_fInPlaceVisible:1;       // we are in place visible or not?
    unsigned int        m_fUIActive:1;             // are we UI active or not.
    unsigned int        m_fHasFocus:1;             // do we have current focus.
    unsigned int        m_fViewAdvisePrimeFirst: 1;// for IViewobject2::setadvise
    unsigned int        m_fViewAdviseOnlyOnce: 1;  // for IViewobject2::setadvise
    unsigned int        m_fUsingWindowRgn:1;       // for SetObjectRects and clipping
    unsigned int        m_fFreezeEvents:1;         // should events be frozen?
    unsigned int        m_fDesignMode:1;           // are we in design mode?
    unsigned int        m_fModeFlagValid:1;        // has mode changed since last check?
    unsigned int        m_fBorderStyle:2;          // the border style
    unsigned int        m_fShowTitlebar:1;         // should we show titlebar?
    unsigned int        m_fShowToolbars:1;         // should we show toolbars?
    unsigned int        m_fModalState:1;           // are we modal?
    unsigned int        m_fObjectMenu:1;           // are we over obj menu item?
    unsigned int        m_fConCntDone:1;           // for enum connectpts
    unsigned int        m_fAppActive:1;            // is the app active?
    unsigned int        m_fComponentActive:1;      // is the component active?
    unsigned int        m_fShowMenuBar:1;          // should we show menubar?
    unsigned int        m_fInDocumentLoad:1;       // set when loading file
    unsigned int        m_fNoInteractive:1;        // set when we don't allow interaction with docobj
    unsigned int        m_fShowMenuPrev:1;         // were menus visible before loss of interactivity?
    unsigned int        m_fShowToolsPrev:1;        // were toolbars visible before loss of interactivity?
    unsigned int        m_fSyncPaintTimer:1;       // is syncpaint timer running?
    unsigned int        m_fInControlActivate:1;    // is currently in activation call?
    unsigned int        m_fInFocusChange:1;        // are we in a focus change?
    unsigned int        m_fActivateOnStatus:1;     // we need to activate on change of status 
    unsigned int        m_fDisableMenuAccel:1;     // using menu accelerators
    unsigned int        m_fBkgrdPaintTimer:1;      // using menu accelerators

};


////////////////////////////////////////////////////////////////////
// CDsoFrameWindowHook -- Frame Window Hook Class
//
//  Used by the control to allow for proper host notification of focus 
//  and activation events occurring at top-level window frame. Because 
//  this DocObject host is an OCX, we don't own these notifications and
//  have to "steal" them from our parent using a subclass.
//
//  IMPORTANT: Since the parent frame may exist on a separate thread, this
//  class does nothing but the hook. The code to notify the active component
//  is in a separate global class that is shared by all threads.
//
class CDsoFrameWindowHook
{
public:
	CDsoFrameWindowHook(){ODS("CDsoFrameWindowHook created\n");m_cHookCount=0;m_hwndTopLevelHost=NULL;m_pfnOrigWndProc=NULL;m_fHostUnicodeWindow=FALSE;}
	~CDsoFrameWindowHook(){ODS("CDsoFrameWindowHook deleted\n");}

	static STDMETHODIMP_(CDsoFrameWindowHook*) AttachToFrameWindow(HWND hwndParent);
	STDMETHODIMP Detach();

	static STDMETHODIMP_(CDsoFrameWindowHook*) GetHookFromWindow(HWND hwnd);
	inline STDMETHODIMP_(void) AddRef(){InterlockedIncrement((LONG*)&m_cHookCount);}

    static STDMETHODIMP_(LRESULT) 
		HostWindowProcHook(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

protected:
	DWORD                   m_cHookCount;
	HWND                    m_hwndTopLevelHost;    // Top-level host window (hooked)
    WNDPROC                 m_pfnOrigWndProc;
	BOOL                    m_fHostUnicodeWindow;
};

// THE MAX NUMBER OF DSOFRAMER CONTROLS PER PROCESS
#define DSOF_MAX_CONTROLS   10

////////////////////////////////////////////////////////////////////
// CDsoFrameHookManager -- Hook Manager Class
//
//  Used to keep track of which control is active and forward notifications
//  to it using window messages (to cross thread boundaries).  
//
class CDsoFrameHookManager
{
public:
	CDsoFrameHookManager(){ODS("CDsoFrameHookManager created\n"); m_fAppActive=TRUE; m_idxActive=DSOF_MAX_CONTROLS; m_cComponents=0;}
	~CDsoFrameHookManager(){ODS("CDsoFrameHookManager deleted\n");}

	static STDMETHODIMP_(CDsoFrameHookManager*)
		RegisterFramerControl(HWND hwndParent, HWND hwndControl);

	STDMETHODIMP AddComponent(HWND hwndParent, HWND hwndControl);
	STDMETHODIMP DetachComponent(HWND hwndControl);
	STDMETHODIMP SetActiveComponent(HWND hwndControl);
	STDMETHODIMP OnComponentNotify(DWORD msg, WPARAM wParam, LPARAM lParam);

	inline STDMETHODIMP_(HWND)
		GetActiveComponentWindow(){return m_pComponents[m_idxActive].hwndControl;}

	inline STDMETHODIMP_(CDsoFrameWindowHook*)
		GetActiveComponentFrame(){return m_pComponents[m_idxActive].phookFrame;}

	STDMETHODIMP_(BOOL) SendNotifyMessage(HWND hwnd, DWORD msg, WPARAM wParam, LPARAM lParam);

protected:
	BOOL                    m_fAppActive;
	DWORD                   m_idxActive;
	DWORD                   m_cComponents;
    struct FHOOK_COMPONENTS
	{
		HWND hwndControl;
		CDsoFrameWindowHook *phookFrame;
	}                       m_pComponents[DSOF_MAX_CONTROLS];
};

#endif //DS_DSOFRAMER_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -