viewhelp思密达是什么意思思

1798人阅读
& & MFC之所以为应用程序框架,最重要的特征就是他能够将管理数据的程序代码和负责数据显示的程序代码分离开来。这种能力由文档视图结构提供。在的中被实例化,它本身就是一个空壳,当开发自己的程序时,应该从派生出一个属于自己的类,并且在类中声明一些成员变量,用以容纳数据。然后再改写函数,派生自类,所以它具有所支持的一切性质,包括运行时类型识别,动态创建,文件读写,又由于它派生自,所以它可以接受来自菜单或工具栏的消息。
&&&&CView负责数据的显示。本身并无用途,它也是提供了一个空壳,当开发程序时,应该从派生出一个属于自己的类,并且在类中改写负责数据显示的函数。由于派生自因此它可以接受一般的消息,又由于它派生自,所以它可以接收来自菜单或工具栏的消息。
&&&&View是一个没有边框的窗口,其外围还有一个窗口。
&&&&CDocTemplate负责管理、和。它有两个派生类,分别为:,。如果程序能够处理两种以上的数据,就必须构造两个出来,然后调用将它们加入到系统之中。这和程序是不是没有关系。如果程序支持多种数据类型,但是是那只是每次只能打开一个文件罢了,可以同时打开多个。
&&&&CDocTemplate用以管理,和。而管理。在中构建:
Bool&CMyWinApp::InitInstance()
&&&&CMultiDocTemplate&*pDocTemplate=new&CMultiDocTemplate(
&&&&&&&&&&&&IDR_SCRIBYTEP,
&&&&&&&&&&&&RUNTIME_CLASS(CMyDoc),
&&&&&&&&&&&&RUNTIME_CLASS(CChildFrame),
&&&&&&&&&&&&RUNTIME_CLASS(CMyView);
&&&&&&AddDocTemplate(pDocTemplate);
&&&&注意构造对象和产生窗口之间的区别。类用于管理窗口,它内部含有要产生的窗口的句柄,因此必须首先构造对象,在调用该类的成员函数如函数产生窗口。
&&&&由于在构建时,传递的是,和的结构,在内部,会构建调用各自类的构建函数构建这三个对象。这是在::内实现的。
&&&&当使用者单击,函数被调用,然后它又调用::后者又调用::此函数调用动态创建,调用动态产生。然而的产生就没有这么显而易见了,首先的创建发出消息,是::被调用,经过一些列调用,在最后调用的::内,对象以及窗口都被创建出来。
&&&&CWinApp又有一个指向的指针,它指向类型的对象。
class CWinApp : public CWinThread
DECLARE_DYNAMIC(CWinApp)
// Constructor
/* explicit */ CWinApp(LPCTSTR lpszAppName = NULL);
// app name defaults to EXE name
// Attributes
// Startup args (do not change)
// This module's hInstance.
HINSTANCE m_hI
// Pointer to the command-line.
LPTSTR m_lpCmdL
// Initial state of the application' normally,
// this is an argument to ShowWindow().
int m_nCmdS
// Running args (can be changed in InitInstance)
// Human-redable name of the application. Normally set in
// constructor or retreived from AFX_IDS_APP_TITLE.
LPCTSTR m_pszAppN
/// &summary&
/// Application User Model ID.&/summary&
LPCTSTR m_pszAppID;
// Name of registry key for this application. See
// SetRegistryKey() member function.
LPCTSTR m_pszRegistryK
// Pointer to CDocManager used to manage document templates
// for this application instance.
CDocManager* m_pDocM
// Support for Shift+F1 help mode.
// TRUE if we're in SHIFT+F1 mode.
BOOL m_bHelpM
// set in constructor to override default
// Executable name (no spaces).
LPCTSTR m_pszExeN
// Default based on this module's path.
LPCTSTR m_pszHelpFileP
// Default based on this application's name.
LPCTSTR m_pszProfileN
// Sets and initializes usage of HtmlHelp instead of WinHelp.
void EnableHtmlHelp();
// Sets and initializes usage of HtmlHelp instead of WinHelp.
void SetHelpMode( AFX_HELP_TYPE eHelpType );
AFX_HELP_TYPE GetHelpMode();
// help mode used by the app
AFX_HELP_TYPE m_eHelpT
// Initialization Operations - should be done in InitInstance
protected:
// Load MRU file list and last preview state.
void LoadStdProfileSettings(UINT nMaxMRU = _AFX_MRU_COUNT);
void EnableShellOpen();
// SetDialogBkColor is no longer supported.
// To change dialog background and text color, handle WM_CTLCOLORDLG instead.
AFX_DEPRECATED(&CWinApp::SetDialogBkColor is no longer supported. Instead, handle WM_CTLCOLORDLG in your dialog&)
void SetDialogBkColor(COLORREF clrCtlBk = RGB(192, 192, 192), COLORREF clrCtlText = RGB(0, 0, 0));
// Set registry key name to be used by CWinApp's
// prof prevents writing to an INI file.
void SetRegistryKey(LPCTSTR lpszRegistryKey);
void SetRegistryKey(UINT nIDRegistryKey);
/// &summary&
/// Explicitly sets Application User Model ID for the application. This method should be called before any user interface
/// is presented to user (the best place is the application constructor).&/summary&
/// &param name=&lpcszAppID&&Specifies the Application User Model ID.&/param&
void SetAppID(LPCTSTR lpcszAppID);
// Enable3dControls and Enable3dControlsStatic are no longer necessary.
AFX_DEPRECATED(&CWinApp::Enable3dControls is no longer needed. You should remove this call.&)
BOOL Enable3dControls();
#ifndef _AFXDLL
AFX_DEPRECATED(&CWinApp::Enable3dControlsStatic is no longer needed. You should remove this call.&)
BOOL Enable3dControlsStatic();
void RegisterShellFileTypes(BOOL bCompat = FALSE);
// call after all doc templates are registered
void UnregisterShellFileTypes();
// Loads a cursor resource.
HCURSOR LoadCursor(LPCTSTR lpszResourceName)
HCURSOR LoadCursor(UINT nIDResource)
// Loads a s for for IDC_* values.
HCURSOR LoadStandardCursor(LPCTSTR lpszCursorName)
// Loads an OEM for all OCR_* values.
HCURSOR LoadOEMCursor(UINT nIDCursor)
// Loads an icon resource.
HICON LoadIcon(LPCTSTR lpszResourceName)
HICON LoadIcon(UINT nIDResource)
// Lo for stock IDI_ values.
HICON LoadStandardIcon(LPCTSTR lpszIconName)
// Loads an OEM for all OIC_* values.
HICON LoadOEMIcon(UINT nIDIcon)
// Retrieve an integer value from INI file or registry.
virtual UINT GetProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nDefault);
// Sets an integer value to INI file or registry.
virtual BOOL WriteProfileInt(LPCTSTR lpszSection, LPCTSTR lpszEntry, int nValue);
// Retrieve a string value from INI file or registry.
virtual CString GetProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszDefault = NULL);
// Sets a string value to INI file or registry.
virtual BOOL WriteProfileString(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPCTSTR lpszValue);
// Retrieve an arbitrary binary value from INI file or registry.
virtual BOOL GetProfileBinary(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPBYTE* ppData, UINT* pBytes);
// Sets an arbitrary binary value to INI file or registry.
virtual BOOL WriteProfileBinary(LPCTSTR lpszSection, LPCTSTR lpszEntry, LPBYTE pData, UINT nBytes);
// Override in derived class.
virtual void InitLibId();
// Register
virtual BOOL Register();
// Unregisters everything this app was known to register.
virtual BOOL Unregister();
/// &summary&
/// Deletes the subkeys and values of the specified key recursively.&/summary&
/// &returns&
/// If the function succeeds, the return value is ERROR_SUCCESS. If the function fails, the return value is a nonzero error code defined in Winerror.h&/returns&
/// &param name=&hParentKey&&A handle to an open registry key.&/param&
/// &param name=&strKeyName&&The name of the key to be deleted.&/param&
/// &param name=&pTM&&Pointer to CAtlTransactionManager object&/param&
LONG DelRegTree(HKEY hParentKey, const CString& strKeyName, CAtlTransactionManager* pTM = NULL);
// Running Operations - to be done on a running application
// Dealing with document templates
void AddDocTemplate(CDocTemplate* pTemplate);
POSITION GetFirstDocTemplatePosition()
CDocTemplate* GetNextDocTemplate(POSITION& pos)
// Open named file, trying to match a regsitered
// document template to it.
virtual CDocument* OpenDocumentFile(LPCTSTR lpszFileName);
virtual CDocument* OpenDocumentFile(LPCTSTR lpszFileName, BOOL bAddToMRU);
// Add a string to the recent file list. Remove oldest string,
// if no space left.
virtual void AddToRecentFileList(LPCTSTR lpszPathName);
// Printer DC Setup routine, 'struct tagPD' is a PRINTDLG structure.
void SelectPrinter(HANDLE hDevNames, HANDLE hDevMode,
BOOL bFreeOld = TRUE);
// Create a DC for the system default printer.
BOOL CreatePrinterDC(CDC& dc);
BOOL GetPrinterDeviceDefaults(PRINTDLG* pPrintDlg);
// Run this app as an embedded object.
BOOL RunEmbedded();
// Run this app as an OLE automation server.
BOOL RunAutomated();
// Parse the command line for stock options and commands.
void ParseCommandLine(CCommandLineInfo& rCmdInfo);
// React to a shell-issued command line directive.
BOOL ProcessShellCommand(CCommandLineInfo& rCmdInfo);
// Overridables
// Hooks for your initialization code
virtual BOOL InitApplication();
// exiting
virtual BOOL SaveAllModified(); // save before exit
void HideApplication();
void CloseAllDocuments(BOOL bEndSession); // close documents before exiting
// Advanced: to override message boxes and other hooks
virtual int DoMessageBox(LPCTSTR lpszPrompt, UINT nType, UINT nIDPrompt);
virtual void DoWaitCursor(int nCode); // 0 =& restore, 1=& begin, -1=& end
// Advanced: process async DDE request
virtual BOOL OnDDECommand(_In_z_ LPTSTR lpszCommand);
// Advanced: Help support
virtual void WinHelp(DWORD_PTR dwData, UINT nCmd = HELP_CONTEXT);
virtual void HtmlHelp(DWORD_PTR dwData, UINT nCmd = 0x000F);
virtual void WinHelpInternal(DWORD_PTR dwData, UINT nCmd = HELP_CONTEXT);
// Restart Manager support
virtual HRESULT RegisterWithRestartManager(BOOL bRegisterRecoveryCallback, const CString &strRestartIdentifier);
virtual HRESULT RegisterWithRestartManager(LPCWSTR pwzCommandLineArgs, DWORD dwRestartFlags, APPLICATION_RECOVERY_CALLBACK pRecoveryCallback, LPVOID lpvParam, DWORD dwPingInterval, DWORD dwCallbackFlags);
virtual DWORD ApplicationRecoveryCallback(LPVOID lpvParam);
virtual BOOL SupportsRestartManager() const { return m_dwRestartManagerSupportFlags & AFX_RESTART_MANAGER_SUPPORT_RESTART; }
virtual BOOL SupportsApplicationRecovery() const { return m_dwRestartManagerSupportFlags & AFX_RESTART_MANAGER_SUPPORT_RECOVERY; }
virtual BOOL SupportsAutosaveAtRestart() const { return m_dwRestartManagerSupportFlags & AFX_RESTART_MANAGER_AUTOSAVE_AT_RESTART; }
virtual BOOL SupportsAutosaveAtInterval() const { return m_dwRestartManagerSupportFlags & AFX_RESTART_MANAGER_AUTOSAVE_AT_INTERVAL; }
virtual BOOL ReopenPreviousFilesAtRestart() const { return m_dwRestartManagerSupportFlags & AFX_RESTART_MANAGER_REOPEN_PREVIOUS_FILES; }
virtual BOOL RestoreAutosavedFilesAtRestart() const { return m_dwRestartManagerSupportFlags & AFX_RESTART_MANAGER_RESTORE_AUTOSAVED_FILES; }
virtual DWORD GetApplicationRestartFlags() { return 0; }
// Flags for RegisterApplicationRestart: default is none of RESTART_NO_CRASH/RESTART_NO_HANG/RESTART_NO_PATCH/RESTART_NO_REBOOT
virtual LPVOID GetApplicationRecoveryParameter() { return NULL; }
// Parameter to be passed along to RegisterApplicationRecoveryCallback
virtual DWORD GetApplicationRecoveryPingInterval() { return RECOVERY_DEFAULT_PING_INTERVAL; }
// Ping interval for RegisterApplicationRecoveryCallback
// Command Handlers
protected:
// map to the following for file new/open
afx_msg void OnFileNew();
afx_msg void OnFileOpen();
// map to the following to enable print setup
afx_msg void OnFilePrintSetup();
// map to the following to enable help
afx_msg void OnContextHelp();
// shift-F1
afx_msg void OnHelp();
// F1 (uses current context)
afx_msg void OnHelpIndex();
// ID_HELP_INDEX
afx_msg void OnHelpFinder();
// ID_HELP_FINDER, ID_DEFAULT_HELP
afx_msg void OnHelpUsing();
// ID_HELP_USING
// Implementation
protected:
HGLOBAL m_hDevM
// printer Dev Mode
HGLOBAL m_hDevN
// printer Device Names
DWORD m_dwPromptC
// help context override for message box
HINSTANCE m_hLangResourceDLL;
// Satellite resource DLL
int m_nWaitCursorC
// for wait cursor (&0 =& waiting)
HCURSOR m_hcurWaitCursorR // old cursor to restore after wait cursor
CRecentFileList* m_pRecentFileL
CDataRecoveryHandler* m_pDataRecoveryH
void UpdatePrinterSelection(BOOL bForceDefaults);
void SaveStdProfileSettings();
// save options to .INI file
public: // public for implementation access
CCommandLineInfo* m_pCmdI
ATOM m_atomApp, m_atomSystemT
// for DDE open
UINT m_nNumPreviewP
// number of default printed pages
m_nSafetyPoolS
// ideal size
void (AFXAPI* m_lpfnDaoTerm)();
void DevModeChange(_In_z_ LPTSTR lpDeviceName);
void SetCurrentHandles();
// Finds number of opened CDocument items owned by templates
// registered with the doc manager.
int GetOpenDocumentCount();
virtual CDataRecoveryHandler *GetDataRecoveryHandler();
/// &summary&
/// Tells whether Windows 7 Taskbar interaction is enabled.&/summary&
/// &returns&
/// Returns TRUE if EnableTaskbarInteraction has been called and Operation System is
/// Windows 7 or higher.&/returns&
/// &remarks& Taskbar interaction means that MDI application displays the content of MDI children
/// in separate tabbed thumbnails that appear when mouse pointer is over application taskbar button.&/remarks&
virtual BOOL IsTaskbarInteractionEnabled();
/// &summary&
/// Enables Taskbar interaction&/summary&
/// &returns&
/// Returns TRUE if taskbar interaction can be enabled or disabled (e.g. this method was called before creation of main window).&/returns&
/// &remarks&
/// This method must be called before creation of main window, otherwise it asserts and returns FALSE.&/remarks&
/// &param name=&bEnable&& Specifies whether interaction with Windows 7 taskbar should be enabled (TRUE), or disabled (FALSE).&/param&
BOOL EnableTaskbarInteraction(BOOL bEnable = TRUE);
// helpers for standard commdlg dialogs
BOOL DoPromptFileName(CString& fileName, UINT nIDSTitle,
DWORD lFlags, BOOL bOpenFileDialog, CDocTemplate* pTemplate);
INT_PTR DoPrintDialog(CPrintDialog* pPD);
void EnableModeless(BOOL bEnable); // to disable OLE in-place dialogs
// overrides for implementation
virtual BOOL InitInstance();
virtual int ExitInstance(); // return app exit code
virtual BOOL RestartInstance(); // handle restart by Restart Manager
virtual int Run();
virtual BOOL OnIdle(LONG lCount); // return TRUE if more idle processing
virtual LRESULT ProcessWndProcException(CException* e, const MSG* pMsg);
virtual HINSTANCE LoadAppLangResourceDLL();
// Help can work when no CWinApp can be found
static int ShowAppMessageBox(CWinApp *pApp, LPCTSTR lpszPrompt, UINT nType, UINT nIDPrompt);
static void DoEnableModeless(BOOL bEnable); // to disable OLE in-place dialogs
virtual ~CWinApp();
#ifdef _DEBUG
virtual void AssertValid()
virtual void Dump(CDumpContext& dc)
// helpers for registration
/// &summary&
/// returns key for HKEY_CURRENT_USER\&Software&\RegistryKey\AppName\lpszSection.&/summary&
/// &returns&
/// Section key if the function succeeds, NULL - otherwise&/returns&
/// &param name=&lpszSection&&The name of the key to be obtained.&/param&
/// &param name=&pTM&&Pointer to CAtlTransactionManager object&/param&
HKEY GetSectionKey(LPCTSTR lpszSection, CAtlTransactionManager* pTM = NULL);
/// &summary&
/// returns key for HKEY_CURRENT_USER\&Software&\RegistryKey\ProfileName.&/summary&
/// &returns&
/// Applixation key if the function succeeds, NULL - otherwise&/returns&
/// &param name=&pTM&&Pointer to CAtlTransactionManager object&/param&
HKEY GetAppRegistryKey(CAtlTransactionManager* pTM = NULL);
/// &summary&
/// Enable application D2D support. This method should be called prior to initialization of the main window .&/summary&
/// &returns&
/// Returns TRUE if D2D support was enabled, FALSE - otherwise&/returns&
/// &param name=&d2dFactoryType&&The threading model of the D2D factory and the resources it creates.&/param&
/// &param name=&writeFactoryType&&A value that specifies whether the write factory object will be shared or isolated&/param&
BOOL EnableD2DSupport(D2D1_FACTORY_TYPE d2dFactoryType = D2D1_FACTORY_TYPE_SINGLE_THREADED, DWRITE_FACTORY_TYPE writeFactoryType = DWRITE_FACTORY_TYPE_SHARED);
protected:
//{{AFX_MSG(CWinApp)
afx_msg void OnAppExit();
afx_msg void OnUpdateRecentFileMenu(CCmdUI* pCmdUI);
afx_msg BOOL OnOpenRecentFile(UINT nID);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
// System Policy Settings
virtual BOOL LoadSysPolicies(); // Override to load policies other than the system policies that MFC loads.
BOOL GetSysPolicyValue(DWORD dwPolicyID, BOOL *pbValue); // returns the policy's setting in the out parameter
protected :
BOOL _LoadSysPolicies() throw(); // Implementation helper
DWORD m_dwP
// block for storing boolean system policies
// Restart Manager support
DWORD m_dwRestartManagerSupportF // What aspects of restart/recovery does the application support?
m_nAutosaveI
// How frequently are documents autosaved? (value in milliseconds)
BOOL m_bTaskbarInteractionE
& & 在类中,有一个指针链表,用来维护一系列的,如果一个程序支持两种以上的文件类型,那么就应该调用将加入到链表中。
class CDocManager : public CObject
DECLARE_DYNAMIC(CDocManager)
// Constructor
CDocManager();
//Document functions
virtual void AddDocTemplate(CDocTemplate* pTemplate);
virtual POSITION GetFirstDocTemplatePosition()
virtual CDocTemplate* GetNextDocTemplate(POSITION& pos)
virtual void RegisterShellFileTypes(BOOL bCompat);
void UnregisterShellFileTypes();
virtual CDocument* OpenDocumentFile(LPCTSTR lpszFileName); // open named file
virtual CDocument* OpenDocumentFile(LPCTSTR lpszFileName, BOOL bAddToMRU); // open named file
virtual BOOL SaveAllModified(); // save before exit
virtual void CloseAllDocuments(BOOL bEndSession); // close documents before exiting
virtual int GetOpenDocumentCount();
virtual CDocTemplate* GetBestTemplate(LPCTSTR lpszFileName); // return best template named file
// helper for standard commdlg dialogs
virtual BOOL DoPromptFileName(CString& fileName, UINT nIDSTitle,
DWORD lFlags, BOOL bOpenFileDialog, CDocTemplate* pTemplate);
//Commands
// Advanced: process async DDE request
virtual BOOL OnDDECommand(_In_z_ LPTSTR lpszCommand);
virtual void OnFileNew();
virtual void OnFileOpen();
// Implementation
protected:
CPtrList m_templateL
int GetDocumentCount(); // helper to count number of total documents
static CPtrList* pStaticL
// for static CDocTemplate objects
static BOOL bStaticI
// TRUE during static initialization
static CDocManager* pStaticDocM
// for static CDocTemplate objects
virtual ~CDocManager();
#ifdef _DEBUG
virtual void AssertValid()
virtual void Dump(CDumpContext& dc)
&&&&CDocTemplate拥有三个成员变量,分别为指向和的指针,另一个成员为。用来表示此显现时应该使用的对象。这四个成员应该在
CMyWinApp::InitInstance中构造时指定。然后可以借助这些参数,动态构建,和。
class AFX_NOVTABLE CDocTemplate : public CCmdTarget
DECLARE_DYNAMIC(CDocTemplate)
// Constructors
protected:
CDocTemplate(UINT nIDResource, CRuntimeClass* pDocClass,
CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass);
virtual void LoadTemplate();
// Attributes
// setup for OLE containers
void SetContainerInfo(UINT nIDOleInPlaceContainer);
// setup for OLE servers
void SetServerInfo(UINT nIDOleEmbedding, UINT nIDOleInPlaceServer = 0,
CRuntimeClass* pOleFrameClass = NULL, CRuntimeClass* pOleViewClass = NULL);
/// &summary&
/// Setups out of process preview handler. &/summary&
/// &param name=&nIDPreviewFrame&&Specifies a resource ID of preview frame.&/param&
/// &param name=&pPreviewFrameClass&&Specifies a pointer to a runtime class information of preview frame.&/param&
/// &param name=&pPreviewViewClass&&Specifies a pointer to a runtime class information of preview view.&/param&
void SetPreviewInfo(UINT nIDPreviewFrame, CRuntimeClass* pPreviewFrameClass = NULL, CRuntimeClass* pPreviewViewClass = NULL);
// iterating over open documents
virtual POSITION GetFirstDocPosition() const = 0;
virtual CDocument* GetNextDoc(POSITION& rPos) const = 0;
// Operations
virtual void AddDocument(CDocument* pDoc);
// must override
virtual void RemoveDocument(CDocument* pDoc);
// must override
enum DocStringIndex
windowTitle,
// default window title
// user visible name for default document
fileNewName,
// user visible name for FileNew
// for file based documents:
filterName,
// user visible name for FileOpen
filterExt,
// user visible extension for FileOpen
// for file based documents with Shell open support:
regFileTypeId,
// REGEDIT visible registered file type identifier
regFileTypeName,
// Shell visible registered file type name
virtual BOOL GetDocString(CString& rString,
enum DocStringIndex index) // get one of the info strings
CFrameWnd* CreateOleFrame(CWnd* pParentWnd, CDocument* pDoc,
BOOL bCreateView);
/// &summary&
/// Creates a child frame used for Rich Preview.&/summary&
/// &returns& A valid pointer to a CFrameWnd object, or NULL if creation fails. &/returns&
/// &param name=&pParentWnd&& A pointer to a parent window (usually provided by the Shell).&/param&
/// &param name=&pDoc&& A pointer to a document object, whose content will be previewed. &/param&
CFrameWnd* CreatePreviewFrame(CWnd* pParentWnd, CDocument* pDoc);
// Overridables
enum Confidence
noAttempt,
maybeAttemptForeign,
maybeAttemptNative,
yesAttemptForeign,
yesAttemptNative,
yesAlreadyOpen
virtual Confidence MatchDocType(LPCTSTR lpszPathName,
CDocument*& rpDocMatch);
virtual CDocument* CreateNewDocument();
virtual CFrameWnd* CreateNewFrame(CDocument* pDoc, CFrameWnd* pOther);
virtual void InitialUpdateFrame(CFrameWnd* pFrame, CDocument* pDoc,
BOOL bMakeVisible = TRUE);
virtual BOOL SaveAllModified();
// for all documents
virtual void CloseAllDocuments(BOOL bEndSession);
// if lpszPathName == NULL =& create new file with this type
virtual CDocument* OpenDocumentFile(LPCTSTR lpszPathName, BOOL bMakeVisible = TRUE) = 0;
virtual CDocument* OpenDocumentFile(LPCTSTR lpszPathName, BOOL bAddToMRU, BOOL bMakeVisible) = 0;
virtual void SetDefaultTitle(CDocument* pDocument) = 0;
// Implementation
BOOL m_bAutoD
virtual ~CDocTemplate() = 0;
// back pointer to OLE or other server (NULL if none or disabled)
CObject* m_pAttachedF
// Class ID for preview handler - used for registration
CString m_strCLSID;
// menu & accelerator resources for in-place container
HMENU m_hMenuInP
HACCEL m_hAccelInP
// menu & accelerator resource for server editing embedding
HMENU m_hMenuE
HACCEL m_hAccelE
// menu & accelerator resource for server editing in-place
HMENU m_hMenuInPlaceS
HACCEL m_hAccelInPlaceS
#ifdef _DEBUG
virtual void Dump(CDumpContext&)
virtual void AssertValid()
virtual void OnIdle();
// for all documents
virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra,
AFX_CMDHANDLERINFO* pHandlerInfo);
protected:
UINT m_nIDR
// IDR_ for frame/menu/accel as well
UINT m_nIDServerR
// IDR_ for OLE inplace frame/menu/accel
UINT m_nIDEmbeddingR
// IDR_ for OLE open frame/menu/accel
UINT m_nIDContainerR
// IDR_ for container frame/menu/accel
UINT m_nIDPreviewR
// IDR_ for preview frame. Do not load menu/accel
CRuntimeClass* m_pDocC
// class for creating new documents
CRuntimeClass* m_pFrameC
// class for creating new frames
CRuntimeClass* m_pViewC
// class for creating new views
CRuntimeClass* m_pOleFrameC
// class for creating in-place frame
CRuntimeClass* m_pOleViewC
// class for creating in-place view
CRuntimeClass* m_pPreviewFrameC // class for creating in-place preview frame
CRuntimeClass* m_pPreviewViewC
// class for creating in-place preview view
CString m_strDocS
// '\n' separated names
// The document names sub-strings are represented as _one_ string:
// windowTitle\ndocName\n ... (see DocStringIndex enum)
// need for preview handler. CDocument finds template by m_pDocClass in order to instantiate related frame/view
friend class CD
& & 如果是单文档程序,就是,此时它有一个成员变量,也就是说它只能打开一份文档。
// SDI support (1 document only)
class CSingleDocTemplate : public CDocTemplate
DECLARE_DYNAMIC(CSingleDocTemplate)
// Constructors
CSingleDocTemplate(UINT nIDResource, CRuntimeClass* pDocClass,
CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass);
// Implementation
virtual ~CSingleDocTemplate();
virtual void AddDocument(CDocument* pDoc);
virtual void RemoveDocument(CDocument* pDoc);
virtual POSITION GetFirstDocPosition()
virtual CDocument* GetNextDoc(POSITION& rPos)
virtual CDocument* OpenDocumentFile(LPCTSTR lpszPathName, BOOL bMakeVisible = TRUE);
virtual CDocument* OpenDocumentFile(LPCTSTR lpszPathName, BOOL bAddToMRU, BOOL bMakeVisible);
virtual void SetDefaultTitle(CDocument* pDocument);
#ifdef _DEBUG
virtual void Dump(CDumpContext&)
virtual void AssertValid()
#endif //_DEBUG
protected:
// standard implementation
CDocument* m_pOnlyD
& & 如果为多文档应用程序,使用的就是它有一个成员变量,此变量为类型,指向一系列打开的文档。
// MDI support (zero or more documents)
class CMultiDocTemplate : public CDocTemplate
DECLARE_DYNAMIC(CMultiDocTemplate)
// Constructors
CMultiDocTemplate(UINT nIDResource, CRuntimeClass* pDocClass,
CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass);
// Implementation
// Menu and accel table for MDI Child windows of this type
HMENU m_hMenuS
HACCEL m_hAccelT
virtual ~CMultiDocTemplate();
virtual void LoadTemplate();
virtual void AddDocument(CDocument* pDoc);
virtual void RemoveDocument(CDocument* pDoc);
virtual POSITION GetFirstDocPosition()
virtual CDocument* GetNextDoc(POSITION& rPos)
virtual CDocument* OpenDocumentFile(LPCTSTR lpszPathName, BOOL bMakeVisible = TRUE);
virtual CDocument* OpenDocumentFile(LPCTSTR lpszPathName, BOOL bAddToMRU, BOOL bMakeVisible);
virtual void SetDefaultTitle(CDocument* pDocument);
#ifdef _DEBUG
virtual void Dump(CDumpContext&)
virtual void AssertValid()
#endif //_DEBUG
protected:
// standard implementation
CPtrList m_docL
// open documents of this type
UINT m_nUntitledC
// start at 0, for &Document1& title
&&&&CDocument有一个成员变量,指向它所属的。另一个成员变量指向它维护的一系列。
class AFX_NOVTABLE CDocument : public CCmdTarget
DECLARE_DYNAMIC(CDocument)
// Constructors
CDocument();
/// &summary&
/// This class implements IDocument interface required for Search and Organize handlers.&/summary&
/// &remarks&
/// Search and Organize handlers are implemented in ATL DLLs, which can be MFC or not-MFC based.
/// Internally handlers refer to IDocument interface, whose implementation in the common case should be
/// supplied by a developer. CDocumentAdapter provides this implementation for MFC and basically calls
/// the appropriate methods of the parent CDocument.&/remarks&
class CDocumentAdapter : public ATL::IDocument
friend class CD
/// &summary&
/// Constructs a CDocumentAdapter object.&/summary&
/// &param name=&pParentDoc&& A pointer to a related document.&/param&
CDocumentAdapter(CDocument* pParentDoc) : m_pParentDoc(pParentDoc)
/// &summary&
/// A destructor. Also deletes a related (parent) CDocument.&/summary&
virtual ~CDocumentAdapter()
if (m_pParentDoc != NULL)
delete m_pParentD
m_pParentDoc = NULL;
/// &summary&
/// Loads document data from a stream &/summary&
/// &returns&
/// S_OK otherwise failed HRESULT.&/returns&
/// &param name=&pStream&&A pointer to a stream. This stream is supplied by the Shell.&/param&
/// &param name=&grfMode&&Access mode to the stream.&/param&
virtual HRESULT LoadFromStream(IStream* pStream, DWORD grfMode)
ASSERT_VALID(m_pParentDoc);
if (m_pParentDoc == NULL)
TRACE0(&CDocumentAdapter::LoadFromStream is called, but its CDocument is NULL.&);
return E_POINTER;
m_pParentDoc-&m_bPreviewHandlerMode = TRUE;
m_pParentDoc-&m_bEmbedded = TRUE;
m_pParentDoc-&OnNewDocument();
return m_pParentDoc-&LoadDocumentFromStream(pStream, grfMode);
/// &summary&
/// Initializes search content. &/summary&
virtual void InitializeSearchContent()
ASSERT_VALID(m_pParentDoc);
if (m_pParentDoc == NULL)
TRACE0(&CDocumentAdapter::InitializeSearchContent is called, but its CDocument is NULL.&);
m_pParentDoc-&InitializeSearchContent();
/// &summary&
/// Clears the chunk list. &/summary&
virtual void ClearChunkList()
ASSERT_VALID(m_pParentDoc);
if (m_pParentDoc == NULL)
TRACE0(&CDocumentAdapter::ClearChunkList is called, but its CDocument is NULL.&);
m_pParentDoc-&ClearChunkList ();
/// &summary&
/// Sets a chunk value. &/summary&
/// &returns&
/// Nonzero if succeeds. Otherwise 0.&/returns&
/// &param name=&pValue&& Specifies a chunk value to set.&/param&
virtual BOOL SetChunkValue(ATL::IFilterChunkValue* pValue)
ASSERT_VALID(m_pParentDoc);
if (m_pParentDoc == NULL)
TRACE0(&CDocumentAdapter::SetChunkValue is called, but its CDocument is NULL.&);
return FALSE;
return m_pParentDoc-&SetChunkValue(pValue);
/// &summary&
/// Initializes chunk reading. &/summary&
virtual void BeginReadChunks()
ASSERT_VALID(m_pParentDoc);
if (m_pParentDoc == NULL)
TRACE0(&CDocumentAdapter::BeginReadChunks is called, but its CDocument is NULL.&);
m_pParentDoc-&BeginReadChunks();
/// &summary&
/// Reads next chunk value. &/summary&
/// &returns&
/// Nonzero if succeeds. Otherwise 0.&/returns&
/// &param name=&ppValue&& Output parameter. When the function returns ppValue contains the value.&/param&
virtual BOOL ReadNextChunkValue(ATL::IFilterChunkValue** ppValue)
ASSERT_VALID(m_pParentDoc);
if (m_pParentDoc == NULL)
TRACE0(&CDocumentAdapter::ReadNextChunkValue is called, but its CDocument is NULL.&);
return FALSE;
return m_pParentDoc-&ReadNextChunkValue(ppValue);
/// &summary&
/// Removes a chunk with specified GUID &/summary&
/// &param name=&guid& Specifies GUID of a chunk to be removed.&/param&
/// &param name=&pid& Specifies PID of a chunk to be removed.&/param&
virtual void RemoveChunk(REFCLSID guid, DWORD pid)
ASSERT_VALID(m_pParentDoc);
if (m_pParentDoc == NULL)
TRACE0(&CDocumentAdapter::RemoveChunk is called, but its CDocument is NULL.&);
m_pParentDoc-&RemoveChunk(guid, pid);
/// &summary&
/// Looks for a chunk with specified GUID &/summary&
/// &returns&
/// Position in the internal chunk list if succeeds. Otherwise NULL.&/returns&
/// &param name=&guid& Specifies GUID of a chunk to find.&/param&
/// &param name=&pid& Specifies PID of a chunk to find.&/param&
virtual POSITION FindChunk(REFCLSID guid, DWORD pid)
ASSERT_VALID(m_pParentDoc);
if (m_pParentDoc == NULL)
TRACE0(&CDocumentAdapter::FindChunk is called, but its CDocument is NULL.&);
return NULL;
return m_pParentDoc-&FindChunk(guid, pid);
/// &summary&
/// Returns a pointer to a parent CDocument.&/summary&
/// &returns& Returns a pointer to a parent (container) CDocument.&/returns&
virtual LPVOID GetContainer() const
return m_pParentD
/// &summary&
/// Creates a bitmap for Thumbnail provider.&/summary&
/// &returns&Returns TRUE if a bitmap for thumbnail was
otherwise FALSE.&/returns&
/// &param name=&cx&&Specifies width and height of the bitmap.&/param&
/// &param name=&phbmp&&Should contain a handle to a bitmap, when the function returns. &/param&
/// &param name=&pdwAlpha&&Should contain a DWORD specifying alpha channel value, when the function returns.&/param&
virtual BOOL GetThumbnail(UINT cx, HBITMAP* phbmp, WTS_ALPHATYPE* pdwAlpha)
ASSERT_VALID(m_pParentDoc);
if (m_pParentDoc == NULL)
TRACE0(&CDocumentAdapter::GetThumbnail is called, but its CDocument is NULL.&);
return FALSE;
return m_pParentDoc-&GetThumbnail(cx, phbmp, pdwAlpha);
protected:
/// &summary&
/// A pointer to a parent document (container).&/summary&
CDocument* m_pParentD
friend class CDocumentA
/// &summary&
/// Returns a pointer to object implementing IDocument interface. &/summary&
/// &returns&
/// A pointer to object implementing IDocument interface. &/returns&
virtual ATL::IDocument* GetAdapter()
if (m_pDocumentAdapter == NULL)
ATLTRY(m_pDocumentAdapter = new CDocumentAdapter(this));
if (m_pDocumentAdapter != NULL)
m_pDocumentAdapter-&AddRef();
return m_pDocumentA
// Attributes
const CString& GetTitle()
virtual void SetTitle(LPCTSTR lpszTitle);
const CString& GetPathName()
virtual void SetPathName(LPCTSTR lpszPathName, BOOL bAddToMRU = TRUE);
virtual void ClearPathName();
CDocTemplate* GetDocTemplate()
virtual BOOL IsModified();
virtual void SetModifiedFlag(BOOL bModified = TRUE);
/// &summary&
/// Tells whether this instance of CDocument object was created for Search & Organize handler.&/summary&
/// &returns&
/// Returns TRUE if this instance of CDocument was created for Search & Organize handler.&/returns&
/// &remarks&
/// Currently this function returns TRUE only for Rich Preview handler implemented in out of process server.
/// You can set the appropriate flags (m_bPreviewHandlerMode, m_bSearchMode, m_bGetThumbnailMode) at your application level
/// to make this function returning TRUE.&/remarks&
BOOL IsSearchAndOrganizeHandler()
// Operations
void AddView(CView* pView);
void RemoveView(CView* pView);
virtual POSITION GetFirstViewPosition()
virtual CView* GetNextView(POSITION& rPosition)
// Update Views (simple update - DAG only)
void UpdateAllViews(CView* pSender, LPARAM lHint = 0L,
CObject* pHint = NULL);
// Overridables
// Special notifications
virtual void OnChangedViewList(); // after Add or Remove view
virtual void DeleteContents(); // delete doc items etc
// File helpers
virtual BOOL OnNewDocument();
virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
virtual BOOL OnSaveDocument(LPCTSTR lpszPathName);
virtual void OnCloseDocument();
virtual void ReportSaveLoadException(LPCTSTR lpszPathName,
CException* e, BOOL bSaving, UINT nIDPDefault);
virtual CFile* GetFile(LPCTSTR lpszFileName, UINT nOpenFlags,
CFileException* pError);
virtual void ReleaseFile(CFile* pFile, BOOL bAbort);
// search/organize/preview/thumbnail notifications
/// &summary&
/// Called before Rich Preview font is changed. &/summary&
virtual void OnBeforeRichPreviewFontChanged(){}
/// &summary&
/// Called when Rich Preview font has changed. &/summary&
virtual void OnRichPreviewFontChanged(){}
/// &summary&
/// Called when Rich Preview text color has changed. &/summary&
virtual void OnRichPreviewTextColorChanged(){}
/// &summary&
/// Called when Rich Preview background color has changed. &/summary&
virtual void OnRichPreviewBackColorChanged(){}
/// &summary&
/// Called when Rich Preview site has changed. &/summary&
virtual void OnRichPreviewSiteChanged(){}
/// &summary&
/// Called when Rich Preview is unloaded.&/summary&
/// &remarks&
/// OnUnloadHandler allows to take some additional on handler unload.
/// Overriding this method allows complete control on clean up process if you don't call the
/// base implementation, which releases preview handler site, destroys preview frame and
/// releases the stream.&/remarks&
virtual void OnRichPreviewUnload();
// search/organize/preview/thumbnail helpers
/// &summary&
/// Called to load document data from stream. &/summary&
/// &returns&S_OK if the load operation succeeds, otherwise HRESULT with error code.&/returns&
/// &remarks&
/// You can override this method in a derived class to customize loading data from the stream. &/remarks&
/// &param name=&pStream&&A pointer to a stream. This stream is supplied by the Shell.&/param&
/// &param name=&grfMode&&Access mode to the stream.&/param&
virtual HRESULT LoadDocumentFromStream(IStream* pStream, DWORD dwGrfMode);
/// &summary&
/// Called to create a bitmap to be used by thumbnail provider to display thumbnail. &/summary&
/// &returns&Returns TRUE if a bitmap for thumbnail was
otherwise FALSE.&/returns&
/// &param name=&cx&&Specifies width and height of the bitmap.&/param&
/// &param name=&phbmp&&Should contain a handle to a bitmap, when the function returns. &/param&
/// &param name=&pdwAlpha&&Should contain a DWORD specifying alpha channel value, when the function returns.&/param&
virtual BOOL GetThumbnail(UINT cx, HBITMAP* phbmp, WTS_ALPHATYPE* pdwAlpha);
// search/organize/preview/thumbnail support - search and chunk management
/// &summary&
/// Called to initialize search content for Search Handler. &/summary&
/// &remarks&
/// You should override this method in a derived class to initialize search content.
/// The content should be a string with parts delimited by ';'. For example, & ole item&. &/remarks&
virtual void InitializeSearchContent ()
TRACE0(&Override this method in a derived class to initialize chunk list for search filter.&);
/// &summary&
/// Clears the chunk list. &/summary&
virtual void ClearChunkList ();
/// &summary&
/// Sets a chunk value. &/summary&
/// &returns&
/// Nonzero if succeeds. Otherwise 0.&/returns&
/// &param name=&pValue&& Specifies a chunk value to set.&/param&
virtual BOOL SetChunkValue (ATL::IFilterChunkValue* pValue);
/// &summary&
/// Initializes chunk reading. &/summary&
virtual void BeginReadChunks ();
/// &summary&
/// Reads next chunk value. &/summary&
/// &returns&
/// Nonzero if succeeds. Otherwise 0.&/returns&
/// &param name=&ppValue&& Output parameter. When the function returns ppValue contains the value.&/param&
virtual BOOL ReadNextChunkValue(ATL::IFilterChunkValue** ppValue);
/// &summary&
/// Removes a chunk with specified GUID &/summary&
/// &param name=&guid&& Specifies GUID of a chunk to be removed.&/param&
/// &param name=&pid&& Specifies PID of a chunk to be removed.&/param&
virtual void RemoveChunk(REFCLSID guid, DWORD pid);
/// &summary&
/// Looks for a chunk with specified GUID &/summary&
/// &returns&
/// Position in the internal chunk list if succeeds. Otherwise NULL.&/returns&
/// &param name=&guid&& Specifies GUID of a chunk to find.&/param&
/// &param name=&pid&& Specifies PID of a chunk to find.&/param&
virtual POSITION FindChunk(REFCLSID guid, DWORD pid);
// Document event notifications
enum DocumentEvent
onAfterNewDocument = 0,
onAfterOpenDocument = 1,
onAfterSaveDocument = 2,
onAfterCloseDocument = 3
virtual void OnDocumentEvent(DocumentEvent deEvent);
// advanced overridables, closing down frame/doc, etc.
virtual BOOL CanCloseFrame(CFrameWnd* pFrame);
virtual BOOL SaveModified(); // return TRUE if ok to continue
virtual void PreCloseFrame(CFrameWnd* pFrame);
// Implementation
protected:
// default implementation
CString m_strT
CString m_strPathN
CDocTemplate* m_pDocT
CPtrList m_viewL
// list of views
// changed since last saved
BOOL m_bFinalR
// we're in CDocument's FinalRelease
BOOL m_bOLEL
// AfxOleLockApp has been called
// search/organize/preview/thumbnail data
HWND m_hWndH // a handle to window (host) supplied by prevhost.exe
CRect m_rectH // window rectangle of host. Our preview frame should fit this rectangle
IStream* m_pS // stream to load the document data from
DWORD m_grfM // stream opening mode
CFrameWnd* m_pPreviewF // frame to display the rich preview
ATL::CComPtr&IUnknown& m_spUnkS // SetSite called through IObjectWithSite
// search support
CPtrList m_lstC
POSITION m_posReadC
/// &summary&
/// A pointer to embedded document adapter - an object implementing IDocument interface.&/summary&
CDocumentAdapter* m_pDocumentA
BOOL m_bAutoD
// TRUE =& delete document when no more views
// TRUE =& document is being created by OLE
/// &summary&
/// Specifies that CDocument object was created by dllhost for thumbnails. Should be checked in CView::OnDraw.&/summary&
BOOL m_bGetThumbnailM
// TRUE =& document was created by dllhost for thumbnails. Should be checked in CView::OnDraw
/// &summary&
/// Specifies that CDocument object was created by prevhost for Rich Preview. Should be checked in CView::OnDraw.&/summary&
BOOL m_bPreviewHandlerM // TRUE =& document was created by prevhost for rich preview
/// &summary&
/// Specifies that CDocument object was created by indexer or other search application.&/summary&
BOOL m_bSearchM
// TRUE =& document was created by indexer or other search application
// rich preview visuals
/// &summary&
/// Specifies background color of Rich Preview window. This color is set by host.&/summary&
COLORREF m_clrRichPreviewBackC
/// &summary&
/// Specifies foreground color of Rich Preview window. This color is set by host.&/summary&
COLORREF m_clrRichPreviewTextC
/// &summary&
/// Specifies text font for Rich Preview window. This font information is set by host.&/summary&
m_lfRichPreviewF
#ifdef _DEBUG
virtual void Dump(CDumpContext&)
virtual void AssertValid()
#endif //_DEBUG
virtual ~CDocument() = 0;
// implementation helpers
virtual BOOL DoSave(LPCTSTR lpszPathName, BOOL bReplace = TRUE);
virtual BOOL DoFileSave();
virtual void UpdateFrameCounts();
void DisconnectViews();
void SendInitialUpdate();
// overridables for implementation
virtual HMENU GetDefaultMenu(); // get menu depending on state
virtual HACCEL GetDefaultAccelerator();
virtual void OnIdle();
virtual void OnFinalRelease();
// search/organize/preview/thumbnail overridables
// Load document from IStream
/// &summary&
/// Called by the framework when it needs to load the document data from stream.&/summary&
/// &returns& S_OK if load succeeds, otherwise error code.&/returns&
/// &param name=&pStream&&A pointer to incoming stream.&/param&
/// &param name=&grfMode&&Access mode to the stream.&/param&
virtual HRESULT OnLoadDocumentFromStream(IStream* pStream, DWORD grfMode);
/// &summary&
/// Directs the preview handler to return the HWND from calling the GetFocus Function. &/summary&
/// &returns& Returns S_OK if successful, or an error value otherwise. &/returns&
/// &param name=&phwnd&& [out] When this method returns, contains a pointer to the HWND returned from calling the GetFocus Function from the preview handler's foreground thread.&/param&
virtual HRESULT OnPreviewHandlerQueryFocus(HWND* phwnd);
/// &summary&
/// Directs the preview handler to handle a keystroke passed up from the message pump of the process in which the preview handler is running.&/summary&
/// &returns&If the keystroke message can be processed by the preview handler, the handler will
/// process it and return S_OK. If the preview handler cannot process the keystroke message,
/// it will offer it to the host via IPreviewHandlerFrame::TranslateAccelerator. If the host processes the message, this method will return S_OK. If the host does not process the message,
/// this method will return S_FALSE.&/returns&
/// &param name=&pmsg&&[in] A pointer to a window message.&/param&
virtual HRESULT OnPreviewHandlerTranslateAccelerator(MSG* pmsg);
/// &summary&
/// Called by the framework when it needs to create a preview frame for Rich Preview.&/summary&
/// &returns& Returns TRUE if the frame is
otherwise FALSE.&/returns&
virtual BOOL OnCreatePreviewFrame();
/// &summary&
/// Called by the framework when the preview handler is beign unloaded.&/summary&
virtual void OnUnloadHandler();
/// &summary&
/// Override this method in a derived class to draw content of thumbnail &/summary&
/// &param name=&dc&& A reference to a device context.&/param&
/// &param name=&lprcBounds&& Specifies a bounding rectangle of area where the thumbnail should be drawn.&/param&
virtual void OnDrawThumbnail(CDC& dc, LPRECT lprcBounds);
virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra,
AFX_CMDHANDLERINFO* pHandlerInfo);
friend class CDocT
protected:
// file menu commands
//{{AFX_MSG(CDocument)
afx_msg void OnFileClose();
afx_msg void OnFileSave();
afx_msg void OnFileSaveAs();
//}}AFX_MSG
// mail enabling
afx_msg void OnFileSendMail();
afx_msg void OnUpdateFileSendMail(CCmdUI* pCmdUI);
DECLARE_MESSAGE_MAP()
#if WINVER &= 0x0600
BEGIN_INTERFACE_PART(InitializeWithStream, IInitializeWithStream)
INIT_INTERFACE_PART(CDocument, InitWithStream)
STDMETHOD(Initialize)(IStream* pStream, DWORD grfMode);
END_INTERFACE_PART(InitializeWithStream)
BEGIN_INTERFACE_PART(PreviewHandler, IPreviewHandler)
INIT_INTERFACE_PART(CDocument, PreviewHandler)
STDMETHOD(SetWindow)(HWND hwnd, const RECT *prc);
STDMETHOD(SetRect)(const RECT *prc);
STDMETHOD(DoPreview)();
STDMETHOD(Unload)();
STDMETHOD(SetFocus)();
STDMETHOD(QueryFocus)(HWND *phwnd);
STDMETHOD(TranslateAccelerator)(MSG *pmsg);
END_INTERFACE_PART(PreviewHandler)
BEGIN_INTERFACE_PART(PreviewHandlerVisuals, IPreviewHandlerVisuals)
INIT_INTERFACE_PART(CDocument, PreviewHandlerVisuals)
STDMETHOD(SetBackgroundColor)(COLORREF color);
STDMETHOD(SetFont)(const LOGFONTW *plf);
STDMETHOD(SetTextColor)(COLORREF color);
END_INTERFACE_PART(PreviewHandlerVisuals)
BEGIN_INTERFACE_PART(ObjectWithSite, IObjectWithSite)
INIT_INTERFACE_PART(CDocument, ObjectWithSite)
STDMETHOD(SetSite)(IUnknown *punkSite);
STDMETHOD(GetSite)(REFIID riid, void **ppvSite);
END_INTERFACE_PART(ObjectWithSite)
BEGIN_INTERFACE_PART(OleWindow, IOleWindow)
INIT_INTERFACE_PART(CDocument, ObjectWithSite)
STDMETHOD(GetWindow)(HWND *phwnd);
STDMETHOD(ContextSensitiveHelp)(BOOL);
END_INTERFACE_PART(OleWindow)
DECLARE_INTERFACE_MAP()
protected:
IPreviewHandlerFrame* m_pPreviewHandlerS // Ole frame for rich preview
BEGIN_INTERFACE_PART(InitializeWithStream, IUnknown)
END_INTERFACE_PART_OPTIONAL(InitializeWithStream)
BEGIN_INTERFACE_PART(PreviewHandler, IUnknown)
END_INTERFACE_PART_OPTIONAL(PreviewHandler)
BEGIN_INTERFACE_PART(PreviewHandlerVisuals, IUnknown)
END_INTERFACE_PART_OPTIONAL(PreviewHandlerVisuals)
BEGIN_INTERFACE_PART(ObjectWithSite, IUnknown)
END_INTERFACE_PART_OPTIONAL(ObjectWithSite)
BEGIN_INTERFACE_PART(OleWindow, IUnknown)
END_INTERFACE_PART_OPTIONAL(OleWindow)
protected:
IUnknown* m_pPreviewHandlerS // Ole frame for rich preview
& &CFrameWnd有一个成员指向当前活动的。
class CFrameWnd : public CWnd
DECLARE_DYNCREATE(CFrameWnd)
// Constructors
static AFX_DATA const CRect rectD
CFrameWnd();
BOOL LoadAccelTable(LPCTSTR lpszResourceName);
virtual BOOL Create(LPCTSTR lpszClassName,
LPCTSTR lpszWindowName,
DWORD dwStyle = WS_OVERLAPPEDWINDOW,
const RECT& rect = rectDefault,
CWnd* pParentWnd = NULL,
// != NULL for popups
LPCTSTR lpszMenuName = NULL,
DWORD dwExStyle = 0,
CCreateContext* pContext = NULL);
// dynamic creation - load frame and associated resources
virtual BOOL LoadFrame(UINT nIDResource,
DWORD dwDefaultStyle = WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE,
CWnd* pParentWnd = NULL,
CCreateContext* pContext = NULL);
// special helper for view creation
CWnd* CreateView(CCreateContext* pContext, UINT nID = AFX_IDW_PANE_FIRST);
// Attributes
virtual CDocument* GetActiveDocument();
// Active child view maintenance
CView* GetActiveView()
// active view or NULL
void SetActiveView(CView* pViewNew, BOOL bNotify = TRUE);
// active view or NULL, bNotify == FALSE if focus should not be set
// Active frame (for frames within frames -- MDI)
virtual CFrameWnd* GetActiveFrame();
// For customizing the default messages on the status bar
virtual void GetMessageString(UINT nID, CString& rMessage)
BOOL m_bAutoMenuE
// TRUE =& menu items without handlers will be disabled
BOOL IsTracking()
// Operations
virtual void RecalcLayout(BOOL bNotify = TRUE);
virtual void ActivateFrame(int nCmdShow = -1);
void InitialUpdateFrame(CDocument* pDoc, BOOL bMakeVisible);
void SetTitle(LPCTSTR lpszTitle);
CString GetTitle()
virtual CMenu* GetMenu()
virtual BOOL SetMenu(CMenu* pMenu);
// set/get menu bar visibility style
virtual void SetMenuBarVisibility(DWORD dwStyle);
virtual DWORD GetMenuBarVisibility()
// set/get menu bar visibility state
virtual BOOL SetMenuBarState(DWORD dwState);
virtual DWORD GetMenuBarState()
#if (WINVER &= 0x0601)
/// &summary&
/// Sets range for Windows 7 progress bar displayed on taskbar. &/summary&
/// &param name=&nRangeMin&&Minimal value.&/param&
/// &param name=&nRangeMax&&Maximal value.&/param&
void SetProgressBarRange(int nRangeMin, int nRangeMax);
/// &summary&
/// Sets current position for Windows 7 progress bar displayed on taskbar.&/summary&
/// &param name=&nProgressPos&&Specifies the position to set. It must be within range set by SetProgressBarRange.&/param&
void SetProgressBarPosition(int nProgressPos);
/// &summary&Sets the type and state of the progress indicator displayed on a taskbar button.&/summary&
/// &param name=&tbpFlags&&Flags that control the current state of the progress button. Specify only one of all states are mutually exclusive of all others:
/// TBPF_NOPROGRESS, TBPF_INDETERMINATE, TBPF_NORMAL, TBPF_ERROR, TBPF_PAUSED.&/param&
void SetProgressBarState(TBPFLAG tbpFlags);
/// &summary&
/// Applies an overlay to a taskbar button to indicate application status or a notification to the user.&/summary&
/// &returns& TRUE FALSE if OS version is less than Windows 7 or if an error occurs setting the icon.&/returns&
/// &param name=&nIDResource&&Specifies Resource ID of an icon to use as the overlay. See description for hIcon for details.&/param&
/// &param name=&lpcszDescr&&A pointer to a string that provides an alt text version of the information conveyed by the overlay, for accessibility purposes.&/param&
BOOL SetTaskbarOverlayIcon(UINT nIDResource, LPCTSTR lpcszDescr);
/// &summary&
/// Applies an overlay to a taskbar button to indicate application status or a notification to the user.&/summary&
/// &returns& TRUE FALSE if OS version is less than Windows 7 or if an error occurs setting the icon.&/returns&
/// &param name=&hIcon&& The handle of an icon to use as the overlay. This should be a small icon, measuring 16x16 pixels at 96 dots per inch (dpi).
/// If an overlay icon is already applied to the taskbar button, that existing overlay is replaced.
/// This value can be NULL. How a NULL value is handled depends on whether the taskbar button represents a single window or a group of windows.
/// It is the responsibility of the calling application to free hIcon when it is no longer needed.&/param&
/// &param name=&lpcszDescr&&A pointer to a string that provides an alt text version of the information conveyed by the overlay, for accessibility purposes.&/param&
BOOL SetTaskbarOverlayIcon(HICON hIcon, LPCTSTR lpcszDescr);
#if WINVER &= 0x0500
BOOL GetMenuBarInfo(LONG idObject, LONG idItem, PMENUBARINFO pmbi)
/// &summary& Designates the specified view to be the active view for Rich Preview.&/summary&
/// &param name=&pViewNew&& A pointer to a view that should be activated.&/param&
void SetActivePreviewView(CView* pViewNew);
// to set text of standard status bar
void SetMessageText(LPCTSTR lpszText);
void SetMessageText(UINT nID);
// control bar docking
void EnableDocking(DWORD dwDockStyle);
void DockControlBar(CControlBar* pBar, UINT nDockBarID = 0,
LPCRECT lpRect = NULL);
void FloatControlBar(CControlBar* pBar, CPoint point,
DWORD dwStyle = CBRS_ALIGN_TOP);
CControlBar* GetControlBar(UINT nID);
// frame window based modality
virtual void BeginModalState();
virtual void EndModalState();
BOOL InModalState()
void ShowOwnedWindows(BOOL bShow);
// saving and loading control bar state
void LoadBarState(LPCTSTR lpszProfileName);
void SaveBarState(LPCTSTR lpszProfileName)
void ShowControlBar(CControlBar* pBar, BOOL bShow, BOOL bDelay);
void SetDockState(const CDockState& state);
void GetDockState(CDockState& state)
// Overridables
virtual void OnSetPreviewMode(BOOL bPreview, CPrintPreviewState* pState);
virtual CWnd* GetMessageBar();
// border space negotiation
enum BorderCmd
{ borderGet = 1, borderRequest = 2, borderSet = 3 };
virtual BOOL NegotiateBorderSpace(UINT nBorderCmd, LPRECT lpRectBorder);
protected:
virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
// Command Handlers
afx_msg void OnContextHelp();
// for Shift+F1 help
afx_msg void OnUpdateControlBarMenu(CCmdUI* pCmdUI);
afx_msg BOOL OnBarCheck(UINT nID);
// Implementation
virtual ~CFrameWnd();
// general purpose window number - display as &:n&
// -1 =& unknown, 0 =& only window viewing document
// 1 =& first of many windows viewing document, 2=& second
HMENU m_hMenuD
// default menu resource for this frame
HACCEL m_hAccelT
// accelerator table
DWORD m_dwPromptC
// current help prompt context for message box
BOOL m_bHelpM
// if TRUE, then Shift+F1 help mode is active
CFrameWnd* m_pNextFrameW // next CFrameWnd in app global list
CRect m_rectB
// for OLE border space negotiation
COleFrameHook* m_pNotifyH
CPtrList m_listControlB // array of all control bars that have this
// window as their dock site
int m_nShowD
// SW_ command for delay show/hide
CMiniDockFrameWnd* CreateFloatingFrame(DWORD dwStyle);
DWORD CanDock(CRect rect, DWORD dwDockStyle,
CDockBar** ppDockBar = NULL); // called by CDockContext
void AddControlBar(CControlBar *pBar);
void RemoveControlBar(CControlBar *pBar);
void DockControlBar(CControlBar* pBar, CDockBar* pDockBar,
LPCRECT lpRect = NULL);
void ReDockControlBar(CControlBar* pBar, CDockBar* pDockBar,
LPCRECT lpRect = NULL);
void NotifyFloatingWindows(DWORD dwFlags);
void DestroyDockBars();
protected:
UINT m_nIDH
// Help ID (0 for none, see HID_BASE_RESOURCE)
UINT m_nIDT
// tracking command ID or string IDS
UINT m_nIDLastM
// last displayed message string IDS
CView* m_pViewA
// current active view
BOOL (CALLBACK* m_lpfnCloseProc)(CFrameWnd* pFrameWnd);
UINT m_cModalS
// BeginModalState depth
HWND* m_phWndD
// windows disabled because of BeginModalState
HMENU m_hMenuA
// menu to update to (NULL means default)
CString m_strT
// default title (original)
BOOL m_bInRecalcL
// avoid recursion in RecalcLayout
CRuntimeClass* m_pFloatingFrameC
static const DWORD dwDockBarMap[4][2];
DWORD m_dwMenuBarV
// menu bar visibility style
DWORD m_dwMenuBarS
// menu bar visibility state
HMENU m_hM
// backed menu for restoring from the hidden state
m_bTempShowM
// temporarily show the menu bar to enable menu access keys
m_bMouseHitM
// if TRUE, the mouse is hitting the menu bar
int m_nProgressBarRangeM // Win7 taskbar support - min progress range
int m_nProgressBarRangeM // Win7 taskbar support - max progress range
#ifdef _DEBUG
virtual void AssertValid()
virtual void Dump(CDumpContext& dc)
virtual BOOL IsFrameWnd()
virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra,
AFX_CMDHANDLERINFO* pHandlerInfo);
virtual void OnUpdateFrameTitle(BOOL bAddToTitle);
virtual void OnUpdateFrameMenu(HMENU hMenuAlt);
virtual HACCEL GetDefaultAccelerator();
virtual BOOL PreTranslateMessage(MSG* pMsg);
// idle update of frame user interface
enum IdleFlags
{ idleMenu = 1, idleTitle = 2, idleNotify = 4, idleLayout = 8 };
UINT m_nIdleF
// set of bit flags for idle processing
virtual void DelayUpdateFrameMenu(HMENU hMenuAlt);
void DelayUpdateFrameTitle();
void DelayRecalcLayout(BOOL bNotify = TRUE);
// for Shift+F1 help support
BOOL CanEnterHelpMode();
virtual void ExitHelpMode();
// implementation helpers
void UpdateFrameTitleForDocument(LPCTSTR lpszDocName);
protected:
LPCTSTR GetIconWndClass(DWORD dwDefaultStyle, UINT nIDResource);
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
virtual void PostNcDestroy();
// default to delete this.
int OnCreateHelper(LPCREATESTRUCT lpcs, CCreateContext* pContext);
void BringToTop(int nCmdShow);
// bring window to top for SW_ commands which affect z-order
// implementation helpers for Shift+F1 help mode
BOOL ProcessHelpMsg(MSG& msg, DWORD* pContext);
HWND SetHelpCapture(POINT point, BOOL* pbDescendant);
// CFrameWnd list management
void AddFrameWnd();
void RemoveFrameWnd();
// called before changing the menu bar visibility state
virtual void OnShowMenuBar();
virtual void OnHideMenuBar();
friend class CW
// for access to m_bModalDisable
friend class CReB // for access to m_bInRecalcLayout
//{{AFX_MSG(CFrameWnd)
// Windows messages
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnDestroy();
afx_msg void OnClose();
afx_msg void OnInitMenu(CMenu*);
afx_msg void OnInitMenuPopup(CMenu*, UINT, BOOL);
afx_msg void OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu);
afx_msg LRESULT OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu);
afx_msg LRESULT OnPopMessageString(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnSetMessageString(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnHelpPromptAddr(WPARAM wParam, LPARAM lParam);
afx_msg void OnIdleUpdateCmdUI();
afx_msg void OnEnterIdle(UINT nWhy, CWnd* pWho);
afx_msg void OnSetFocus(CWnd* pOldWnd);
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
afx_msg BOOL OnNcActivate(BOOL bActive);
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg BOOL OnQueryEndSession();
afx_msg void OnEndSession(BOOL bEnding);
afx_msg void OnDropFiles(HDROP hDropInfo);
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg LRESULT OnCommandHelp(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnHelpHitTest(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnActivateTopLevel(WPARAM wParam, LPARAM lParam);
afx_msg void OnEnable(BOOL bEnable);
afx_msg void OnPaletteChanged(CWnd* pFocusWnd);
afx_msg BOOL OnQueryNewPalette();
// standard commands
afx_msg BOOL OnToolTipText(UINT nID, NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnUpdateKeyIndicator(CCmdUI* pCmdUI);
afx_msg void OnHelp();
afx_msg void OnUpdateContextHelp(CCmdUI* pCmdUI);
afx_msg BOOL OnChevronPushed(UINT id, NMHDR *pnm, LRESULT *result);
//}}AFX_MSG
protected:
afx_msg LRESULT OnDDEInitiate(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnDDEExecute(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnDDETerminate(WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
friend class CWinA
CView有一个成员变量,指向相关的。
class AFX_NOVTABLE CView : public CWnd
friend class CWinAppEx;
DECLARE_DYNAMIC(CView)
// Constructors
protected:
// Attributes
CDocument* GetDocument()
// Operations
// for standard printing setup (override OnPreparePrinting)
BOOL DoPreparePrinting(CPrintInfo* pInfo);
// Overridables
virtual BOOL IsSelected(const CObject* pDocItem) // support for OLE
// OLE scrolling support (used for drag/drop as well)
virtual BOOL OnScroll(UINT nScrollCode, UINT nPos, BOOL bDoScroll = TRUE);
virtual BOOL OnScrollBy(CSize sizeScroll, BOOL bDoScroll = TRUE);
// OLE drag/drop support
virtual DROPEFFECT OnDragEnter(COleDataObject* pDataObject,
DWORD dwKeyState, CPoint point);
virtual DROPEFFECT OnDragOver(COleDataObject* pDataObject,
DWORD dwKeyState, CPoint point);
virtual void OnDragLeave();
virtual BOOL OnDrop(COleDataObject* pDataObject,
DROPEFFECT dropEffect, CPoint point);
virtual DROPEFFECT OnDropEx(COleDataObject* pDataObject,
DROPEFFECT dropDefault, DROPEFFECT dropList, CPoint point);
virtual DROPEFFECT OnDragScroll(DWORD dwKeyState, CPoint point);
virtual void OnPrepareDC(CDC* pDC, CPrintInfo* pInfo = NULL);
virtual void OnInitialUpdate(); // called first time after construct
protected:
// Activation
virtual void OnActivateView(BOOL bActivate, CView* pActivateView,
CView* pDeactiveView);
virtual void OnActivateFrame(UINT nState, CFrameWnd* pFrameWnd);
// General drawing/updating
virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);
virtual void OnDraw(CDC* pDC) = 0;
// Printing support
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
// must override to enable printing and print preview
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
// Advanced: end print preview mode, move to point
virtual void OnEndPrintPreview(CDC* pDC, CPrintInfo* pInfo, POINT point,
CPreviewView* pView);
// Implementation
virtual ~CView() = 0;
#ifdef _DEBUG
virtual void Dump(CDumpContext&)
virtual void AssertValid()
#endif //_DEBUG
// Advanced: for implementing custom print preview
BOOL DoPrintPreview(UINT nIDResource, CView* pPrintView,
CRuntimeClass* pPreviewViewClass, CPrintPreviewState* pState);
virtual void CalcWindowRect(LPRECT lpClientRect,
UINT nAdjustType = adjustBorder);
virtual CScrollBar* GetScrollBarCtrl(int nBar)
static CSplitterWnd* PASCAL GetParentSplitter(
const CWnd* pWnd, BOOL bAnyState);
protected:
CDocument* m_pD
BOOL m_bInitialR
virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra,
AFX_CMDHANDLERINFO* pHandlerInfo);
protected:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual void PostNcDestroy();
// friend classes that call protected CView overridables
friend class CD
friend class CDocT
friend class CPreviewV
friend class CFrameW
friend class CMDIFrameW
friend class CMDIChildW
friend class CSplitterW
friend class COleServerD
friend class CDocObjectS
//{{AFX_MSG(CView)
afx_msg int OnCreate(LPCREATESTRUCT lpcs);
afx_msg void OnDestroy();
afx_msg void OnPaint();
afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
// Print client support: used for interaction with Windows task bar
afx_msg LRESULT OnPrintClient(WPARAM wp, LPARAM lp);
// commands
afx_msg void OnUpdateSplitCmd(CCmdUI* pCmdUI);
afx_msg BOOL OnSplitCmd(UINT nID);
afx_msg void OnUpdateNextPaneMenu(CCmdUI* pCmdUI);
afx_msg BOOL OnNextPaneCmd(UINT nID);
// not mapped commands - must be mapped in derived class
afx_msg void OnFilePrint();
afx_msg void OnFilePrintPreview();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
& & 前面就提到过会抽象类且它没有基类,因此它需要特殊处理。
&&&&当多个视图显示同一个文档,为了保持各个视图操作的文档内容的一致性,需要以消息通知使用同一份文档的其他视图,中有三个虚函数:
&&&&1:负责的初始化。
&&&&2:::,当调用此函数时,表示的内容已经发生了变化。
&&&&3:::在消息时会调用此函数,此函数负责更新窗口的内容。
让所有的窗口同步更新数据的关键在于两个函数:
&&&&1:::它会遍历使用这个文档的各个视图,逐个调用它们的函数。
void CDocument::UpdateAllViews(CView* pSender, LPARAM lHint, CObject* pHint)
// walk through all views
ASSERT(pSender == NULL || !m_viewList.IsEmpty());
// must have views if sent by one of them
POSITION pos = GetFirstViewPosition();
while (pos != NULL)
CView* pView = GetNextView(pos);
ASSERT_VALID(pView);
if (pView != pSender)
pView-&OnUpdate(pSender, lHint, pHint);
& & 2:::,这是个虚函数,可以改写。它的作用就是告诉,的内容已经改变,你需要更新了。
具体步骤为:
&&&&1:在中调用获得指针。
&&&&2:在中调用::
&&&&3:所有使用这一份的都被调用。
原文链接:
http://www.oschina.net/question/75
版权声明:本文为博主原创文章,未经博主允许不得转载。
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:1781239次
积分:24341
积分:24341
排名:第116名
原创:259篇
转载:1983篇
评论:200条
(13)(8)(16)(82)(74)(85)(9)(28)(5)(11)(13)(2)(2)(6)(9)(33)(8)(15)(3)(4)(1)(1)(8)(61)(10)(5)(1)(3)(40)(44)(21)(19)(11)(1)(1)(1)(1)(3)(14)(48)(48)(2)(14)(53)(12)(12)(17)(9)(25)(15)(17)(9)(18)(18)(2)(6)(1)(14)(8)(12)(23)(26)(14)(2)(13)(17)(53)(13)(2)(6)(5)(15)(10)(19)(14)(15)(5)(14)(28)(15)(17)(22)(3)(18)(9)(10)(13)(21)(22)(110)(78)(81)(21)(23)(42)(3)(5)(19)(16)(31)(1)(7)(14)(9)(12)(27)(30)(10)(19)(12)(6)(13)(17)(18)(23)(28)(19)(12)(5)(3)(5)(5)(5)(21)(11)(39)

我要回帖

更多关于 思密达是什么意思 的文章

 

随机推荐