Visual Studio 2010(c#)开发ActiveX控件及制作CAB包总结(1)

1、开发及测试环境:

(1)开发环境:

          Visual Studio 2010

           cabsdk(下载地址:http://support.microsoft.com/kb/310618)

(2)测试环境:

          Windows xp          IE6

2、创建项目

 

我这里创建了三个项目:

(1)HelloBossma :

项目模板:Windows窗体控件库

(2)HelloBossmaSetup:

项目模板:安装项目 

(3)Web:

项目模板:ASP.NET 网站

3、HelloBossma项目

这个项目用于编写具体的控件,并生成安装文件所需要的dll。

(1)添加用户控件:

 

(2)设计控件:

 

添加Panel、GroupBox、Label 控件。NowTime是一个Label控件,用于显示时间。

然后在控件对应的代码文件中编写程序:

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Drawing;

using System.Data;

using System.Text;

using System.Windows.Forms;
using System.Runtime.InteropServices;

 

 

namespace HelloBossma
{

    /// <summary> 

    /// Guid将用作控件的classid 

    /// IObjectSafety的是用来标记可安全执行脚本的ActiveX控件 

    /// </summary> 

    [Guid("636B8CE1-7512-464C-B63C-FC75BDCA21DB"), ProgId("HelloBossma.HelloBossmaActiveX"), ComVisible(true)]

    public partial class HelloBossmaActiveX : UserControl, IObjectSafety
    {

        private const string _IID_IDispatch = "{00020400-0000-0000-C000-000000000046}";

        private const string _IID_IDispatchEx = "{a6ef9860-c720-11d0-9337-00a0c90dcaa9}";

        private const string _IID_IPersistStorage = "{0000010A-0000-0000-C000-000000000046}";

        private const string _IID_IPersistStream = "{00000109-0000-0000-C000-000000000046}";

        private const string _IID_IPersistPropertyBag = "{37D84F60-42CB-11CE-8135-00AA004BB851}";

 

        private const int INTERFACESAFE_FOR_UNTRUSTED_CALLER = 0x00000001;

        private const int INTERFACESAFE_FOR_UNTRUSTED_DATA = 0x00000002;

        private const int S_OK = 0;

        private const int E_FAIL = unchecked((int)0x80004005);

        private const int E_NOINTERFACE = unchecked((int)0x80004002);

 

        private bool _fSafeForScripting = true;

        private bool _fSafeForInitializing = true;

 

        public HelloBossmaActiveX()
        {

            InitializeComponent();

        }

 

        /// <summary> 

        /// 设置当前时间 

        /// </summary> 

        /// <param name="timeStr"></param> 

        public void SetTime(string timeStr)
        {

            this.label2.Text = timeStr;

        }

        public void messagea(string timeStr)
        {

            MessageBox.Show(timeStr);

        }


        public int GetInterfaceSafetyOptions(ref Guid riid,

                        ref int pdwSupportedOptions,

                        ref int pdwEnabledOptions)
        {

            int Rslt = E_FAIL;

 

         

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值