準備寫一個公用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重寫?
大家有什么建議、看法,歡迎指教。。。
uj5u.com熱心網友回復:
VB的CommonControls (Replacement of the MS common controls)專案,網址:http://www.vbforums.com/showthread.php?698563-CommonControls-%28Replacement-of-the-MS-common-controls%29
uj5u.com熱心網友回復:
一切以在線MSDN為準。我只知道這個。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/103871.html
下一篇:c語言苦難戶
