Chinaunix首页 | 论坛 | 博客
  • 博客访问: 80573
  • 博文数量: 27
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 300
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-21 11:32
文章分类

全部博文(27)

文章存档

2010年(3)

2009年(13)

2008年(11)

我的朋友

分类: C/C++

2009-05-24 16:16:36

IAECommand插件开发介绍(C#语言)

C#开发和VC++开发原理完全一样。

²        打开Microsoft Visual Studio 2005。选择新建C#项目,然后在模板列表中选择“类库”,最后输入项目名称。按“确定”完成项目的创建,输入项目名称“TestCommandClassLibrary”,当然,你可以依据自己喜好任意命名。项目创建完毕,同时已经建立了一个类,名称是“Class1”,修改类名称为“TestCommand”。

 

 

²        AEBase引用添加到当前项目中来。方法是,菜单:项目 \ 添加引用

 

 

 

 

接下来,在弹出的对话框中选择上AEBase组件,按“确定”,关闭设置对话框,完成引用的添加。

 

 

 

²        给类“Class1”增加一个基类:“AEBaseLib.AECommand”。最后类的定义如下:

using System;

using System.Collections.Generic;

using System.Text;

 

namespace TestCommandClassLibrary

{

    public class TestCommand : AEBaseLib.AECommand

    {

    }

}

 

²        实现基类的接口。在“AEBaseLib.AECommand”上按鼠标右键,选择“实现接口 \ 实现接口”命令。系统将自动把接口函数添加到类中了。

 

 

 

 

 

 

 

接口实现之后的类如下:

using System;

using System.Collections.Generic;

using System.Text;

 

namespace ClassLibrary1

{

    public class TestCommand : AEBaseLib.AECommand

    {

        #region IAECommand 成员

 

        public void Deactivate(out bool pVal)

        {

            throw new Exception("The method or operation is not implemented.");

        }

 

        public void GetCaption(out string caption)

        {

            throw new Exception("The method or operation is not implemented.");

        }

 

        public void GetCategory(out string category)

        {

            throw new Exception("The method or operation is not implemented.");

        }

 

        public void GetChecked(out bool pVal)

        {

            throw new Exception("The method or operation is not implemented.");

        }

 

        public void GetContextMenu(int type, out string name)

        {

            throw new Exception("The method or operation is not implemented.");

        }

 

        public void GetEnabled(out bool pVal)

        {

            throw new Exception("The method or operation is not implemented.");

        }

 

        public void GetIcon(out int icon)

        {

            throw new Exception("The method or operation is not implemented.");

        }

 

        public void GetTooltip(out string tooltip)

        {

            throw new Exception("The method or operation is not implemented.");

        }

 

        public void OnClick()

        {

            throw new Exception("The method or operation is not implemented.");

        }

 

        public void OnCreate(object hook)

        {

            throw new Exception("The method or operation is not implemented.");

        }

 

        public void OnKeyDown(int keycode, int shift)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        public void OnKeyUp(int keycode, int shift)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        public void OnMouseDown(int button, int shift, int x, int y)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        public void OnMouseMove(int button, int shift, int x, int y)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        public void OnMouseUp(int button, int shift, int x, int y)

        {

            throw new Exception("The method or operation is not implemented.");

        }

        public void Refresh()

        {

            throw new Exception("The method or operation is not implemented.");

        }

        #endregion

    }

}

现在更改该类,增加一个基本的对话框提示。最终的代码如下:

using System;

using System.Collections.Generic;

using System.Text;

using System.Runtime.InteropServices;

 

 

namespace ClassLibrary1

{

    [Guid("1A71B9BA-DB3B-4bb0-8AA2-0CC0F3912864")]

    public class TestCommand : AEBaseLib.AECommand

    {

        #region IAECommand 成员

 

        public void Deactivate(out bool pVal)

        {

            pVal = true;

        }

 

        public void GetCaption(out string caption)

        {

            caption = "C#开发的插件";

        }

 

        public void GetCategory(out string category)

        {

            category = "C#开发的插件";

        }

 

        public void GetChecked(out bool pVal)

        {

            pVal = true;

        }

 

        public void GetContextMenu(int type, out string name)

        {

            name = null;

        }

 

        public void GetEnabled(out bool pVal)

        {

            pVal = true;

        }

 

        public void GetIcon(out int icon)

        {

            icon = 0;

        }

 

        public void GetTooltip(out string tooltip)

        {

            tooltip = "来自C#语言的插件提示";

        }

 

        public void OnClick()

        {

                 // 测试弹出一个对话框来。

            MessageBox.Show("测试弹出一个对话框来。");

        }

 

        public void OnCreate(object hook)

        {

        }

 

        public void OnKeyDown(int keycode, int shift)

        {

        }

 

        public void OnKeyUp(int keycode, int shift)

        {

        }

 

        public void OnMouseDown(int button, int shift, int x, int y)

        {

        }

 

        public void OnMouseMove(int button, int shift, int x, int y)

        {

        }

 

        public void OnMouseUp(int button, int shift, int x, int y)

        {

        }

 

        public void Refresh()

        {

        }

 

        #endregion

    }

}

 

 

 

 

 

 

 

 

 

 

 

 

 

阅读(957) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~