📄 dsoframer.h
字号:
/***************************************************************************
* DSOFRAMER.H
*
* Developer Support Office ActiveX Document Framer Control Sample
*
* Copyright ?999-2004; Microsoft Corporation. All rights reserved.
* Written by Microsoft Developer Support Office Integration (PSS DSOI)
*
* This code is provided via KB 311765 as a sample. It is not a formal
* product and has not been tested with all containers or servers. Use it
* for educational purposes only.
*
* You have a royalty-free right to use, modify, reproduce and distribute
* this sample application, and/or any modified version, in any way you
* find useful, provided that you agree that Microsoft has no warranty,
* obligations or liability for the code or information provided herein.
*
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
*
* See the EULA.TXT file included in the KB download for full terms of use
* and restrictions. You should consult documentation on MSDN Library for
* possible updates or changes to behaviors or interfaces used in this sample.
*
***************************************************************************/
#ifndef DS_DSOFRAMER_H
#define DS_DSOFRAMER_H
#include "XMLHttpClient.h"
#include "afxinet.h" // ftp
////////////////////////////////////////////////////////////////////
// We compile at level 4 and disable some unnecessary warnings...
//
#pragma warning(push, 4) // Compile at level-4 warnings
#pragma warning(disable: 4100) // unreferenced formal parameter (in OLE this is common)
#pragma warning(disable: 4146) // unary minus operator applied to unsigned type, result still unsigned
#pragma warning(disable: 4268) // const static/global data initialized with compiler generated default constructor
#pragma warning(disable: 4310) // cast truncates constant value
#pragma warning(disable: 4786) // identifier was truncated in the debug information
////////////////////////////////////////////////////////////////////
// Needed include files (both standard and custom)
//
//#include <windows.h>
#include <afxwin.h>
#include <winspool.h>
#include <ole2.h>
#include <olectl.h>
#include <oleidl.h>
#include <objsafe.h>
#include "version.h"
#include "utilities.h"
#include "dsofdocobj.h"
#include ".\lib\dsoframerlib.h"
#include ".\res\resource.h"
#include "msoffice.h"
#define FILE_TYPE_NULL 0
#define FILE_TYPE_WORD 11
#define FILE_TYPE_EXCEL 12
#define FILE_TYPE_PPT 13
#define FILE_TYPE_RTF 14
#define FILE_TYPE_WPS 21
#define FILE_TYPE_PDF 31
#define FILE_TYPE_UNK 127
#define E_OK 0 ;
#define E_NOLOAD -1;//没有装载文件
#define E_NOBOOKMARK -50;
#define E_NOSHEET -51;
#define E_NOSUPPORT -126
#define E_UNKNOW -127;
#define E_EXCEPTIONAL -255;
////////////////////////////////////////////////////////////////////
// Global Variables
//
extern HINSTANCE v_hModule;
extern CRITICAL_SECTION v_csecThreadSynch;
extern HICON v_icoOffDocIcon;
extern ULONG v_cLocks;
extern BOOL v_fUnicodeAPI;
extern BOOL v_fWindows2KPlus;
////////////////////////////////////////////////////////////////////
// Custom Errors - we support a very limited set of custom error messages
//
#define DSO_E_ERR_BASE 0x80041100
#define DSO_E_UNKNOWN 0x80041101 // "An unknown problem has occurred."
#define DSO_E_INVALIDPROGID 0x80041102 // "The ProgID/Template could not be found or is not associated with a COM server."
#define DSO_E_INVALIDSERVER 0x80041103 // "The associated COM server does not support ActiveX Document embedding."
#define DSO_E_COMMANDNOTSUPPORTED 0x80041104 // "The command is not supported by the document server."
#define DSO_E_DOCUMENTREADONLY 0x80041105 // "Unable to perform action because document was opened in read-only mode."
#define DSO_E_REQUIRESMSDAIPP 0x80041106 // "The Microsoft Internet Publishing Provider is not installed, so the URL document cannot be open for write access."
#define DSO_E_DOCUMENTNOTOPEN 0x80041107 // "No document is open to perform the operation requested."
#define DSO_E_INMODALSTATE 0x80041108 // "Cannot access document when in modal condition."
#define DSO_E_NOTBEENSAVED 0x80041109 // "Cannot Save file without a file path."
#define DSO_E_ERR_MAX 0x8004110A
////////////////////////////////////////////////////////////////////
// Custom OLE Command IDs - we use for special tasks
//
#define OLECMDID_GETDATAFORMAT 0x7001 // 28673
#define OLECMDID_SETDATAFORMAT 0x7002 // 28674
////////////////////////////////////////////////////////////////////
// Custom Window Messages (only apply to CDsoFramerControl window proc)
//
#define DSO_WM_ASYNCH_OLECOMMAND (WM_USER + 300)
#define DSO_WM_ASYNCH_STATECHANGE (WM_USER + 301)
// State Flags for DSO_WM_ASYNCH_STATECHANGE:
#define DSO_STATE_MODAL 1
#define DSO_STATE_ACTIVATION 2
#define DSO_STATE_INTERACTIVE 3
////////////////////////////////////////////////////////////////////
// Menu Bar Items
//
#define DSO_MAX_MENUITEMS 16
#define DSO_MAX_MENUNAME_LENGTH 32
#ifndef DT_HIDEPREFIX
#define DT_HIDEPREFIX 0x00100000
#define DT_PREFIXONLY 0x00200000
#endif
////////////////////////////////////////////////////////////////////
// Control Class Factory
//
class CDsoFramerClassFactory : public IClassFactory
{
public:
CDsoFramerClassFactory(): m_cRef(0){}
~CDsoFramerClassFactory(void){}
// IUnknown Implementation
STDMETHODIMP QueryInterface(REFIID riid, void ** ppv);
STDMETHODIMP_(ULONG) AddRef(void);
STDMETHODIMP_(ULONG) Release(void);
// IClassFactory Implementation
STDMETHODIMP CreateInstance(LPUNKNOWN punk, REFIID riid, void** ppv);
STDMETHODIMP LockServer(BOOL fLock);
private:
ULONG m_cRef; // Reference count
};
////////////////////////////////////////////////////////////////////
// CDsoFramerControl -- Main Control (OCX) Object
//
// The CDsoFramerControl control is standard OLE control designed around
// the OCX94 specification. Because we plan on doing custom integration to
// act as both OLE object and OLE host, it does not use frameworks like ATL
// or MFC which would only complicate the nature of the sample.
//
// The control inherits from its automation interface, but uses nested
// classes for all OLE interfaces. This is not a requirement but does help
// to clearly seperate the tasks done by each interface and makes finding
// ref count problems easier to spot since each interface carries its own
// counter and will assert (in debug) if interface is over or under released.
//
// The control is basically a stage for the ActiveDocument embedding, and
// handles any external (user) commands. The task of actually acting as
// a DocObject host is done in the site object CDsoDocObject, which this
// class creates and uses for the embedding.
//
#include <afxcmn.h>
#include "dsoframer.h"
class CDsoFramerControl : public _FramerControl
{
public:
IHTMLDocument2 * m_spDoc;
char m_cPassWord[128];//Excel的只读密码
char m_cPWWrite[128];//Excel的可写密码
int m_nOriginalFileType;// m_clsidObject; // CLSID of the embedded object
char m_cUrl[1024];//保存Http路径
unsigned int m_fInPlaceActive:1; // are we in place active or not?
XMLHttpClient *m_pHttp;
//--------FTP
CFtpConnection *m_pFtpConnection;
CInternetSession * m_pSession;
BOOL m_bConnect ;
CDsoFramerControl(LPUNKNOWN punk);
~CDsoFramerControl(void);
// IUnknown Implementation -- Always delgates to outer unknown...
STDMETHODIMP QueryInterface(REFIID riid, void ** ppv){return m_pOuterUnknown->QueryInterface(riid, ppv);}
STDMETHODIMP_(ULONG) AddRef(void){return m_pOuterUnknown->AddRef();}
STDMETHODIMP_(ULONG) Release(void){return m_pOuterUnknown->Release();}
// IDispatch Implementation
STDMETHODIMP GetTypeInfoCount(UINT* pctinfo);
STDMETHODIMP GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo);
STDMETHODIMP GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId);
STDMETHODIMP Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr);
// _FramerControl Implementation
STDMETHODIMP Activate();
STDMETHODIMP get_ActiveDocument(IDispatch** ppdisp);
STDMETHODIMP CreateNew(BSTR ProgIdOrTemplate);
STDMETHODIMP Open(VARIANT Document, VARIANT ReadOnly, VARIANT ProgId, VARIANT WebUsername, VARIANT WebPassword);
STDMETHODIMP Save(VARIANT SaveAsDocument, VARIANT OverwriteExisting, VARIANT WebUsername, VARIANT WebPassword);
STDMETHODIMP _PrintOutOld(VARIANT PromptToSelectPrinter);
STDMETHODIMP Close();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -