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

📄 addinwindowmanager.cpp

📁 ResOrg 图形化管理Vc项目的资源ID的工具的源代码。 ResOrg - Manage and Renumber Resource Symbol IDs Introduction The
💻 CPP
字号:
/************************************************************************
 *
 *            Resource ID Organiser Add-In for Visual C++ .NET
 *
 * (c) Copyright 2000-2005 by Riverblade Limited (UK). All rights reserved.
 *
 ************************************************************************
 *                                                                       
 *  Description : CAddInWindowManager - Manages the ResOrg toolwindow
 *
 *  Compiler    : Microsoft Visual C++ .NET 2003
 *                                                                       
 *  Target                                                               
 *  Environment : Windows 2000/XP/Vista;
 *                Visual Studio 2002, 2003 or 2005
 *
 *  NOTE:
 *
 *    This software is provided "as is". All title and copyrights in and
 *    to the software, including but not limited to any images, text etc.
 *    etc. incorporated into it, are the property of Anna-Jayne Metcalfe
 *    and Riverblade Limited, except where acknowledged otherwise.
 *
 *    Your may freely use this code in your own products, PROVIDED
 *    this notice is not removed or modified.
 *
 *    Please visit http://www.riverblade.co.uk/products/resorg or email 
 *    support@riverblade.co.uk for latest updates and product support 
 *
 ************************************************************************
 *
 *   MODIFICATION HISTORY:
 *
 *           This is a controlled document. See project configuration
 *           control tool for latest version and full version history.
 *
 *    $Archive: /Projects/AddIns/ResOrg/ResOrgNETAddIn/AddInWindowManager.cpp $
 *   $Revision: 1 $
 *       $Date: 22/10/05 11:07 $
 *     $Author: Anna $
 *
 *    $History: AddInWindowManager.cpp $
 * 
 * *****************  Version 1  *****************
 * User: Anna         Date: 22/10/05   Time: 11:07
 * Created in $/Projects/AddIns/ResOrg/ResOrgNETAddIn
 * 
 * $Nokeywords: $
 *
 ************************************************************************/

#include "StdAfx.h"

#include "AddInWindowManager.h"




// The following GUIDs are uniquely generated to identify each toolwindow.
// They are NOT associated directly with any of the corresponding interfaces.
_bstr_t bsGUID_MainToolWindow	= _T("{B93C9C4C-4B90-47cf-AB45-208AE877550B}");



/////////////////////////////////////////////////////////////////////////////
// Support functions

static HPALETTE CreateDIBPalette(LPBITMAPINFO lpbmi, LPINT lpiNumColors)
{
	LPBITMAPINFOHEADER  lpbi;
	LPLOGPALETTE		lpPal;
	HANDLE				hLogPal;
	HPALETTE			hPal = NULL;
	int					i;

	lpbi = (LPBITMAPINFOHEADER)lpbmi;

	if (lpbi->biBitCount <= 8)
		*lpiNumColors = (1 << lpbi->biBitCount);
	else
		*lpiNumColors = 0;  // No palette needed for 24 BPP DIB

	if (lpbi->biClrUsed > 0)
		*lpiNumColors = lpbi->biClrUsed;  // Use biClrUsed

	if (*lpiNumColors)
	{
		hLogPal = GlobalAlloc(GHND, sizeof (LOGPALETTE) + sizeof (PALETTEENTRY) * (*lpiNumColors) );
		lpPal = (LPLOGPALETTE) GlobalLock (hLogPal);
		lpPal->palVersion    = 0x300;
		lpPal->palNumEntries = *lpiNumColors;

		for (i = 0;  i < *lpiNumColors;  i++)
		{
			lpPal->palPalEntry[i].peRed   = lpbmi->bmiColors[i].rgbRed;
			lpPal->palPalEntry[i].peGreen = lpbmi->bmiColors[i].rgbGreen;
			lpPal->palPalEntry[i].peBlue  = lpbmi->bmiColors[i].rgbBlue;
			lpPal->palPalEntry[i].peFlags = 0;
		}
		hPal = CreatePalette(lpPal);

		GlobalUnlock(hLogPal);
		GlobalFree(hLogPal);

	}
	return hPal;
}


static HBITMAP LoadResourceBitmap(HINSTANCE hInstance, LPSTR lpString, HPALETTE FAR* lphPalette)
{
	HRSRC  hRsrc;
	HGLOBAL hGlobal;
	HBITMAP hBitmapFinal = NULL;
	LPBITMAPINFOHEADER  lpbi;
	HDC hdc;
	int iNumColors;

	if (hRsrc = FindResource(hInstance, lpString, RT_BITMAP) )
	{
		hGlobal = LoadResource(hInstance, hRsrc);

		lpbi = (LPBITMAPINFOHEADER)LockResource(hGlobal);

		hdc = GetDC(NULL);

		*lphPalette =  CreateDIBPalette ((LPBITMAPINFO)lpbi, &iNumColors);
		if (*lphPalette)
		{
			SelectPalette(hdc,*lphPalette,FALSE);
			RealizePalette(hdc);
		}

		hBitmapFinal = CreateDIBitmap(	hdc,
			(LPBITMAPINFOHEADER)lpbi,
			(LONG)CBM_INIT,
			(LPSTR)lpbi + lpbi->biSize + iNumColors *

			sizeof(RGBQUAD), (LPBITMAPINFO)lpbi, DIB_RGB_COLORS );

		ReleaseDC(NULL,hdc);

		UnlockResource(hGlobal);
		FreeResource(hGlobal);
	}
	return (hBitmapFinal);
}


static EnvDTE::WindowPtr CreateToolWindow(	const CComPtr<EnvDTE::_DTE>& pDTE,
																		 const CComPtr<EnvDTE::AddIn>& pAddInInstance,
																		 const _bstr_t& bsDocObjProgID,
																		 const _bstr_t& bsTitle,
																		 const _bstr_t& bsGUIDTool,
																		 UINT uBitmapID)
{
	USES_CONVERSION;

	try
	{
		EnvDTE::WindowsPtr ptrWindows = pDTE->GetWindows();
		//IfNullIssueError(ptrWindows);

		CComPtr<IDispatch> pDocObjDisp;

		EnvDTE::WindowPtr ptrToolWindow = ptrWindows->CreateToolWindow(	pAddInInstance,
																		bsDocObjProgID,
																		bsTitle,
																		bsGUIDTool,
																		&pDocObjDisp);

		if (ptrToolWindow != NULL)
		{
			CComBSTR bsSatelliteDll;
			pAddInInstance->get_SatelliteDllPath(&bsSatelliteDll.m_str);

			//TRACE( _T("ResOrg.NET Satellite DLL path: %s\n"), OLE2T(bsSatelliteDll.m_str) );
			HMODULE hModule = ::LoadLibrary( OLE2CT(bsSatelliteDll.m_str) );
			ATLASSERT(NULL != hModule);

			if (NULL != hModule)
			{
				PICTDESC pd;
				pd.cbSizeofstruct	= sizeof(PICTDESC);
				pd.picType			= PICTYPE_BITMAP;

				pd.bmp.hbitmap = ::LoadResourceBitmap(hModule,
					MAKEINTRESOURCE(uBitmapID),
					&pd.bmp.hpal);

				//lint -save -e929 (Note -- cast from pointer to pointer)
				CComPtr<IPictureDisp> pPictureDisp;
				::OleCreatePictureIndirect(&pd, IID_IPictureDisp, FALSE, (LPVOID*)&pPictureDisp);

				CComVariant varPic;
				pPictureDisp->QueryInterface(IID_IUnknown, (LPVOID*)&varPic.punkVal);
				//lint -restore

				varPic.vt = VT_UNKNOWN;

				ptrToolWindow->SetTabPicture(varPic);

				// We no longer need the original copies of the bitmap and palette so close the handles [IMS ID 18]
				::DeleteObject(pd.bmp.hbitmap);
				::DeleteObject(pd.bmp.hpal);
			}
			::FreeLibrary(hModule);

			return ptrToolWindow;
		}
	}
	catch (const _com_error& e)
	{
		HRESULT hr = e.Error();

		UNREFERENCED_PARAMETER(hr);
	}
	return NULL;
}


/////////////////////////////////////////////////////////////////////////////
// CAddInWindowManager construction/destruction

CAddInWindowManager::CAddInWindowManager(void)
{
}


CAddInWindowManager::CAddInWindowManager(const CComPtr<EnvDTE::_DTE>& pDTE)
{
	OnConnection(pDTE, NULL);
}


CAddInWindowManager::~CAddInWindowManager(void)
{
	try
	{
		m_pDTE						= NULL;
	}
	catch (...)
	{
		ATLASSERT(!"CAddInWindowManager::~CAddInWindowManager(): Unexpected exception in destructor!");
	}
}


/////////////////////////////////////////////////////////////////////////////
// CAddInWindowManager operations

HRESULT CAddInWindowManager::OnConnection(	const CComPtr<EnvDTE::_DTE>& pDTE,
										const CComPtr<EnvDTE::AddIn>& pAddInInstance)
{
	m_pDTE = pDTE;
	ATLASSERT(m_pDTE != NULL);

	m_pAddInInstance = pAddInInstance;

	return S_OK;
}


HRESULT CAddInWindowManager::OnDisconnection(AddInDesignerObjects::ext_DisconnectMode eRemoveMode)
{
	// When an add-in is unloaded it's toolwindows aren't automatically closed by the IDE, so it's better if
	// we close them ourselves. This is a known bug in Visual Studio .NET 2002 and 2003.
	// Please refer to MSDN KB article 555258 ("BUG: AutoHide ToolWindow remains open after unloading Visual
	// Studio .NET add-in" - http://support.microsoft.com/default.aspx?scid=kb;en-us;555258) for details.
	//
	switch ( (int)eRemoveMode)
	{
		case 0 /*AddInDesignerObjects::ext_dm_HostShutdown*/:			// Application is closing down. 

		case 2 /*AddInDesignerObjects::ext_dm_UISetupComplete*/:		// Environment setup completed. Since we don't
																// create our toolwindows in this case, we don't
																// need to close them!
			break;

		case 1 /*AddInDesignerObjects::ext_dm_UserClosed*/:			// The user cleared its check box in the Add-In Manager
																// dialog box, or when the Connect property of the
																// corresponding AddIn object was set to False.

		case 3 /*AddInDesignerObjects::ext_dm_SolutionClosed*/:		// The Add-in was unloaded when the solution was closed.
																// Received by solution Add-ins. 
			try
			{
				m_ptrMainToolWindow->Close(EnvDTE::vsSaveChangesNo);
			}
			catch(const _com_error& e)
			{
				UNREFERENCED_PARAMETER(e);
			}
			break;

		default:
			ATLASSERT(false);
			break;
	}
	return S_OK;
}



bool CAddInWindowManager::CreateToolWindows(void)
{
	try
	{
		m_ptrMainToolWindow = ::CreateToolWindow(m_pDTE,
																				m_pAddInInstance,
																				_T("ResOrgNETAddIn.MainToolWindowCtrl.1"),
																				_T("ResOrg"),
																				bsGUID_MainToolWindow,
																				IDR_VIEW_MAIN_TOOLWIN_CMD);
		ATLASSERT(m_ptrMainToolWindow != NULL);

		IDispatchPtr ptrDisp = m_ptrMainToolWindow->GetObject();

		//lint -save -e929 (Note -- cast from pointer to pointer)
		ptrDisp->QueryInterface(IID_IMainToolWindowCtrl, (void**)&m_pMainToolWindowCtrl);
		//lint -restore
	}
	catch (const _com_error& e)
	{
		UNREFERENCED_PARAMETER(e);
	}

	return true;
}


/////////////////////////////////////////////////////////////////////////////
// CAddInWindowManager implementation
// (none)



/////////////////////////////////////////////////////////////////////////////
// CAddInWindowManager message handlers
// (none)

⌨️ 快捷键说明

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