高速掌握VC6.0中各种宏注释(附图)

为了方便别人或自己阅读自己的程序,注释是坚决不可少的。一个漂亮的程序,不是在于你应用的技术多么高深,而是能够把高深的技术描述的清楚易懂。

在Java的IDE环境——Eclispe中,有很多中注释的,并且设置注释也是很方便的,因为现在从事C++,嘻嘻,Eclispe已经卸载,至于设置注释的地方,直接百度或谷歌即可。

所以嘛,习惯了Eclispe的注释,所以想法设法,在VC6.0中尝试。当对于一个陌生的东西而言,如何熟悉他呢,就是拿你现在已有的知识,去联想。比如Java中截取字符串,或解析xml等,一个语言中有,另一个语言中十之八九也有的。

并且在VB.NET中,当时添加各种注释,是通过宏定义的,相比之下,还是喜欢Eclispe设置,因为更加傻瓜,直接选择添加宏定义比如$Date

那么来说一下,在VC6.0中是如何添加常用的文件头注释和函数方法注释。

在上上篇博客中,已经介绍了一种,使用CTRL+\来注释某一行的或多行。并且在上篇博客中也介绍了插件的使用,其中就有多行注释。

我们说一下,使用宏定义的方式,来添加文件头和函数的注释,也就是自己定义脚本,嘻嘻,是VB6.0的脚本吼,看见那种Sub End Sub,还是蛮亲切的哦

第一:打开VC6.0程序,工具——定制——附加项和宏定义——勾选SAMPLE

高速掌握VC6.0中各种宏注释(附图)

第二:打开VC6.0程序,选择工具——宏

高速掌握VC6.0中各种宏注释(附图)

第三:点击确定。出现各种宏的界面。

高速掌握VC6.0中各种宏注释(附图)

第四:在宏名称中,写自己需要定义的注释名称。比如函数注释——FunctionDesc。然后点击编辑。

Sub FunctionDesc()

End Sub

PS:可以对设置的注释,进行快捷键设置,类似Java中的CTRL+SHIFT+\

点击选项:

高速掌握VC6.0中各种宏注释(附图)

高速掌握VC6.0中各种宏注释(附图)

第五:填充vb脚本。若是您的脚本技术了得,那就自己写喽,若是想省事可以直接copy或者modify一下即可。我函数描述脚本如下:

Sub FunctionDesc()
Dim doc
    set doc = ActiveDocument
    ' Be sure active document is a text document
    if doc Is Nothing Then
        Exit Sub
    elseif doc.Type <> "Text" Then
        Exit Sub
    End If
doc.Selection = "/** " 
doc.Selection.NewLine
doc.Selection = " * 函数名 : "
doc.Selection.LineDown
doc.Selection.copy
doc.Selection.LineUp
doc.Selection.EndOfLine dsLastText
doc.Selection = doc.Selection + " "
doc.Selection.paste
doc.Selection = " * 功能描述:" 
doc.Selection.NewLine
doc.Selection = "* 输入参数:" 
doc.Selection.NewLine
doc.Selection = "* 输出参数:" 
doc.Selection.NewLine
doc.Selection = "* 返回值 :"
doc.Selection.LineDown
doc.Selection.StartOfLine dsFirstText
' doc.Selection.CharRight   dsExtend, 4
doc.Selection.WordRight dsExtend, 1
doc.Selection.copy
doc.Selection.LineUp
doc.Selection.EndOfLine dsLastText
doc.Selection = doc.Selection + " "
doc.Selection.paste
doc.Selection.NewLine
doc.Selection = "* 作者    : lhy " 
doc.Selection.NewLine
doc.Selection = "* 创建日期: " + CStr(Now()) 
doc.Selection.NewLine
doc.Selection = "*/ " 
End Sub


 
 

文件头注释类似:文件头注释如下:

Sub FileDesc()

Dim doc
    set doc = ActiveDocument
    ' Be sure active document is a text document
    if doc Is Nothing Then
        Exit Sub
    elseif doc.Type <> "Text" Then
        Exit Sub
    End If

doc.Selection.MoveTo 1, 1
doc.Selection.NewLine
doc.Selection.MoveTo 1, 1
doc.Selection = "/** " 
doc.Selection.NewLine
doc.Selection = " * 版权说明 Contect copyright (c)"
doc.Selection.NewLine
doc.Selection = "* 文件名 : " + ActiveDocument.Name 
doc.Selection.NewLine
doc.Selection ="* 文件描述:"
doc.Selection.NewLine
doc.Selection = "* 创建日期: " + CStr(Now()) 
doc.Selection.NewLine
doc.Selection = "* 作者    : lhy" 
doc.Selection.NewLine
doc.Selection = "*/ " 

End Sub


<pre class="html" name="code" style="padding: 0px; margin-top: 0px; margin-bottom: 0px; color: rgb(51, 51, 51); font-size: 14px; line-height: 24px; background-color: rgb(255, 255, 255);">效果如下哈:


<pre name="code" class="cpp">/** 
 * 函数名 :  active(long processInstID,long activityInstID)
 * 功能描述: 激活指定业务功能的窗口。
 * 输入参数: 流程实例id,活动实例id
 * 输出参数:
 * 返回值 : active
 * 作者    : lhy 
 * 创建日期: 2012/10/11 10:26:42
 */ 
HRESULT active(long processInstID,long activityInstID)
{
  
	//动态加载客户的动态链接库
	//加载动态链接库
	HINSTANCE  hDLL=LoadLibrary("customerdll.dll");
	
	//声明函数指针
	typedef HRESULT (*activeBusiness)(long,long);
	if(hDLL==NULL)
		return S_FALSE;
	
	//加载动态链接库中函数的地址
	activeBusiness activeBusinessFunc=(activeBusiness)GetProcAddress(hDLL,"active");
	//判断地址是否为空
	if(activeBusinessFunc==NULL)
		return S_FALSE;
	
	
    activeBusinessFunc(processInstID,activityInstID);
	
	//释放动态链接库
	FreeLibrary(hDLL);
    return S_OK;
}


 
 


 

其中的样式,可以自己更改,比如//或*。但是这种注释,还是达不到Eclispe中,因为在Eclispe中,每个参数已经在注释中了,这样就直接对每个参数,进行中文解释而已。而这种方式,输入参数,是自己手动填写的。o(︶︿︶)o

另一种更简单的做法如下:

第一:编写脚本,放在安装路径下Macros。后缀是DSM。我的DSM文件路径如下:

高速掌握VC6.0中各种宏注释(附图)

第二:选择宏文件

高速掌握VC6.0中各种宏注释(附图)

第三:载入文件后,工具—定制中会自动出现或浏览相应路径下相应的文件

高速掌握VC6.0中各种宏注释(附图)

第四:操作完毕,进一步设置快捷键,类似第一种方法中设置快捷键,工具—宏—选择相应的宏进行设置

高速掌握VC6.0中各种宏注释(附图)

到此为止,最常用的两种注释,都已经添加啦。目前我设置的规范注释就两种,快捷键全部设置java中的快捷键。

遇到陌生的事物,其实请不必因担心顾虑而失去冷静。可以用以前学的知识去剖析这个所谓陌生的东东,陌生中肯定会有您所熟悉亲切的一部分。剩下那部分陌生部分,再在亲切的感觉中慢慢摸索。纵然知道新手,肯定不如老手熟练,效率高,但是谁都有新手的时候,谁有都有老手的时候。

本文转载:http://www.ylzx8.cn/windows/vc-mfc/122460.html  (未找到原帖,非常感谢作者!!!)

下面贴出我自己写的宏文件:

'------------------------------------------------------------------------------
'FILE DESCRIPTION: New Macro File
'------------------------------------------------------------------------------

Sub FileNote()
Dim doc
    set doc = ActiveDocument
    ' Be sure active document is a text document
    if doc Is Nothing Then
        Exit Sub
    elseif doc.Type <> "Text" Then
        Exit Sub
    End If
