commands.cpp

来自「语法检查程序」· C++ 代码 · 共 101 行

CPP
101
字号
/***************************************************************************/
/* NOTE:                                                                   */
/* This document is copyright (c) by Oz Solomon and Yonat Sharon, and is   */
/* bound by the MIT open source license.                                   */ 
/* See License.txt or visit www.opensource.org/licenses/mit-license.html   */
/***************************************************************************/

// Commands.cpp : implementation file
//

#include "stdafx.h"
#include "Spellyer.h"
#include "Commands.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCommands

CCommands::CCommands()
    : m_pSpellyer(NULL), m_pApplication(NULL)
{
}

CCommands::~CCommands()
{
	ASSERT (m_pApplication != NULL);
	m_pApplication->Release();
    delete m_pSpellyer;
}

void CCommands::SetApplicationObject(IApplication* pApplication)
{
	// This function assumes pApplication has already been AddRef'd
	//  for us, which CDSAddIn did in its QueryInterface call
	//  just before it called us.
	m_pApplication = pApplication;
}


/////////////////////////////////////////////////////////////////////////////
// CCommands methods

STDMETHODIMP CCommands::SpellyCommandMethod() 
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE));

    try
    {
        if (m_pSpellyer == NULL)
            m_pSpellyer = new Spellyer;
    }
    catch (...)
    {
        delete m_pSpellyer;
        m_pSpellyer = NULL;
        VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));
	    return S_OK;
    }

    IDispatch* pDispatch;
    m_pApplication->get_ActiveDocument(&pDispatch);
    CComQIPtr<ITextDocument, &IID_ITextDocument> pDocument(pDispatch);

	if (pDocument)
		m_pSpellyer->Spell(pDocument, true);

	if (pDispatch)
		pDispatch->Release();

    VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));
	return S_OK;
}

STDMETHODIMP CCommands::SpellyNoCodeCommandMethod() 
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());
	VERIFY_OK(m_pApplication->EnableModeless(VARIANT_FALSE));

    if (m_pSpellyer == NULL)
        m_pSpellyer = new Spellyer;

    IDispatch* pDispatch;
    m_pApplication->get_ActiveDocument(&pDispatch);
    CComQIPtr<ITextDocument, &IID_ITextDocument> pDocument(pDispatch);

	if (pDocument)
		m_pSpellyer->Spell(pDocument, false);

	if (pDispatch)
		pDispatch->Release();

    VERIFY_OK(m_pApplication->EnableModeless(VARIANT_TRUE));
	return S_OK;
}

⌨️ 快捷键说明

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