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

📄 dsaddin.cpp

📁 语法检查程序
💻 CPP
字号:
/***************************************************************************/
/* 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   */
/***************************************************************************/

// AddInMod.cpp : implementation file
//

#include "stdafx.h"
#include "Spelly.h"
#include "DSAddIn.h"
#include "Commands.h"
#include "Config.h"
#include "TBAdderWnd.h"

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

LPCTSTR CMD_NAME_SPELLY         = _T("Spelly");
LPCTSTR CMD_NAME_SPELLY_NO_CODE = _T("SpellyNoCode");

CDSAddIn *g_pDSAddin = NULL;

// This is called when the user first loads the add-in, and on start-up
//  of each subsequent Developer Studio session
STDMETHODIMP CDSAddIn::OnConnection(IApplication* pApp, VARIANT_BOOL bFirstTime,
		long dwCookie, VARIANT_BOOL* OnConnection)
{
    // must be before the AFX_MANAGE_STATE
    char host_path[1024];
    GetModuleFileName(NULL, host_path, countof(host_path));

    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    g_pDSAddin = this;
    
	// Store info passed to us
	IApplication* pApplication = NULL;
	if (FAILED(pApp->QueryInterface(IID_IApplication, (void**) &pApplication))
		|| pApplication == NULL)
	{
		*OnConnection = VARIANT_FALSE;
		return S_OK;
	}

    m_pApplication = pApplication;

	m_dwCookie = dwCookie;

	// Create command dispatch, send info back to DevStudio
	CCommandsObj::CreateInstance(&m_pCommands);
	m_pCommands->AddRef();

	// The QueryInterface above AddRef'd the Application object.  It will
	//  be Release'd in CCommand's destructor.
	m_pCommands->SetApplicationObject(pApplication);

	// (see stdafx.h for the definition of VERIFY_OK)

	VERIFY_OK(pApplication->SetAddInInfo((long) AfxGetInstanceHandle(),
		(LPDISPATCH) m_pCommands, IDR_TOOLBAR_MEDIUM, IDR_TOOLBAR_LARGE, m_dwCookie));

	// Inform DevStudio of the commands we implement

	// The command name should not be localized to other languages.  The 
	//  tooltip, command description, and other strings related to this
	//  command are stored in the string table (IDS_CMD_STRING) and should
	//  be localized.
	LPCTSTR szCommand = CMD_NAME_SPELLY;
	VARIANT_BOOL bRet;
	CString strCmdString;
	strCmdString.LoadString(IDS_CMD_STRING);
	strCmdString = szCommand + strCmdString;
	CComBSTR bszCmdString(strCmdString);
	CComBSTR bszMethod(_T("SpellyCommandMethod"));
	CComBSTR bszCmdName(szCommand);
	VERIFY_OK(pApplication->AddCommand(bszCmdString, bszMethod, 0, m_dwCookie, &bRet));

	LPCTSTR szCommand2 = CMD_NAME_SPELLY_NO_CODE;
	VARIANT_BOOL bRet2;
	CString strCmdString2;
	strCmdString2.LoadString(IDS_CMD_STRING_NO_CODE);
	strCmdString2 = szCommand2 + strCmdString2;
	CComBSTR bszCmdString2(strCmdString2);
	CComBSTR bszMethod2(_T("SpellyNoCodeCommandMethod"));
	CComBSTR bszCmdName2(szCommand2);
	VERIFY_OK(pApplication->AddCommand(bszCmdString2, bszMethod2, 1, m_dwCookie, &bRet2));

/*
	if (bRet == VARIANT_FALSE || bRet2 == VARIANT_FALSE) {
		// AddCommand failed because a command with this name already
		//  exists.  You may try adding your command under a different name.
		//  Or, you can fail to load as we will do here.
		*OnConnection = VARIANT_FALSE;
		return S_OK;
	}
*/

    if (bFirstTime == VARIANT_FALSE)
    {
        // see if we have a registry setting forcing a first time init
        bFirstTime = VARIANT_TRUE;
        int i = 0;
        CString sHost;
        while (AfxExtractSubString(sHost, cfg_sInitedEnvs, i++))
        {
            if (sHost.CompareNoCase(host_path) == 0)
            {
                bFirstTime = VARIANT_FALSE;
                break;
            }
        }
    }

    // the following is a trick that will allow up to add a toolbar even
    // if bFirstTime is false
    if (bFirstTime == VARIANT_TRUE)
    {
        CTBAdderWnd *pAdder = new CTBAdderWnd();
        pAdder->CreateEx(0, NULL, "", WS_CHILD, CRect(0, 0, 1, 1), 
            CWnd::GetDesktopWindow(), 0);
        pAdder->PostMessage(WM_CLOSE);
        cfg_sInitedEnvs += '\n';
        cfg_sInitedEnvs += host_path;
    }

	*OnConnection = VARIANT_TRUE;
	return S_OK;
}

// This is called on shut-down, and also when the user unloads the add-in
STDMETHODIMP CDSAddIn::OnDisconnection(VARIANT_BOOL bLastTime)
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState());

	m_pCommands->Release();
	m_pCommands = NULL;

	// TODO: Perform any cleanup work here

	return S_OK;
}

void CDSAddIn::AddToolbarCmds() const
{
	VERIFY_OK(m_pApplication->
		AddCommandBarButton(dsGlyph, CComBSTR(CMD_NAME_SPELLY), m_dwCookie));
	VERIFY_OK(m_pApplication->
		AddCommandBarButton(dsGlyph, CComBSTR(CMD_NAME_SPELLY_NO_CODE), 
        m_dwCookie));
}

⌨️ 快捷键说明

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