doc.Selection.MoveTo 1, 1
doc.Selection.NewLine
doc.Selection.MoveTo 1, 1
doc.Selection = "/*"
for i=0 to 60
	doc.Selection = "*"
next
doc.Selection.NewLine
doc.Selection = " * 文件名    : " + ActiveDocument.Name
doc.Selection.NewLine
doc.Selection = "* 简要描述: "
doc.Selection.NewLine
doc.Selection = "* 编译环境: Microsoft Visual C++ 6.0 (SP6)"
doc.Selection.NewLine
doc.Selection = "* 当前版本: 0.0.0"
doc.Selection.NewLine
doc.Selection = "* 取代版本: 0.0.0"
doc.Selection.NewLine
doc.Selection = "* 作者        : Semaphores"
doc.Selection.NewLine
doc.Selection = "* 邮箱        : Semaphores@qq.com"
doc.Selection.NewLine
doc.Selection = "* 博客        : http://blog.csdn.net/semaphores"
doc.Selection.NewLine
doc.Selection = "* 创建日期: " + CStr(Now())
doc.Selection.NewLine
doc.Selection = "* 修改日期: " + CStr(Now())
doc.Selection.NewLine
doc.Selection = "* Copyright(c) 2014 Semaphores. All rights reserved."
doc.Selection.NewLine
doc.Selection = "*"
doc.Selection.NewLine
doc.Selection = "* 修改时间:                   修正版本:    修改描述:"
doc.Selection.NewLine
doc.Selection = "* " + CStr(Now())+"  0.0.0" + "             " + "创建当前工程"
doc.Selection.NewLine
for i=0 to 60
	doc.Selection = "*"
next
	doc.Selection = "*/"
doc.Selection.NewLine
End Sub


Sub FunctionNote()
Dim doc
    set doc = ActiveDocument
    ' Be sure active document is a text document
    if doc Is Nothing Then
        Exit Sub
    elseif doc.Type <> "Text" Then
        Exit Sub
    End If
doc.Selection.NewLine
doc.Selection = "/*"
for i=0 to 60
	doc.Selection = "*"
next
doc.Selection.NewLine
doc.Selection = "* 函数描述: "
doc.Selection.NewLine
doc.Selection = "* 函数参数: "
doc.Selection.NewLine
doc.Selection = "* 函数返回: "
doc.Selection.NewLine
doc.Selection = "* 函数备注: "
doc.Selection.NewLine
for i=0 to 60
	doc.Selection = "*"
next
	doc.Selection = "*/"
End Sub

Sub VoidNote()
Dim doc
    set doc = ActiveDocument
    ' Be sure active document is a text document
    if doc Is Nothing Then
        Exit Sub
    elseif doc.Type <> "Text" Then
        Exit Sub
    End If
doc.Selection.NewLine
doc.Selection = "/*"
for i=0 to 60
	doc.Selection = "*"
next
doc.Selection.NewLine
doc.Selection = "* Void: Void"
doc.Selection.NewLine
for i=0 to 60
	doc.Selection = "*"
next
	doc.Selection = "*/"
End Sub

Sub GetFileNameNote()
Dim doc
    set doc = ActiveDocument
    ' Be sure active document is a text document
    if doc Is Nothing Then
        Exit Sub
    elseif doc.Type <> "Text" Then
        Exit Sub
    End If
MsgBox "FileName: " + ActiveDocument.Name
End Sub

Sub LineNote()
Dim doc
    set doc = ActiveDocument
    ' Be sure active document is a text document
    if doc Is Nothing Then
        Exit Sub
    elseif doc.Type <> "Text" Then
        Exit Sub
    End If
doc.Selection.NewLine
doc.Selection = "/*"
for i=0 to 60
	doc.Selection = "*"
next
doc.Selection = "/"
doc.Selection.NewLine
End Sub

参考:http://xinxing124.blog.163.com/blog/static/30170195201036104555855/


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值