公用ActiveX控件

阿凡提 2017-04-15 07:48:14
准备写一个公用ActiveX控件(如Button,CheckBox,TextBox等)供其它语言使用,
有些问题向各位请教:

1,各版本windows都有comctl32.dll,其中包含5.x的公用控件;
comctl32.ocx包含6.0的公用控件,但windows 7以后没有这个文件,是否windows 7以后都没有6.0的公用控件?

2,System.Windows.Forms.dll中的公用控件是dotNET的公用控件,
如果使用System.Windows.Forms.dll中的公用控件,是否必须安装dotNET运行库?

3,C#语言容易编写公用控件的wrapper代码,例如:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Runtime.InteropServices;
using System.Reflection;
using Microsoft.Win32;

namespace DotNetControl
{
[ProgId("DotNetControl.MyUserControl")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[Guid("FBD9A300-A0D2-4E68-8A6C-EB3B378F5E2D")]
[ComVisible(true)]
public partial class MyUserControl : System.Windows.Forms.UserControl
{
public MyUserControl()
{
InitializeComponent();
}

[ComRegisterFunction()]
public static void RegisterClass(string key)
{
// Strip off HKEY_CLASSES_ROOT\ from the passed key as I don't need it
StringBuilder sb = new StringBuilder(key);
sb.Replace(@"HKEY_CLASSES_ROOT\", "");

// Open the CLSID\{guid} key for write access
RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);

// And create the 'Control' key - this allows it to show up in
// the ActiveX control container
RegistryKey ctrl = k.CreateSubKey("Control");
ctrl.Close();

// Next create the CodeBase entry - needed if not string named and GACced.
RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true);
inprocServer32.SetValue("CodeBase", Assembly.GetExecutingAssembly().CodeBase);
inprocServer32.Close();

// Finally close the main key
k.Close();
}

[ComUnregisterFunction()]
public static void UnregisterClass(string key)
{
StringBuilder sb = new StringBuilder(key);
sb.Replace(@"HKEY_CLASSES_ROOT\", "");

// Open HKCR\CLSID\{guid} for write access
RegistryKey k = Registry.ClassesRoot.OpenSubKey(sb.ToString(), true);

// Delete the 'Control' key, but don't throw an exception if it does not exist
k.DeleteSubKey("Control", false);

// Next open up InprocServer32
RegistryKey inprocServer32 = k.OpenSubKey("InprocServer32", true);

// And delete the CodeBase key, again not throwing if missing
k.DeleteSubKey("CodeBase", false);

// Finally close the main key
k.Close();
}
}
}
经测试可以正常使用。
C/C++语言能否出类似的wrapper代码?或者参考示例?

4,网上有一个VB的CommonControls (Replacement of the MS common controls)项目,
能否参考该项目用VC重写?

大家有什么建议、看法,欢迎指教。。。



...全文
274 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2017-04-18
  • 打赏
  • 举报
回复
一切以在线MSDN为准。 我只知道这个。
阿凡提 2017-04-15
  • 打赏
  • 举报
回复
VB的CommonControls (Replacement of the MS common controls)项目,网址: http://www.vbforums.com/showthread.php?698563-CommonControls-%28Replacement-of-the-MS-common-controls%29

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