本文介绍了如何扩展Visual C++ 6 (VC6) 的编辑能力,利用宏和Add-in功能提高代码编写效率。通过将宏代码保存为.dsm格式并绑定快捷键,实现类似vi或emacs的命令式编辑。内容包括宏的安装、快捷键设置方法,以及一些实用宏的示例,如选中单词、注释/取消注释代码块和打开资源文件。虽然未能找到VC6的VBA对象来进一步定制,但作者鼓励读者自行编写或在codeproject上寻找更多宏。
Sub doubleclick() 'DESCRIPTION: For simulated double clicking 'Begin Recording ActiveDocument.Selection.WordLeft ActiveDocument.Selection.WordRight dsExtend 'End Recording End Sub
简单吧
第二个宏,注释和解除注释块
Sub CommentBlock() With ActiveDocument.Selection '对于当前窗口打开的文档中选中的文本 .ReplaceText "%", "//", dsMatchRegExpB '在开始位置增加 // 注释 EndWith End Sub Sub UncommentBlock() With ActiveDocument.Selection .ReplaceText "%//", "", dsMatchRegExpB '同样的,去掉在选择文本中开头找到的注释符号 EndWith End Sub Sub CommentLine() With ActiveDocument.Selection n = .SelectLine .MoveTo n,0 EndWith ActiveDocument.Selection ="//" End Sub Sub UnCommentLine() End Sub
第三个,以资源脚本形式打开资源文件;
Sub OpenRCFile() 'DESCRIPTION: Opens the primary .rc file as text 'NOTE: If the resource file is already open within the ' resource editor, you may be asked if you wish to ' close it. ' Simply strip the project filename of its extension... ' ...and replace it with "rc" If Projects.Count =0Then MsgBox"Load a project first." ExitSub EndIf PathName = ActiveProject.fullname PathName =Left(PathName, Len(PathName)-3) PathName = PathName +"rc" Documents.Open PathName, "Text" End Sub