VS2015 C++ 插件开发-代码处理-格式化
来源:互联网 发布:it读音 编辑:程序博客网 时间:2024/06/05 19:21
// Command handler called when the user selects the "My Command" command.void OnMyCommand(CommandHandler* /*pSender*/, DWORD /*flags*/, VARIANT* /*pIn*/, VARIANT* /*pOut*/){CComPtr<IServiceProvider> spServiceProvider;this->GetSite(&spServiceProvider);if(spServiceProvider){CComPtr<IVsTextManager> spTextMgr;spServiceProvider->QueryService<IVsTextManager>(SID_SVsTextManager, &spTextMgr);if(spTextMgr){CComPtr<IVsTextView> spTextView;spTextMgr->GetActiveView(TRUE, NULL, &spTextView);if(spTextView){TextSpan txSpan;HRESULT hr1 = spTextView->GetSelectionSpan(&txSpan);if(hr1 == S_OK){CComBSTR bstrText;HRESULT hr2 = spTextView->GetSelectedText(&bstrText);if(hr2 == S_OK && bstrText){CString strChanged = FormatCode(CString(bstrText));if(strChanged.GetLength()){CComPtr < IVsTextLines> spTextLines;spTextView->GetBuffer(&spTextLines);if(spTextLines){TextSpan txSpan2;HRESULT hr3 = spTextLines->ReplaceLines(txSpan.iStartLine, txSpan.iStartIndex, txSpan.iEndLine, txSpan.iEndIndex, strChanged, strChanged.GetLength(), &txSpan2);if(hr3 == S_OK){spTextView->SetSelection(txSpan2.iStartLine, txSpan2.iStartIndex, txSpan2.iEndLine, txSpan2.iEndIndex);}}}}}}}}}
经过摸索,C++开发一个代码格式化插件的方法如下
(1)选择新建项目
(2)C++ / 扩展 /VSIX 包
(3)创建菜单命令工具
(4)编写代码处理选中文字,如下:
阅读全文
0 0
- VS2015 C++ 插件开发-代码处理-格式化
- NppAStyle代码格式化插件(C/C++/C#/JAVA)
- NppAStyle代码格式化插件(C/C++/C#/JAVA)
- Flex代码格式化插件
- Flex代码格式化插件
- XCode 代码格式化插件
- XCode代码格式化插件
- Notepad++格式化代码插件
- 为Qt Creator 开发astyle代码格式化插件
- wireshark2.4.2 vs2015 源码编译及C语言插件开发总结
- flex builder 代码格式化插件
- VS代码格式化小插件
- Flex Builder 代码格式化插件
- sql 代码格式化 优化 插件
- Flex actionscript 代码格式化插件
- flash builder 代码格式化插件
- flash builder 代码格式化插件
- eclipse 安装代码格式化插件
- 黄金交易所可能采用自主监管模型
- 加密货币与央行:货币非物质化的探索
- 澳大利亚比特币ATM数量从20台增加到500台
- 【国际】英国金融监管机构在R3 Corda平台之上构建区块链应用
- 删除超长文件夹及文件 小记
- VS2015 C++ 插件开发-代码处理-格式化
- 【转】整理:著名软件是使用什么语言写的?
- 我所理解的大数据个性化推荐
- 基于python开发环境的Dockerfile总结
- 【国际】韩国法院宣布没收比特币属不合法行为
- 分布式定时任务——elastic-job
- hive启动报错-Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
- spring <context:component-scan>使用说明
- 阿里云的Apache配置https