Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Project Line Counter Add-In v2.10 for VS.NET and VC6

, 29 Jun 2003
Get statistics about your source code with a click of a button
linecount_dll.zip
LineCount.dll
WWhizInterface.mod
LineCount.chm
linecount_src.zip
LineCount.dsw
LineCount_VC5.dsw
LineCount.dsp
LineCount_VC5.dsp
LineCount.odl
LineCount.def
LineCount.clw
Help
arrowrt.gif
Index.hhk
LineCount.chm
LineCount.hhp
mailto.gif
metl011.gif
PLC.gif
small_exclamation.gif
TOC.hhc
weblink.gif
res
idr_main.ico
project.ico
TBarLrge.bmp
TBarMedm.bmp
title.ico
ExtrnSrc
Release
LineCount.dll
WWhizInterface.mod
LineCount.chm
plc110src.zip
plc111.zip
WWhizInterfaceInstaller210Beta1.exe
LineCount.dll
LineCount.chm
plc111src.zip
WWhizInterfaceInstaller210Beta1.exe
LineCount.dll
LineCount.chm
Source
LineCount.dsw
LineCount_VC5.dsw
LineCount.dsp
LineCount_VC5.dsp
LineCount.odl
LineCount.def
Help
.cvsignore
Index.hhk
LineCount.hhp
PLC.gif
TOC.hhc
arrowrt.gif
mailto.gif
metl011.gif
small_exclamation.gif
weblink.gif
res
TBarLrge.bmp
TBarMedm.bmp
idr_main.ico
project.ico
title.ico
ExtrnSrc
Debug
WWhizInterface2D.mod
plc150.zip
WWhizInterfaceInstaller212.exe
LineCount.dll
LineCount.chm
Reports
SampleAnalysis.xls
Simple-BW.xsl
Simple-Color.xsl
plc150src.zip
WWhizInterfaceInstaller212.exe
LineCount.dll
LineCount.chm
SampleAnalysis.xls
Simple-BW.xsl
Simple-Color.xsl
LineCount.dsw
LineCount.dsp
LineCount.odl
LineCount.def
LineCount.clw
.cvsignore
TOC.hhc
linecount.hhp
arrowrt.gif
Index.hhk
PLC.gif
mailto.gif
small_exclamation.gif
weblink.gif
info_dot_small.gif
TBarLrge.bmp
idr_main.ico
project.ico
HdrDownA.bmp
HdrUpA.bmp
title.ico
info.ico
TBarMedm.bmp
WWhizInterface2D.mod
plc200.zip
LineCount.cab
WWhizInterface30VC6_1016.exe
plc200src.zip
.cvsignore
LineCount.def
LineCount.dsp
LineCount.dsw
LineCount.odl
ResizableLib
.cvsignore
ResizableLib.dsp
ResizableLib.dsw
.cvsignore
Index.hhk
LineCount.hhp
PLC.gif
TOC.hhc
arrowrt.gif
info_dot_small.gif
mailto.gif
small_exclamation.gif
weblink.gif
ObjModelVC6
ObjModelVC7
MSADDNDR.tlh
MSO.tlh
dte.tlh
HdrDownA.bmp
HdrUpA.bmp
LineCountVC6.rgs
LineCountVC7.rgs
TBarLrge.bmp
TBarMedm.bmp
idr_main.ico
info.ico
lcgo.bmp
project.ico
title.ico
WWhizInterface2D.mod
plc210.zip
SetupPLC210.exe
plc210src.zip
.cvsignore
LineCount.def
LineCount.dsp
LineCount.dsw
LineCount.odl
.cvsignore
ResizableLib.dsp
ResizableLib.dsw
.cvsignore
Index.hhk
LineCount.hhp
PLC.gif
TOC.hhc
arrowrt.gif
info_dot_small.gif
mailto.gif
small_exclamation.gif
weblink.gif
MSADDNDR.tlh
MSO.tlh
dte.tlh
HdrDownA.bmp
HdrUpA.bmp
LineCountVC6.rgs
LineCountVC7.rgs
TBarLrge.bmp
TBarMedm.bmp
gallery.xsl
idr_main.ico
info.ico
lcgo.bmp
project.ico
title.ico
WWhizInterface2D.mod
/***************************************************************************/
/* NOTE:                                                                   */
/* This document is copyright (c) by Oz Solomonovich, and is bound by the  */
/* MIT open source license (www.opensource.org/licenses/mit-license.html). */
/* See License.txt for more information.                                   */
/***************************************************************************/

