设为首页 加入收藏

TOP

用ATL实现VC插件(三)
2012-11-04 15:22:31 来源: 作者: 【 】 浏览:729
Tags:ATL 实现 插件
  如果我增加一条这样的命令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;
}

首页 上一页 1 2 3 4 下一页 尾页 3/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇ATL接口映射宏详解 下一篇共享内存实现进程间大数据的交换

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: