📄 dsaddin.cpp
字号:
// AddInMod.cpp : implementation file
/*********************************************************************
* class: 提供Visual Studio要求的接口方法
* Author: Simon Wang
* Date: 2000-11-21
* Contact us: inte2000@263.net
* Web Page: http://www.winmsg.com/cn/orbit.htm (for Chinese version)
* http://www.winmsg.com/orbit.htm (for English version)
**********************************************************************/
#include "stdafx.h"
#include "TabBars.h"
#include "DSAddIn.h"
#include "Commands.h"
#include "Common\SplashWnd.h"
#include "TabBarWnd.h"
#include "TabManagerWnd.h"
#include "DevStudioWnd.h"
#include "DS_MDIWnd.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
long g_dwCookie;
CDevStudioWnd *g_pDevStudioWnd;
/*
extern int AddInCallback(LPCTSTR pCmd);
#if _MSC_VER <= 1100 // for VC 5 (steal from shlwapi.h)
struct DLLVERSIONINFO
{
DWORD cbSize;
DWORD dwMajorVersion; // Major version
DWORD dwMinorVersion; // Minor version
DWORD dwBuildNumber; // Build number
DWORD dwPlatformID; // DLLVER_PLATFORM
};
typedef HRESULT (CALLBACK* DLLGETVERSIONPROC)(DLLVERSIONINFO *);
#endif
static DWORD GetDllVersion(LPCTSTR lpszDllName)
{
HINSTANCE hinstDll;
DWORD dwVersion = 0;
hinstDll = LoadLibrary(lpszDllName);
if(hinstDll)
{
DLLGETVERSIONPROC pDllGetVersion;
pDllGetVersion = (DLLGETVERSIONPROC)GetProcAddress(hinstDll, _T("DllGetVersion"));
if(pDllGetVersion)
{
DLLVERSIONINFO dvi;
HRESULT hr;
ZeroMemory(&dvi, sizeof(dvi));
dvi.cbSize = sizeof(dvi);
hr = (*pDllGetVersion)(&dvi);
if(SUCCEEDED(hr))
{
dwVersion = PACKVERSION(dvi.dwMajorVersion,dvi.dwMinorVersion);
}
}
FreeLibrary(hinstDll);
}
return dwVersion;
}
*/
// 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)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
#ifndef _DEBUG
CSplashWnd *pSplash = new CSplashWnd(IDB_SPLASH);
pSplash->Create();
#endif
// pSplash->ShowWindow(SW_HIDE);
HWND hWnd, hMDIWnd, hDevStudioWnd, hDesktopWnd = ::GetDesktopWindow();;
m_pCommands = NULL;
pApp->put_Active(VARIANT_FALSE);
pApp->put_Active(VARIANT_TRUE);
hWnd = ::GetActiveWindow();
while (hWnd && hWnd != hDesktopWnd)
{
hDevStudioWnd = hWnd;
hWnd = ::GetParent(hWnd);
}
g_pDevStudioWnd = new CDevStudioWnd(hDevStudioWnd); //CWnd::FromHandle(hDevStudioWnd);
// Store info passed to us
IApplication* pApplication = NULL;
if (FAILED(pApp->QueryInterface(IID_IApplication, (void**) &pApplication))
|| pApplication == NULL)
{
#ifndef _DEBUG
if(pSplash->GetSafeHwnd())//close splash window if this window still show
pSplash->DestroyWindow();;
#endif
*OnConnection = VARIANT_FALSE;
return S_OK;
}
m_dwCookie = dwCookie;
g_dwCookie = dwCookie;
// Create command dispatch, send info back to DevStudio
CCommandsObj::CreateInstance(&m_pCommands);
m_pCommands->AddRef();//keep it alive otherwise it will be deleted
// The QueryInterface above AddRef'd the Application object. It will
// be Release'd in CCommand's destructor.
m_pCommands->SetApplicationObject(pApplication);
VERIFY_OK(pApplication->SetAddInInfo((long) AfxGetInstanceHandle(),
(LPDISPATCH) m_pCommands, IDR_TOOLBAR_MEDIUM, IDR_TOOLBAR_LARGE, m_dwCookie));
// Inform DevStudio of the commands we implement
// two rules for commands:
// 1. the method name must be the command name
// 2. the commands must appear below in the order of their toolbar
// buttons
/*
struct cmd
{
LPCTSTR szCommand;
int sCmdString;
};
static cmd commands[] =
{
{ _T("OSHeaderFlip"), IDC_HEADERFLIP },//associate toolbar button
{ _T("OSSetCurrDir"), IDC_SETCURRDIR },
{ _T("OSOpenAsText"), IDC_OPENASTEXT },
{ _T("OSBlockRemark"), IDC_BLOCKREMARK },
{ _T("OSRemark"), IDC_REMARK },
{ _T("OSUnremark"), IDC_UNREMARK },
{ _T("OSFuncDesc"), IDC_FUNCDESCR },
{ _T("OSOptions"), IDC_OPTIONS }
};
const nCommands = (sizeof(commands)/sizeof(cmd));
*/
VARIANT_BOOL bRet;
CString strCmdString;
CComBSTR bszCmdString, bszMethod;
for (int i = 0; i < nCommandItem; i++)
{
strCmdString.LoadString(g_toolbar_cmds[i].sCmdString);
strCmdString = g_toolbar_cmds[i].szCommand + strCmdString;
bszCmdString = strCmdString;
bszMethod = g_toolbar_cmds[i].szCommand;
VERIFY_OK(pApplication->AddCommand(bszCmdString, bszMethod, i, m_dwCookie, &bRet));
if (bRet == 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.
#ifndef _DEBUG
if(pSplash->GetSafeHwnd())
pSplash->DestroyWindow();
#endif
*OnConnection = VARIANT_FALSE;
return S_OK;
}
}
// find the MDI client area window
{
char cClassName[256];
hMDIWnd = g_pDevStudioWnd->GetTopWindow()->m_hWnd;
::GetClassName(hMDIWnd, (LPTSTR)cClassName, sizeof(cClassName));
while (strcmp(cClassName, "MDIClient") != 0)
{
hMDIWnd = ::GetNextWindow(hMDIWnd, GW_HWNDNEXT);
ASSERT(hMDIWnd);
GetClassName(hMDIWnd, (LPTSTR)cClassName, sizeof(cClassName));
}
}
// create the tabs window
pGlobalTabs = new CTabBarsWnd(m_pCommands);
pGlobalTabs->CreateEx(WS_EX_NOPARENTNOTIFY, NULL, "TabBar",
WS_CHILD | WS_CLIPSIBLINGS, CRect(0, 0, 0, 0), g_pDevStudioWnd, 0);
// make sure that all MDI window events (especially size changes...)
// pass through our handlers
pGlobalMDIManager->DoSubclass(hMDIWnd);
if (cfg_iSnap == ssMDI)
{
// set the the manager (MDI snap)
pGlobalActiveManager = pGlobalMDIManager;
pGlobalActiveManager->SetManaging(true);
}
// Add toolbar buttons only if this is the first time the add-in
// is being loaded. Toolbar buttons are automatically remembered
// by Developer Studio from session to session, so we should only
// add the toolbar buttons once.
if (bFirstTime == VARIANT_TRUE)
{
CIni ini(g_szIniPathName);
CString strKey;
CComBSTR bszKeystroke;
CComBSTR bszEditor(lpszCommandWnd);
for(int i = 0; i < nCommandItem; i++)
{
cmd& theCmd = g_toolbar_cmds[i];
VERIFY_OK(pApplication->AddCommandBarButton(dsGlyph,CComBSTR(theCmd.szCommand), g_dwCookie));
ini.GetValue(lpszToolbar,g_szHotkeyItem[i],strKey);
if(strKey.GetLength() > 0)
{
bszKeystroke = strKey;
VERIFY_OK(pApplication->AddKeyBinding(bszKeystroke,CComBSTR(theCmd.szCommand),bszEditor));
}
}
ini.Clear();
/*
CComBSTR bszKeystroke;
CComBSTR bszEditor(g_szEdNames[nTmp]);
for (i = 0; i < nCommands; i++)//register every command and shortkey
{
cmd& theCmd = commands[i];
VERIFY_OK(pApplication->AddCommandBarButton(dsGlyph,CComBSTR(theCmd.szCommand), g_dwCookie));
if(strSelect[i] == _T('1'))
{
bszKeystroke = strBaseKey + strKey[i];
VERIFY_OK(pApplication->AddKeyBinding(bszKeystroke,CComBSTR(theCmd.szCommand),bszEditor));
}
}
*/
}
CComBSTR bStr;
pApplication->get_CurrentDirectory(&bStr);
g_strPrjSetFile = bStr;
g_strPrjSetFile += _T("\\BookMark.dat");
// if(pSplash->GetSafeHwnd())
// pSplash->DestroyWindow();
*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());
if (m_pCommands)
{
m_pCommands->UnadviseFromEvents();
m_pCommands->Release();
m_pCommands = NULL;
}
delete g_pDevStudioWnd;
return S_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -