正文

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

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

分享到:

用ATL实现VC插件

 

作者: IUNKNOW 出处: vchelp

 

如果我增加一条这样的命令AddCommand(CComBSTR(_T("ShowInfoDlg\n显示\n修改用户版权信息\n显示")),CComBSTR(_T("ShowInfoDlg")), 0, dwAddInID, &bRet);在Categroy的All Commands中就能找到ShowInfoDlg这条命令。AddCommandBarButton()方法就是向IDE集成环境增加一个工具条按钮,程序中可以不调用此方法,可以手动拖拉到工具条上。打开菜单Tools/Customize 用鼠标拽拉你需要的的命令到工具条上即可(如图)



  在Ccopyright 类NewDocument()方法中的代码,主要就是增加必要的版权信息到文档中,此处主要是说明怎样操作VC环境中文档,大家也得到具体的Windows来修改窗口的形状和属性,怎么修改就要看各自的想象力了。

HRESULT CCopyright::NewDocument(IDispatch* theDocument)
{
CComQIPtr <ITextDocument,&IID_ITextDocument> pTextDoc(theDocument);
HRESULT hr = S_OK;
CComBSTR bstrLang;
if (pTextDoc == NULL) return hr;

hr = pTextDoc->get_Language(&bstrLang);
if (FAILED(hr))
return hr;
//&micro;&Atilde;&micro;&frac12;&Icirc;&Auml;&frac14;
&thorn;&Agrave;à&ETH;&Iacute;&pound;&not;&sup2;&cent;
&micro;&Atilde;&sup3;&ouml;&para;&Ocirc;&Oacute;&brvbar;&micro;&Auml;
×&cent;&Ecirc;&Iacute;·&ucirc;
CComBSTR bstrComment;
if (bstrLang == DS_CPP)
bstrComment = L"//";
else if (bstrLang == DS_HTML_IE3 || bstrLang == DS_HTML_RFC1866)
bstrComment = L"<!--";
else if (bstrLang == DS_IDL)
bstrComment = L"//";
else if (bstrLang == DS_VBS)
bstrComment = L"\'";
else if (bstrLang == DS_JAVA)
bstrComment = L"//";
else
bstrComment = L";";

CComBSTR bstrType;
hr = pTextDoc->get_Type(&bstrType);
if(FAILED(hr))
return hr;
if(bstrType == DS_TEXT_DOCUMENT)
{
CComQIPtr <ITextSelection,&IID_ITextSelection> pTextSel;
CComPtr<IDispatch> pDisp;
hr = pTextDoc->get_Selection(&pDisp);
if(FAILED(hr))
return hr;
pTextSel = pDisp;
hr = pTextSel->StartOfDocument(CComVariant());
if(FAILED(hr))
return hr;

SYSTEMTIME st;
GetLocalTime(&st);
TCHAR strDate[30];
TCHAR strYear[5];
wsprintf(strYear,_T("%ld"),st.wYear);
wsprintf(strDate,_T("%ld&Auml;ê%ld&Ocirc;&Acirc;%ld&Egrave;&Otilde;"),st.wYear,st.wMonth,st.wDay);

CComBSTR bstrText;
bstrText = bstrComment;
bstrText += "\n";
if (!(bstrLang == DS_HTML_IE3 || bstrLang == DS_HTML_RFC1866))
bstrText += bstrComment;
bstrText += L" °&aelig;&Egrave;¨&Euml;ù&Oacute;&ETH;(C) Robin Hohai University ";
bstrText += strYear;
bstrText += L"\n";
if (!(bstrLang == DS_HTML_IE3 || bstrLang == DS_HTML_RFC1866))
bstrText += bstrComment;
bstrText += L"\n";
if (!(bstrLang == DS_HTML_IE3 || bstrLang == DS_HTML_RFC1866))
bstrText += bstrComment;
bstrText += L" ×÷ &Otilde;&szlig;&pound;&ordm;";
bstrText += m_bstrName;
bstrText += L" E-mail&pound;&ordm;";
bstrText += m_bstrEmail;
bstrText += L"\n";
if (!(bstrLang == DS_HTML_IE3 || bstrLang == DS_HTML_RFC1866))
bstrText += bstrComment;
bstrText += L"\n";
if (!(bstrLang == DS_HTML_IE3 || bstrLang == DS_HTML_RFC1866))
bstrText += bstrComment;
bstrText += L" &acute;&acute;&frac12;¨&Egrave;&Otilde;&AElig;&Uacute;&pound;&ordm;";
bstrText += strDate;
bstrText += L"\n";
if (!(bstrLang == DS_HTML_IE3 || bstrLang == DS_HTML_RFC1866))
bstrText += bstrComment;
if (bstrLang == DS_HTML_IE3 || bstrLang == DS_HTML_RFC1866)
bstrText += L" -->";
bstrText += L"\n";

hr = pTextSel->put_Text(bstrText);
}
return hr;
}

阅读(2735) | 评论(0)


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

评论

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