Click here to Skip to main content
11,493,046 members (66,689 online)
Click here to Skip to main content
Add your own
alternative version

WTL Helper

, 27 Aug 2007 411.5K 7.9K 186
Add-in for Microsoft VC++.NET 2003 that helps to insert message handlers for WTL.
wtlhelper.zip
WTLHelper.exe
wtlhelper_exe.zip
WTLHelper.exe
wtlhelper_src.zip
source
AddIn.def
Dialog
vssver.scc
Options
res
a1.ico
AddIn.rgs
addin8.rgs
closefld.ico
Clsdfold.ico
DDX.bmp
dialog.bmp
functoolbar.bmp
icons.bmp
message.ico
msg.bmp
mysmall4.bmp
openfld.ico
Openfold.ico
option.bmp
vartoolbar.bmp
vssver.scc
wizard.bmp
Wizard.ico
WtlHelper.dll.manifest
resources
Setup.nsi
WtlHelperRes
res
DDX.bmp
dialog.bmp
msg.bmp
option.bmp
reflect.bmp
wizard.bmp
WtlHelperRes.aps
WtlHelperRes8.vcproj.MINSK.solozhentsev.user
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2004 Sergey Solozhentsev
// Author: 	Sergey Solozhentsev e-mail: salos@mail.ru
// Product:	WTL Helper
// File:      	VSElements.h
// Created:	16.11.2004 8:55
// 
//   Using this software in commercial applications requires an author
// permission. The permission will be granted to everyone excluding the cases
// when someone simply tries to resell the code.
//   This file may be redistributed by any means PROVIDING it is not sold for
// profit without the authors written consent, and providing that this notice
// and the authors name is included.
//   This file is provided "as is" with no expressed or implied warranty. The
// author accepts no liability if it causes any damage to you or your computer
// whatsoever.
//
////////////////////////////////////////////////////////////////////////////////

#pragma		once
#include <atlstr.h>
#include <crtdbg.h>

__inline LPTSTR ToTCHAR(_bstr_t str)
{
#ifdef _UNICODE
	return (wchar_t*)str;
#else
	return (char*)str;
#endif

}

struct VSElement;

struct VSElement
{
	CString Name;
	EnvDTE::CodeElementPtr pElement;
	VSElement* pParent;
	EnvDTE::vsCMElement ElementType;
	VSElement(EnvDTE::vsCMElement Type) : pElement(NULL), pParent(NULL), ElementType(Type)
	{
	}

	virtual ~VSElement()
	{
	}
	HRESULT RetriveName(bool bFullName = false)
	{
		_bstr_t str;
		HRESULT hRes;
		ATLASSERT(pElement != NULL);
		if (bFullName)
		{
			hRes = pElement->get_FullName(str.GetAddress());
			if (FAILED(hRes))
			{
				return hRes;
			}
			Name = ToTCHAR(str);
		}
		else
		{
			hRes = pElement->get_Name(str.GetAddress());
			if (FAILED(hRes))
			{
				return hRes;
			}
			Name = ToTCHAR(str);
		}
		return S_OK;
	}

	virtual HRESULT GetStartPoint(EnvDTE::EditPoint** ppEditPoint);
	virtual HRESULT GetEndPoint(EnvDTE::EditPoint** ppEditPoint);
	virtual HRESULT Remove(){return S_FALSE;};
	
};

struct VSVariable : public VSElement
{
	EnvDTE::vsCMAccess Access;
	BOOL bStatic;
	BOOL bConst;
	VSVariable(EnvDTE::vsCMElement Type = EnvDTE::vsCMElementVariable):VSElement(Type),
		Access(EnvDTE::vsCMAccessPrivate), bStatic(FALSE), bConst(FALSE){};
	HRESULT RetriveType();
	CString Type;
	HRESULT Remove();
};

struct VSParameter : public VSElement
{
	VSParameter():VSElement(EnvDTE::vsCMElementParameter){};
	CString Type;
	HRESULT RetriveType();
	//HRESULT RetriveName();
};

struct VSFunction : public VSElement
{
	EnvDTE::vsCMFunction Kind;
	BOOL bStatic;
	BOOL bVirtual;
	BOOL bConst;
	BOOL bInline;
	CString Type;
	EnvDTE::vsCMAccess Access;
	LPARAM lParam;
	VSFunction(EnvDTE::vsCMElement Type = EnvDTE::vsCMElementFunction):VSElement(Type), 
		Access(EnvDTE::vsCMAccessPublic), bStatic(FALSE), bConst(FALSE), 
		bVirtual(FALSE), bInline(FALSE), lParam(0){};
	CSmartAtlArray<VSParameter*> Parameters;
	VSFunction(VSFunction& Func);
	HRESULT RetriveParameters();
	HRESULT RetriveType();
	HRESULT RetrieveAccess();
	virtual HRESULT Remove();
	void DeleteAllItems();
	
	virtual ~VSFunction();
};

struct VSMapEntry : public VSFunction
{
	HRESULT GetStartPoint(EnvDTE::EditPoint** ppEditPoint);
	HRESULT GetEndPoint(EnvDTE::EditPoint** ppEditPoint);
	HRESULT Remove();
	VSMapEntry(EnvDTE::EditPoint* pStart = NULL, EnvDTE::EditPoint* pEnd = NULL):m_pEndPoint(pEnd), 
		m_pStartPoint(pStart), pData(NULL), VSFunction(EnvDTE::vsCMElementMapEntry){};
	VSMapEntry(const VSMapEntry& MapEntry);
	virtual ~VSMapEntry();

	EnvDTE::EditPointPtr m_pStartPoint;
	EnvDTE::EditPointPtr m_pEndPoint;
	void* pData;
};

struct VSMap : public VSElement
{
	CSmartAtlArray<VSMapEntry*> MapEntries;
	CSmartAtlArray<VSParameter*> MapParameters;
	CString Postfix;
	HRESULT RetriveMapEntries();
	VSMap():VSElement(EnvDTE::vsCMElementMap), m_pEndPoint(NULL), m_pStartPoint(NULL){};
	VSMap(EnvDTE::EditPointPtr pStartPoint) :VSElement(EnvDTE::vsCMElementMap), 
		m_pEndPoint(NULL), m_pStartPoint(pStartPoint){};
	virtual ~VSMap();
	HRESULT GetEndPoint(EnvDTE::EditPoint** ppEditPoint);
	HRESULT GetStartPoint(EnvDTE::EditPoint** ppEditPoint);
	HRESULT InsertNewMap(EnvDTE::EditPointPtr pInsertAfter, bool bAfter = true);
	HRESULT InsertMapEntry(VSMapEntry* MapEntry);
	HRESULT Remove();
	void DeleteAllItems();
	bool IsSelf();
protected:
	EnvDTE::EditPointPtr m_pEndPoint;
	EnvDTE::EditPointPtr m_pStartPoint;

	virtual HRESULT FindPlaceForNewItem(VSMapEntry* MapEntry, EnvDTE::EditPoint** ppStartPoint);
	//return false when end of map
	virtual bool AddMapEntry(VSMapEntry* pMapEntry);
};

enum MessageEntryType {MESSAGE_WINDOWS, MESSAGE_COMMAND, MESSAGE_NOTIFY, 
MESSAGE_UNKNOWN, MESSAGE_CHAIN_MAP, MESSAGE_FORWARD_REFLECT, MESSAGE_ANOTHER};

struct VSMessageMap : public VSMap
{
	bool bSortItems;
	bool bCorrectEnd;
	CSmartAtlArray<VSMessageMap*> AltMaps;
	VSMessageMap():bSortItems(true), bCorrectEnd(true){};
	VSMessageMap(EnvDTE::EditPoint* pStartPoint) : VSMap(pStartPoint), bSortItems(true), bCorrectEnd(true){};
	~VSMessageMap();
	HRESULT ReFormatItems();
	HRESULT GetEndPoint(EnvDTE::EditPoint** ppEditPoint);
	HRESULT InsertAltMap(VSMessageMap* pAltMap);
	HRESULT Remove();
	HRESULT ReplacePrefixEnd();
	//only windows messages
	static bool FindMapEntryByMessage(CString Message, VSMessageMap* pMap, CAtlArray<VSMapEntry*>& MapEntries);
protected:
	HRESULT FindPlaceForNewItem(VSMapEntry* MapEntry, EnvDTE::EditPoint** ppStartPoint);
	MessageEntryType GetEntryType(VSMapEntry* MapEntry);
	bool AddMapEntry(VSMapEntry* pMapEntry);
};

struct VSBase : public VSElement
{
	CSmartAtlArray<VSParameter*> TemplateParameters;

	VSBase():VSElement(EnvDTE::vsCMElementVCBase){};
	~VSBase();

	bool RetrieveTemplateParameters();
};

enum eBoolUnknown
{
	eUnknown,
	eFalse,
	eTrue	
};

struct VSClass : public VSElement
{
private:
	bool m_bRetrieved;
protected:
	CString GetDialogID(EnvDTE::CodeElementPtr pElem);
	bool FindPlaceForNewVar(_variant_t& Pos, EnvDTE::vsCMAccess NeededAccess);
	EnvDTE::EditPointPtr FindLastPublicElement();
	bool FindPlaceForNewMap(EnvDTE::EditPoint** ppEditPoint);
	bool FindPlaceForNewMessageMap(EnvDTE::EditPoint** ppEditPoint, VSMessageMap* pMap);
	void RemoveMapMacrosFromFunctions();
	void AddMessageMapMacros(VSMessageMap* pMap, CAtlMap<CString, int>& Strings);
	bool IsMapEntryName(CString Name);
public:
	CSmartAtlArray<VSVariable*> Variables;
	CSmartAtlArray<VSFunction*> Functions;
	CSmartAtlArray<VSMap*> Maps;
	CSmartAtlArray<VSBase*> Parents;
	CSmartAtlArray<VSClass*> NestedClasses;
	EnvDTE::CodeModel* pCodeModel;
	CSmartAtlArray<CString> Headers;
	//bool m_bAtlCrack;
	//bool m_bAtlMisc;
	//true ���� ����� ���������� �� CWinDataExchange � ������� ���� atlddx.h
	bool m_bDDX;
	eBoolUnknown m_eDialog;
	CString m_DialogID;
	
	VSClass():VSElement(EnvDTE::vsCMElementClass), /*m_bAtlCrack(false), m_bAtlMisc(false),*/
	m_eDialog(eUnknown), m_bDDX(false), m_bRetrieved(false){};
	bool IsDialog();
	
	HRESULT AddElement(EnvDTE::CodeElementPtr pElement);
	HRESULT RetriveItems();
	void DeleteAllItems();
	VSMap* GetMap(CString MapName);
	HRESULT InsertFunction(VSFunction* pFunc, CString Comment, 
		EnvDTE::vsCMFunction FuncType = EnvDTE::vsCMFunctionFunction,
		_variant_t Position = _variant_t(VCCodeModelLibrary::vsCMAddPositionEnd));
	HRESULT InsertMap(VSMap* pMap);
	HRESULT InsertVariable(VSVariable* pVar);
	HRESULT InsertBase(VSBase* pBase);
	virtual ~VSClass();
};

struct VSInclude : public VSElement
{
	VSInclude() : VSElement(EnvDTE::vsCMElementIncludeStmt){};
};

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

Sergey Solozhentsev
Web Developer
Belarus Belarus
I am a software developer for 3 years.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150520.1 | Last Updated 27 Aug 2007
Article Copyright 2004 by Sergey Solozhentsev
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid