正文

用ATL实现VC插件(1)2008-03-24 22:14:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/lym51/33555.html

分享到:

用ATL实现VC插件

 

作者: IUNKNOW 出处: vchelp

 

4) 选择属性对话框的Names标签,在C++组的Short Name编辑框输入Copyright(如图)



  5) 选择DevStudio Add-in标签,在Add-in Features中选择Application Events,选择OK按钮确定



  上面的步骤生成基本Add-in框架代码

  6) 创建IDE工具条

   a) 创建两个Bitmap 文件作为工具条图像资源

    IDB_TOOLBAR_LARGE_COPYRIGHT 32 x 32大小

    IDB_TOOLBAR_MEDIUM_COPYRIGHT 16 x 16 大小

   b) 在Ccopyright 类的OnConnection()函数中加入创建工具条按钮的代码, 详细代码:

HRESULT CCopyright::OnConnection(IApplication* pApp,
VARIANT_BOOL bFirstTime, long dwAddInID, VARIANT_BOOL* bOnConnection)
{
HRESULT hr = S_OK;
m_spApplication = pApp;
m_dwAddInID = dwAddInID;

// Connect up to application event sink
AtlAdvise(pApp, GetUnknown(), IID_IApplicationEvents, &m_dwAppEvents);

hr = pApp->SetAddInInfo((long)_Module.GetModuleInstance(),
static_cast<ICopyright*>(this), IDB_TOOLBAR_MEDIUM_COPYRIGHT,
IDB_TOOLBAR_LARGE_COPYRIGHT, dwAddInID);

// LPCTSTR szCommand = _T("ShowInfoDlg");
VARIANT_BOOL bRet;
if (SUCCEEDED(hr))
{
hr = pApp->AddCommand(CComBSTR(_T("ShowInfoDlg&Iuml;&Ocirc;&Ecirc;&frac34;
&ETH;&THORN;&cedil;&Auml;&Oacute;&Atilde;&raquo;&micro;&Auml;
&aelig;&Egrave;¨&ETH;&Aring;&Iuml;&cent;
&ETH;&THORN;&cedil;&Auml;°&aelig;&Egrave;
&ETH;&Aring;&Iuml;&cent;")),CComBSTR(_T("ShowInfoDlg")), 0, dwAddInID, &bRet);
hr = pApp->AddCommand(CComBSTR(_T("MiniWindow\n&Euml;&otilde;&ETH;&iexcl;
\n×&icirc;&ETH;&iexcl;&raquo;&macr;&Euml;&Oacute;&ETH;&micro;&Auml;&acute;
&iquest;&Uacute;&icirc;&ETH;&iexcl;&raquo;&macr;&acute;°&iquest;&Uacute;")),
CComBSTR(_T("MiniWindow")), 1, dwAddInID, &bRet);
hr = pApp->AddCommand(CComBSTR(_T("MaxWindow\n·&Aring;&acute;
&icirc;&acute;&raquo;&macr;&Euml;&Oacute;&ETH;&micro;&Auml;&acute;
&iquest;&Uacute;&icirc;&acute;&raquo;&macr;&acute;
&iquest;&Uacute;")),CComBSTR(_T("MaxWindow")), 2, dwAddInID, &bRet);
hr = pApp->AddCommand(CComBSTR(_T("Test\nTest\nTest\nTest")),CComBSTR(_T("Test")), 3, dwAddInID, &bRet);
}

// 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)
{
if (SUCCEEDED(hr))
{
hr = pApp->AddCommandBarButton(dsGlyph, CComBSTR(_T("ShowInfoDlg")), dwAddInID);
hr = pApp->AddCommandBarButton(dsGlyph, CComBSTR(_T("MiniWindow")), dwAddInID);
hr = pApp->AddCommandBarButton(dsGlyph, CComBSTR(_T("MaxWindow")), dwAddInID);
hr = pApp->AddCommandBarButton(dsGlyph, CComBSTR(_T("Test")), dwAddInID);

}
}
//
CRegKey reg;
TCHAR strName[256];
DWORD dwSize = 256,dwRet = 0;
reg.Create(HKEY_CURRENT_USER,_T("Software\\Evesoft\\Addins"));
dwRet = reg.QueryValue(strName,_T("NAME"),&dwSize);
if(dwRet != ERROR_SUCCESS || lstrlen(strName) == 0)
m_bstrName = _T("Evelan");
else
m_bstrName = strName;

dwSize = 100;
dwRet = reg.QueryValue(strName,_T("EMAIL"),&dwSize);
if(dwRet != ERROR_SUCCESS || lstrlen(strName) == 0)
m_bstrEmail = _T("dbw.evelan@263.net");
else
m_bstrEmail = strName;

//

*bOnConnection = SUCCEEDED(hr) ? VARIANT_TRUE :VARIANT_FALSE;
return hr;
}

HRESULT CCopyright::OnDisconnection(VARIANT_BOOL bLastTime)
{
AtlUnadvise(m_spApplication, IID_IApplicationEvents, m_dwAppEvents);
return S_OK;
}

  此段代码主要用了Application Object的两个方法AddCommand()和AddCommandBarButton(),AddCommand()方法调用后,在菜单的Tools/Customize 中的Commands标签中的Categroy列表框中就会有对应的Command命令(),

阅读(2827) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册