// Connect.cpp : Implementation of CConnect
#include "stdafx.h"

#ifdef TARGET_VC7

#include "LineCount.h"
#include "ConnectVC7.h"
#include "WorkspaceInfo.h"
#include "ResultsDlg.h"
#include "Config.h"

const wchar_t * const TOOLBAR_NAME      = L"PLC (Project Line Counter)";

const wchar_t * const COMMAND_NAME_FULL = L"LineCount.CountLines";
const wchar_t * const COMMAND_NAME      = L"CountLines";
const wchar_t * const COMMAND_TEXT      = L"Count Lines";
const wchar_t * const COMMAND_TIP       = L"Count lines of code in your projects";

// When run, the Add-in wizard prepared the registry for the Add-in.
// At a later time, if the Add-in becomes unavailable for reasons such as:
//   1) You moved this project to a computer other than which is was originally created on.
//   2) You chose 'Yes' when presented with a message asking if you wish to remove the Add-in.
//   3) Registry corruption.
// you will need to re-register the Add-in by building the MyAddin21Setup project 
// by right clicking the project in the Solution Explorer, then choosing install.


// CConnect
STDMETHODIMP CConnect::OnConnection(IDispatch *pApplication, AddInDesignerObjects::ext_ConnectMode ConnectMode, IDispatch *pAddInInst, SAFEARRAY ** /*custom*/ )
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    HRESULT hr = S_OK;
    pApplication->QueryInterface(__uuidof(EnvDTE::_DTE), (LPVOID*)&m_pDTE);
    pAddInInst->QueryInterface(__uuidof(EnvDTE::AddIn), (LPVOID*)&m_pAddInInstance);

    OnAddinConnect();

    if(ConnectMode == 5 /* AddInDesignerObjects::ext_cm_UISetup */)
    {
        CComPtr<EnvDTE::Commands> pCommands;
        CComPtr<EnvDTE::Command> pCreatedCommand;

        hr = m_pDTE->get_Commands(&pCommands);

        if (SUCCEEDED(hr))
        {
            hr = pCommands->Item(CComVariant(COMMAND_NAME_FULL), 0, 
                &pCreatedCommand);

            // remove command if it's already there
            if (SUCCEEDED(hr)  &&  pCreatedCommand)
            {
                pCreatedCommand->Delete();
                pCreatedCommand = NULL;
            }

            // add our command
            hr = pCommands->AddNamedCommand(
                m_pAddInInstance, 
                CComBSTR(COMMAND_NAME), 
                CComBSTR(COMMAND_TEXT), 
                CComBSTR(COMMAND_TIP), 
                VARIANT_FALSE, 
                IDB_LCGO,  // MSO: 127
                NULL, 
                EnvDTE::vsCommandStatusSupported+EnvDTE::vsCommandStatusEnabled, 
                &pCreatedCommand);

            if (SUCCEEDED(hr)  &&  pCreatedCommand)
            {
                CComPtr<Office::_CommandBars>      pCommandBars;
                CComPtr<Office::CommandBarControl> pCommandBarControl;
                CComQIPtr<Office::CommandBar>      pToolbar;

                hr = m_pDTE->get_CommandBars(&pCommandBars);
                if (SUCCEEDED(hr))
                {
                    // Get our toolbar
                    hr = pCommandBars->get_Item(CComVariant(TOOLBAR_NAME), 
                        &pToolbar);
                    if (!SUCCEEDED(hr))
                    {
                        // haven't created the toolbar yet
                        CComPtr<IDispatch> pDisp;
                        hr = pCommands->AddCommandBar((LPWSTR)TOOLBAR_NAME,
                            EnvDTE::vsCommandBarTypeToolbar, NULL, 0, 
                            &pDisp);        
                        if (SUCCEEDED(hr))
                        {
                            pToolbar = pDisp;
                        }
                        if (pToolbar == NULL)
                        {
                            hr = E_FAIL;
                        }
                    }
                    else
                    {
                        // make sure visible
                        pToolbar->put_Visible(VARIANT_TRUE);
                    }
                }
                if (SUCCEEDED(hr))
                {
                    // this causes a memory leak -- don't know why
                    hr = pCreatedCommand->AddControl(pToolbar, 1, 
                        &pCommandBarControl);
                    if (SUCCEEDED(hr))
                    {
                        // make sure it's image only
                        CComQIPtr<Office::_CommandBarButton> 
                            pButton(pCommandBarControl);
                        if (pButton) pButton->put_Style(Office::msoButtonIcon);
                    }
                }
            }
        }
        
        return hr;
    }

    if (g_pWorkspaceInfo == NULL)
    {
        InitializeWorkspaceInfo_VC7(m_pDTE);
    }

    return hr;
}

