转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> VB.NET程序 >> 正文
Create Your Own Visual Basic Add-Ins         ★★★★

Create Your Own Visual Basic Add-Ins

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1624 更新时间:2009/4/23 16:39:28
Create Your Own Visual Basic Add-Ins
By S.S. Ahmed Rating: 3.7 out of 5
Rate this article


print this article

email this article to a colleague

Introduction

Programmers like me create add-ins primarily because we feel short of features when working with Microsoft tools.I It seems at times that Microsoft hasn''''t yet developed the tool we need. In fact, Microsoft has done a wonderful job of adding new features to each release of its development tools. Obviously, Microsoft can''''t design features to fulfill the needs of each and every programmer so it made Visual Basic (VB) an extensible product, thereby providing the way for VB developers to create their own features.

Download source code

EOM Defined

EOM stands for Extensibility Object Model. You might ask what is extensibility? Extensibility is the capability to extend or stretch the functionality of different development tools, specifically the Microsoft Integrated Development Environment (IDE). IDE provides a programming interface known as the Extensibility Object Model, a set of powerful interfaces for customizing the environment. It allows you to hook into the IDE to create extensions known as add-ins. A good system is the one that can be extended without jeopardizing the primary functionality of the system.

To implement extensibility features, VB offers the powerful EOM. Through EOM, many core objects in VB itself are available to you at no extra charge. EOM is not that easy to learn, and this article will provide you only the basics of add-in creation. You will have to delve into this vast field yourself to explore the wonders you can do using the EOM.

EOM consists of six loosely coupled packages of objects with methods that implement key services of the VB development model. These are:

  • Core Objects
  • Form Manipulation
  • Event Response
  • Add-In Management
  • Project and Component Manipulation
  • Code Manipulation

Core Objects

This package is the main package used in the creation of add-ins. It has the following objects:

  • The Root object
  • The IDTExtensibility Interface object
  • The Visual Basic Instance variable

The Root Object

VBE is the Root object in Visual Basic. The VBE object is the base object for every extensibility object and collection in Visual Basic. Each object and collection owns a reference to the VBE property. The collections owned by the VBE object include the following:

  • VBProjects
  • Windows
  • CodePanes
  • CommandBars

THE VBPROJECTS COLLECTION

This collection enables you to access a set of VB properties. This feature can be helpful if your development environment has an established process for developing software. Some of the key properties and methods of this collection are:

  • Filename: Returns the full pathname of the group project file.
  • Startproject: Returns or sets the project that will start when users choose the Start menu from the Run menu, click the Run button, or press the F5 key.
  • AddFromFile: This is a method that enables the users to add or open a project or group object. Its only required argument is the string representing the path of the file you want to add.
  • AddFromTemplate: This method enables you to add project templates into the VBProjects collection. Its only required argument is the string representing the path of the file you want to use as a template.

THE WINDOWS COLLECTION

With the Windows collection, you can access windows, such as the project and properties windows. This collection enables you to access a group of all currently open code windows and designer windows.

The IDTExtensibility Interface Object

The IDTExtensibility Interface object exposes the public methods and properties of the extensibility model. By exposes, I mean that because you don''''t directly use the services, methods, and properties of the underlying extensibility model, you need to invoke the methods of the model''''s agent. You can think of interfaces as public agents for the private implementation of an extensibility model object you instantiate.

The Visual Basic Instance Variable

This is also known as the dynamic identification variable. It identifies a particular instance of your VB session. This instance identifier enables you to have separately identifiable running instances of VB in memory.

The instance variable is of the type VBIDE.VBE. To use this variable, declare it in a class module or general module.

Please refer to the Microsoft Web site (see http://www.microsoft.com) for complete details of these packages. Please understand that I cannot explain each and every detail of these packages in this short article.

Creating the Add-In

We will build a simple add-in that will count the number of lines of code for a given program component. To begin creating the add-in, start a new project. Choose the AddIn project type. The AddIn project type includes many components necessary for creating VB add-ins. There is a form that you can modify to provide a user interface for your add-in. There is also a designer module that contains the four methods that are needed for the add-in''''s interface to VB. Users may read more about this at the Microsoft site (see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconcreatingaddin.asp).

Remove the OK and Cancel buttons from the form, and add the following controls to the form:

Control Type

Property

Value

Form

Name

FrmAddIn

 

Caption

Code Line Counter

Label

Name

LblProject

 

Caption

Project

TextBox

Name

TxtProject

Label

Name

LblComponent

 

Caption

Component

TextBox

Name

TxtComponent

CommandButton

Name

cmdCountCodeLines

 

Caption

Count Code Lines

CommandButton

Name

cmdDone

 

Caption

Done

Label

Name

LblCodeLines

 

Caption

Code Lines

TextBox

Name

TxtCodeLines

The Code

Here is the code:

.......................................................


Public VBInstance As VBIDE.VBE
Public Connect As Connect

Option Explicit

Private Sub cmdCountCodeLines_Click()

Dim strVBProject As String
Dim strVBComponent As String
Dim objVBComponent As VBComponent

''''Forms controls
strVBProject = txtProject.Text
strVBComponent = txtComponent.Text

''''Set objVBComponent to the program component suggested by
''''strVBProject and strVBComponent
Set objVBComponent = VBInstance.VBProjects.Item(strVBProject).VBComponents.Item(strVBComponent)

''''Assign the number of lines of code (CountOfLines) of the component
''''objVBComponent to the txtcodelines text box
txtCodeLines.Text = Str(objVBComponent.CodeModule.CountOfLines)



End Sub

Private Sub cmdDone_Click()

''''Hide the AddIn window
Connect.Hide

End Sub

.......................................................

Let''''s see what''''s in the code. The cmdCountCodeLines_click() is triggered when the user clicks on the Count Code Lines button. It uses the project and component names that were typed into the form''''s text box controls to assign that component to the objVBComponent object. Note the hierarchy used to obtain a component item in the following line of code:


Set objVBComponent = VBInstance.VBProjects.Item(strVBProject).VBComponents.Item(strVBComponent)

First, the VBInstance object is referenced and then its VBProjects collection. The current project''''s VBComponents collection is accessed by using the strVBComponent string as a key argument for the collection''''s item method. This long sequence of refe

[1] [2]  下一页


[系统软件]Visual Studio 2005 Express Beta Products 下载链…  [系统软件]Visual FoxPro9.0中扩展报表系统功能
[系统软件]Visual FoxPro:我是旁观者  [系统软件]Visual Studio 2005 Express Editions Beta 2 下载…
[系统软件]Boost库在XP+Visual C++.net中的安装  [系统软件]Visual Studio 2005 Express Edition 正式版下载地…
[常用软件]Visual Foxpro通用报表打印程序  [常用软件]Visual FoxPro 6.0与大型数据库的无数据源连接
[常用软件]Visual Foxpro 的一个BUG  [VB.NET程序]Visual Basic 6 逆向工程与反逆向工程 (2)
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台