STDMETHODIMP CConnect::OnDisconnection(AddInDesignerObjects::ext_DisconnectMode /*RemoveMode*/, SAFEARRAY ** /*custom*/ )
{
    OnAddinDisconnect();
    
    m_pDTE = NULL;
    return S_OK;
}

STDMETHODIMP CConnect::OnAddInsUpdate (SAFEARRAY ** /*custom*/ )
{
    return S_OK;
}

STDMETHODIMP CConnect::OnStartupComplete (SAFEARRAY ** /*custom*/ )
{
    return S_OK;
}

STDMETHODIMP CConnect::OnBeginShutdown (SAFEARRAY ** /*custom*/ )
{
    return S_OK;
}

STDMETHODIMP CConnect::QueryStatus(BSTR bstrCmdName, EnvDTE::vsCommandStatusTextWanted NeededText, EnvDTE::vsCommandStatus *pStatusOption, VARIANT *pvarCommandText)
{
  if(NeededText == EnvDTE::vsCommandStatusTextWantedNone)
    {
      if(!_wcsicmp(bstrCmdName, COMMAND_NAME_FULL))
      {
          *pStatusOption = (EnvDTE::vsCommandStatus)
              (EnvDTE::vsCommandStatusEnabled |
               EnvDTE::vsCommandStatusSupported);
      }
  }
    return S_OK;
}

STDMETHODIMP CConnect::Exec(BSTR bstrCmdName, EnvDTE::vsCommandExecOption ExecuteOption, VARIANT * /*pvarVariantIn*/, VARIANT * /*pvarVariantOut*/, VARIANT_BOOL *pvbHandled)
{
    *pvbHandled = VARIANT_FALSE;
    if(ExecuteOption == EnvDTE::vsCommandExecOptionDoDefault)
    {
        if(!_wcsicmp(bstrCmdName, COMMAND_NAME_FULL))
        {
            AFX_MANAGE_STATE(AfxGetStaticModuleState());
            try
            {
                CResultsDlg dlg(g_pWorkspaceInfo);
                dlg.DoModal();
            }
            catch (...)
            {
                AfxMessageBox(
                    "Exception caught in LineCounter.\n"
                    "You should save all your work and restart Visual Studio.", 
                    MB_OK | MB_ICONEXCLAMATION);
            }
            *pvbHandled = VARIANT_TRUE;
            return S_OK;
        }
    }
    return S_OK;
}

#endif // TARGET_VC7

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Oz Solomon
Experion
Canada Canada
You may know Oz from his WndTabs days. Oz has long since left client side development to work on web technologies and to consult in the R&D management field.

| Advertise | Privacy | Mobile
Web02 | 2.8.140926.1 | Last Updated 30 Jun 2003
Article Copyright 2000 by Oz Solomon
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid