分类目录
文章索引模板
c# ocx - 十二月 21, 2009 by yippee

Windows Forms ActiveX Control Importer (Aximp.exe)
http://msdn.microsoft.com/en-us/library/8ccdh774(VS.80).aspx
Windows Forms ActiveX Control Importer (Aximp.exe)


The ActiveX Control Importer converts type definitions in a COM type library for an ActiveX control into a Windows Forms control.


Windows Forms can only host Windows Forms controls — that is, classes that are derived from Control. Aximp.exe generates a wrapper class for an ActiveX control that can be hosted on a Windows Form. This allows you to use the same design-time support and programming methodology applicable to other Windows Forms controls.


To host the ActiveX control, you must generate a wrapper control that derives from AxHost. This wrapper control contains an instance of the underlying ActiveX control. It knows how to communicate with the ActiveX control, but it appears as a Windows Forms control. This generated control hosts the ActiveX control and exposes its properties, methods, and events as those of the generated control.


aximp [options]{file.dll | file.ocx}


 Remarks
Argument  Description


file
 


The name of the source file that contains the ActiveX control to convert. The file argument must have the extension .dll or .ocx.
Option  Description


/delaysign
 


Specifies to Aximp.exe to sign the resulting control using delayed signing. You must specify this option with either the /keycontainer:, /keyfile:, or /publickey: option. For more information on the delayed signing process, see Delay Signing an Assembly.


/help
 


Displays command syntax and options for the tool.


/keycontainer:containerName
 


Signs the resulting control with a strong name using the public/private key pair found in the key container specified by containerName.


/keyfile:filename
 


Signs the resulting control with a strong name using the publisher’s official public/private key pair found in filename.


/nologo
 


Suppresses the Microsoft startup banner display.


/out:filename
 


Specifies the name of the assembly to create.


/publickey:filename
 


Signs the resulting control with a strong name using the public key found in the file specified by filename.


/silent
 


Suppresses the display of success messages.


/source
 


Generates C# source code for the Windows Forms wrapper.


/verbose
 


Specifies verbose mode; displays additional progress information.


/?
 


Displays command syntax and options for the tool.


Aximp.exe converts an entire ActiveX Control type library at one time and produces a set of assemblies that contain the common language runtime metadata and control implementation for the types defined in the original type library. The generated files are named according to the following pattern:


common language runtime proxy for COM types: progid.dll


Windows Forms proxy for ActiveX controls (where Ax signifies ActiveX): Axprogid.dll
NoteNote


If the name of a member of the ActiveX control matches a name defined in the .NET Framework, Aximp.exe will prefix the member name with “Ctl” when it creates the AxHost derived class. For example, if your ActiveX control has a member named “Layout,” it is renamed “CtlLayout” in the AxHost derived class because the Layout event is defined within the .NET Framework.


You can examine these generated files with tools such as MSIL Disassembler (Ildasm.exe).


Running Aximp.exe over the ActiveX Control shdocvw.dll will always create another file named shdocvw.dll in the directory from which the tool is run. If this generated file is placed in the Documents and Settings directory, it causes problems for Microsoft Internet Explorer and Windows Explorer. When the computer is rebooted, Windows looks in the Documents and Settings directory before the system32 directory to find a copy of shdocvw.dll. It will use the copy it finds in Documents and Settings and attempt to load the managed wrappers. Internet Explorer and Windows Explorer will not function properly because they rely on the rendering engine in the version of shdocvw.dll located in the system32 directory. If this problem occurs, delete the copy of shdocvw.dll in the Documents and Settings directory and reboot the computer.
 Example


The following command generates MediaPlayer.dll and AxMediaPlayer.dll for the Media Player control msdxm.ocx.


aximp c:\systemroot\system32\msdxm.ocx


C#中调用OCX控件_吾心飞扬
http://hi.baidu.com/daijun2007/blog/item/7bc0756dc1cef3f343169408.html
C#中调用OCX控件
2009-03-27 14:20


调用OCX控件的步骤:
1、在系统中注册该ocx控件,命令:regsvr32.exe 控件位置(加 /u 参数是取消注册)
2、在.net的工具箱中添加该控件,拖到form中去就可以了。


不用工具箱的话,自己手工添加,需要注意一个问题,就是要用Aximp.exe来包装一下ocx控件的类,然后再程序中引用生成的dll就可以了。
aximp [options]{file.dll | file.ocx}
The following command generates MediaPlayer.dll and AxMediaPlayer.dll for the Media Player control msdxm.ocx.
aximp c:\systemroot\system32\msdxm.ocx


ActiveX 控件导入程序将 ActiveX 控件的 COM 类型库中的类型定义转换为 Windows 窗体控件。
Windows 窗体只能承载 Windows 窗体控件,即从 Control 派生的类。Aximp.exe 生成可承载于 Windows 窗体上的 ActiveX 控件的包装类。这使您得以使用可应用于其他 Windows 窗体控件的同一设计时支持和编程方法论。若要承载 ActiveX 控件,必须生成从 AxHost 派生的包装控件。此包装控件包含基础 ActiveX 控件的一个实例。它知道如何与 ActiveX 控件通信,但它显示为 Windows 窗体控件。这个生成的控件承载 ActiveX 控件并将其属性、方法和事件公开为生成控件的属性、方法和事件。


如果不包装一下直接用,会出现 灾难性 错误。上面已经说明了原因。


在项目中引用生成的ax开头的dll,在窗体代码中增加:
声明一个公有的控件对象:
public AxISPICRECLib.AxISPICREC AxISPICREC;
在InitializeComponent()方法内初始化控件:
AxISPICREC = new AxISPICRECLib.AxISPICREC();//必须new对象,否则窗体设计器出问题
            ((System.ComponentModel.ISupportInitialize)(this.AxISPICREC)).BeginInit();//初始化开始
            this.Controls.Add(this.AxISPICREC);//添加控件
            ((System.ComponentModel.ISupportInitialize)(this.AxISPICREC)).EndInit();


            this.AxISPICREC.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject(“AxISPICREC.OcxState”)));//设计控件状态


如果遇到“正试图在 os 加载程序锁内执行托管代码”这个错误,请设置“调试”–“异常”
“—-”Managed Debugging Assistants”中勾掉”LoaderLock” 就可以了。


 

标签:
ocx c# - 十二月 14, 2009 by yippee

Using OCX Installer With C#
http://www.softelvdm.com/Products/ActiveXControls/OCXInstaller/OCXInstallerDocumentation/UsingOCXInstallerWithC/tabid/208/Default.aspx
Using OCX Installer With C#


Overview | Documentation | C# | VB.NET | VB6 | C/C++ | Download


You application calls OCX Installer during application initialization, in the Main method of the application:


    if (!Softelvdm.OCXInstaller.ProcessFile(true, _
            “TestApp_CSharp”, “Softel vdm, Inc.”, _
            @”.\SftTree_IX86_U_60.ocx”, “%WinSys”, true, false))
        return;


In order to have access to the assembly containing the OCX Installer, a reference to Softelvdm.OCXInstaller has to be added to the project:


    VS 2003, 2005, 2008: Project, Add Reference… menu command, click Browse, locate the file OCXInstaller.Assembly.dll and add it. It is normally located at \Program Files\Softelvdm\OCX Installer\NET.


In order to debug/execute your application, make sure to copy all other required files (OCXes) to the folder containing your executable.


For all applications that include ActiveX controls, the .NET assembly stdole.dll must be distributed. This assembly is NOT part of the .NET runtime installation, so you have to insure it is included with your application. Other prerequisite files that are part of ActiveX controls, may also be updated accordingly (for example, Softelvdm.OCXHelper also must be distributed):


    VS 2003, 2005, 2008: In your Solution Explorer window, expand the References. Right-click on the stdole entry and select Properties. Set Copy Local to True.


 
Sample


OCX Installer includes a complete C# sample including project files for Visual Studio 2003, 2005, 2008 at


\Program Files\Softelvdm\OCX Installer\Samples\Sample_CS.NET


The completed, precompiled and distributable sample is located in the Bin\Release subfolder. The file PostBuildEvent.bat is not required and can be removed.


When experimenting with deployment of this sample, please make sure to install the .NET runtime first on the target system. Please visit microsoft.com to download the .NET runtime if needed.


Examples to Register / Unregister ActiveX via Code? – DevX.com Forums
http://forums.devx.com/showthread.php?t=57361
Public Class RegCOMServer


Private Declare Function FreeLibrary Lib “kernel32″ (ByVal hLibModule As Integer) As Integer
Private Declare Function LoadLibrary Lib “kernel32″ Alias “LoadLibraryA” (ByVal lpLibFileName As String) As Integer
Private Declare Function GetProcAddress Lib “kernel32″ (ByVal hModule As Integer, ByVal lpProcName As String) As Integer
Private Declare Function CallWindowProc Lib “user32″ Alias “CallWindowProcA” (ByVal lpPrevWndFunc As Integer, ByVal hWnd As Integer, ByVal Msg As System.UInt32, ByVal wParam As UIntPtr, ByVal lParam As IntPtr) As Integer


Private Const ERROR_SUCCESS As Short = &H0S


Public Function RegisterServer(ByRef DllServerPath As String, ByRef bRegister As Boolean) As Boolean


Dim lb As Integer
Dim pa As Integer


Try
lb = LoadLibrary(DllServerPath)


If bRegister Then
pa = GetProcAddress(lb, “DllRegisterServer”)
Else
pa = GetProcAddress(lb, “DllUnregisterServer”)
End If


If CallWindowProc(pa, 0, 0, 0, 0) = ERROR_SUCCESS Then
Return True
Else
Return False
End If


Catch e As Exception
Throw e


Finally
FreeLibrary(lb)


End Try


End Function


End Class


Examples to Register / Unregister ActiveX via Code? – DevX.com Forums
http://forums.devx.com/showthread.php?t=57361
Here’s some C# code I wrote a while ago. I was in a hurry and didn’t
have time to convert the PInvoke declarations in VB.NET, so I did the
whole thing in C#.


However, I am using this in a VB.NET app. Just create a C# class
library and put this code in it. Watch out for line-wrap…


using System;
using System.Runtime.InteropServices;


public class RegCOMServer
{
[DllImport("kernel32.dll")]
static extern bool FreeLibrary(IntPtr hModule);


[DllImport("kernel32.dll")]
static extern IntPtr LoadLibrary(string lpFilename);


[DllImport("kernel32.dll")]
static extern UIntPtr GetProcAddress(IntPtr hModule, string
lpProcName);


[DllImport("user32.dll")]
static extern IntPtr CallWindowProc(UIntPtr lpPrevWndFunc, IntPtr
hWnd, uint Msg, UIntPtr wParam, IntPtr lParam);


public static bool RegisterActiveX(string AXPath)
{
return(RegAX(AXPath, true));
}


public static bool UnRegisterActiveX(string AXPath)
{
return(RegAX(AXPath, false));
}


private static bool RegAX(string AXPath, bool Register)
{
IntPtr lb = IntPtr.Zero;
UIntPtr pa;


try
{
lb = LoadLibrary(AXPath);
if( Register )
pa = GetProcAddress(lb, “DllRegisterServer”);
else
pa = GetProcAddress(lb,
“DllUnregisterServer”);


if( CallWindowProc(pa, IntPtr.Zero, 0, UIntPtr.Zero,
IntPtr.Zero) == IntPtr.Zero )
{
return(true);
}
else
{
return(false);
}
}
catch(Exception e)
{
throw(e);
}
finally
{
FreeLibrary(lb);
}
}
}



Using OCX Installer With C#
http://www.softelvdm.com/Products/ActiveXControls/OCXInstaller/OCXInstallerDocumentation/UsingOCXInstallerWithC/tabid/208/Default.aspx
Using OCX Installer With C#


Overview | Documentation | C# | VB.NET | VB6 | C/C++ | Download


You application calls OCX Installer during application initialization, in the Main method of the application:


    if (!Softelvdm.OCXInstaller.ProcessFile(true, _
            “TestApp_CSharp”, “Softel vdm, Inc.”, _
            @”.\SftTree_IX86_U_60.ocx”, “%WinSys”, true, false))
        return;


In order to have access to the assembly containing the OCX Installer, a reference to Softelvdm.OCXInstaller has to be added to the project:


    VS 2003, 2005, 2008: Project, Add Reference… menu command, click Browse, locate the file OCXInstaller.Assembly.dll and add it. It is normally located at \Program Files\Softelvdm\OCX Installer\NET.


In order to debug/execute your application, make sure to copy all other required files (OCXes) to the folder containing your executable.


For all applications that include ActiveX controls, the .NET assembly stdole.dll must be distributed. This assembly is NOT part of the .NET runtime installation, so you have to insure it is included with your application. Other prerequisite files that are part of ActiveX controls, may also be updated accordingly (for example, Softelvdm.OCXHelper also must be distributed):


    VS 2003, 2005, 2008: In your Solution Explorer window, expand the References. Right-click on the stdole entry and select Properties. Set Copy Local to True.


 
Sample


OCX Installer includes a complete C# sample including project files for Visual Studio 2003, 2005, 2008 at


\Program Files\Softelvdm\OCX Installer\Samples\Sample_CS.NET


The completed, precompiled and distributable sample is located in the Bin\Release subfolder. The file PostBuildEvent.bat is not required and can be removed.


When experimenting with deployment of this sample, please make sure to install the .NET runtime first on the target system. Please visit microsoft.com to download the .NET runtime if needed.


 

标签:,
20090518 c# create ocx - 八月 18, 2009 by yippee

a sample of how to create a very simple ActiveX component:

// AxComp.cs
using System;
using System.Runtime.InteropServices;
namespace AXComponent
&leftsign;

public interface AXTest
&leftsign;
string callMe();
&rightsign;

[ClassInterface(ClassInterfaceType.AutoDual)]
public class AxComp :AXTest
&leftsign;
public string callMe()
&leftsign;
return "My dog has no nose, how does it smell?";
&rightsign;
&rightsign;
&rightsign;

Compile this using:
csc /t:library AxComp.cs

Register and generate Typelib with:
regasm AxComp.dll /tlb:AxCompNet.dll /codebase

Try the control: ( testControl.htm )
<html>
<head>
<script language="javascript">
var obNewAXComponent = new ActiveXObject("AXComponent.AXComp");
alert(obNewAXComponent.callMe());
</script>
</head>
<body>
<h1>Awful!</h1>
</body>
</html>

标签:, ,
20090605 vs2008 ocx - 八月 18, 2009 by yippee

我们在编写ActiveX控件的时候,一般都会用Active X control test container来进行简单的测试,这在VisualStudio 6里面是很方便查找的,工具菜单下面就有。但是在VisualStudio 2008里面TSTCON32.exe这个文件却消失了,在VisualStudio 2008的安装目录下也找不到这个文件。经过在网上搜索,原来微软把它放在了例子程序里面,需要自己编译。详细目录:比如我装在C盘里面,VC的例子在 “C:\\Program Files\\Microsoft Visual Studio 9.0\\Samples\\2052\\AllVCLanguageSamples.zip”,吧这个文件解压缩以后,在下面的目录可以找到TSTCON32.exe的源代码:“C++\\MFC\\ole\\TstCon”,自己编译就可以了。

用ole   view可以看到uuid(F00055F3-EDFC-4270-BE8C-18EE75B4CFEF),   

CodeProject: A Complete ActiveX Web Control Tutorial. Free source code and programming help
http://www.codeproject.com/KB/COM/CompleteActiveX.aspx

CodeProject: A Complete ActiveX Web Control Tutorial. Free source code and programming help
http://www.codeproject.com/KB/COM/CompleteActiveX.aspx

CodeProject: A Complete ActiveX Web Control Tutorial. Free source code and programming help
http://www.codeproject.com/KB/COM/CompleteActiveX.aspx

VC OCX 打包CAB 网页发布全过程记录_Life&Work
http://hi.baidu.com/btb368/blog/item/5cfbb5b60f6683f330add122.html

利用mfc编写activex控件 – VC编程
http://www.99inf.net/SoftwareDev/VC/12811.htm

VC知识库文章 – COM 组件设计与应用(九)——IDispatch 接口 for VC6.0
http://www.vckbase.com/document/viewdoc/?id=1506

ocx更改guid有三个地方 – 小程序积累 – 姑苏一枫
http://blog.chinaunix.net/u/11458/showart_139693.html
ocx更改guid有三个地方
1 xx.odl
中//Class information for CxxCtrl
2 xx.cpp
const GUID CDECL CLSID_SafeItem
3 xxCtl.cpp
IMPLEMENT_OLECREATE_EX
=========================================
如果ocx改名,切记odl里相应也要改动
—————————–
改动是否成功,用vc测试程序一试便知,如果控件能够加入工程,就说明基本可以,否则会报错

ActiveX控件的WEB发布 – 老张的专栏 – CSDN博客
http://blog.csdn.net/jingshuaizh/archive/2007/12/12/1931404.aspx

ActiveX组件与JavaScript交互_清石de博客
http://hi.baidu.com/qdh126/blog/item/1401c21b0c68421f8618bf30.html

DLL+ ActiveX控件+WEB页面调用例子[转载]_清石de博客
http://hi.baidu.com/qdh126/blog/item/223733a742037293d143582e.html

MFC ActiveX 控件 – 资源管理 – 爱国者安全网
http://www.3800hk.com/Article/cxsj/vc/mbzjlvc/2005-08-06/Article_33081.html

如何将MFC ActiveX控件标记为安全 – pengpeng98的专栏 – CSDN博客
http://blog.csdn.net/pengpeng98/archive/2007/07/04/1678458.aspx

用MFC制作Activex_浪子无悔_新浪博客
http://blog.sina.com.cn/s/blog_4a79b21601008tvq.html

OSG–中国
http://www.osgchina.org/projects/osgChina/wiki/Support/3rd/OSGandIE.php
afx_msg

使用MFC开发ActiveX控件 – 蓝色警报 – 博客园
http://www.cnblogs.com/jyz/archive/2008/04/11/1148476.html

如何确定一个ocx的classid? Web 开发 / JavaScript – CSDN社区 community.csdn.net
http://topic.csdn.net/t/20030710/10/2011085.html
你到微软官方网站去下载一个ActiveX   control   Pad   ,然后点击嵌入控件,程序会自动为你添加   classid

Javascript调用OCX控件 – 冰 馨的日志 – 网易博客
http://blog.163.com/pei_hua100/blog/static/8056975920090410495905/

标签:,
20081114 wpf flash ocx - 七月 22, 2009 by yippee

Insert Media Element Flash Movie problem – Directorforum
http://www.directorforum.de/showthread.php?t=1245

How to play flash in MediaElement : Windows Presentation Foundation (WPF) : .NET Development : MSDN Forums
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/93c96c71-c4ef-48e0-a8e9-9a4bb3dab07d/

Imported .swf file won\’t show – Directorforum
http://www.directorforum.de/showthread.php?t=37342

Media Libraries : Introduction
http://lassie.gmacwill.com/help/docs/medialib/intro.php

Media Libraries : Introduction
http://lassie.gmacwill.com/help/docs/medialib/intro.php

Files: Applications
http://wpf.netfx3.com/files/folders/applications/default.aspx

WPF Win32 Interop Render Control – Source Code
http://www.codeplex.com/WPFWin32Renderer/SourceControl/ListDownloadableCommits.aspx

Alpha Channel Videos in WPF : Windows Presentation Foundation (WPF) : .NET Development : MSDN Forums
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/0689e2b8-829e-4860-857b-b4755e0bc0e0/

Flash file (swf / flv) transparency in c# / xaml (wpf application) – DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting &line; Google 网上论坛
http://groups.google.vu/group/DotNetDevelopment/msg/632633da498ce4a0

WindowsFormsHost Problem When Publishing XABP Application : Windows Presentation Foundation (WPF) : .NET Development : MSDN Forums
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/8df535f4-f2e9-401b-a82b-5335d7a01f3b/

Infosys &line; Microsoft: Hosting Flash movie in a WPF project
http://209.85.173.132/u/loyolachicago?q=cache:8RMHeSdzvdcJ:infosysblogs.com/microsoft/2008/07/hosting_flash_movie_in_a_wpf_p.html+wpf+show+swf&hl=en&ct=clnk&cd=7

axShockwaveFlash C# 中随意调用flash 了_I must become a good programmer!
http://hi.baidu.com/leader_bin/blog/item/0b6d3ac8bb56d6117e3e6f1a.html

WPF 中如何嵌入 Flash (ActiveX) – 星辰.Net技术社区
http://www.netcsharp.cn/showtopic-880.aspx

ASP.NET中采用Reflection机制把页面控件元素和对象联系起来。
http://www.chinaitpower.com/A/2002-10-03/36813.html

ASP.Net窗体的控件标识(访问模板控件) – 在浩瀚的编程知识中,让我们共同去探险吧! – 博客园
http://www.cnblogs.com/gfzou/archive/2008/09/26/1299623.html

遍历控件问题? .NET技术 / ASP.NET – CSDN社区 community.csdn.net
http://topic.csdn.net/t/20050831/14/4242044.html

标签:, ,
0819 VB OCX ACTIVEX 事件 DOS输入输出 - 一月 28, 2007 by yippee

0819 VB OCX ACTIVEX 事件 DOS输入输出

如何在网页中响应ActiveX控件或COM组件的事件
分为 js 和 vbs
vbs 中
sub 控件ID_On事件函数名(参数)
…………
end sub

js 中
<script for="控件ID" event="事件函数名(参数)">
…………
</script>

代码:
<SCRIPT LANGUAGE="VBSCRIPT" >
sub testocx1_Eve(l)
window.alert("成功")
button1.value=l
end sub

</SCRIPT>

<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!–
function button1_onclick()
&leftsign;
 testocx1.dd="123sdfsdf23";
 //button1.value="123";
 testocx1.rt();
&rightsign;

//–>

</SCRIPT>
<!– <script for=testocx1 event="Eve(l)" >
 window.alert("成功");  
 button1.value=l;
</script> //–>

VB测试代码
Private Sub Command1_Click()
UserControl11.rt
End Sub

Private Sub UserControl11_Eve(l As Variant)
Debug.Print l
End Sub

Private Sub UserControl11_sss()
Debug.Print "ssssssss"
End Sub

CTL代码
\’注意!不要删除或修改下列被注释的行!
\’MemberInfo=14
Public Function rt() As Variant
    MsgBox dd
   
    \’Shell "ping 192.168.0.1"
    \’RaiseEvent Eve(1223)
    RaiseEvent sss
   
End Function

在VB中使用DOS命令
仅仅是执行可以用shell之类,如果输入输出都想在vb中可以看下面的代码:
Option Explicit

Private Declare Function CreatePipe Lib "kernel32" (phReadPipe As Long, phWritePipe As Long, lpPipeAttributes As SECURITY_ATTRIBUTES, ByVal nSize As Long) As Long
Private Declare Sub GetStartupInfo Lib "kernel32" Alias "GetStartupInfoA" (lpStartupInfo As STARTUPINFO)
Private Declare Function CreateProcess Lib "kernel32" Alias "CreateProcessA" (ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As Any, lpThreadAttributes As Any, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, lpEnvironment As Any, ByVal lpCurrentDriectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As Any) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Type SECURITY_ATTRIBUTES
  nLength As Long
  lpSecurityDescriptor As Long
  bInheritHandle As Long
End Type

Private Type PROCESS_INFORMATION
  hProcess As Long
  hThread As Long
  dwProcessId As Long
  dwThreadId As Long
End Type

Private Type STARTUPINFO
  cb As Long
  lpReserved As Long
  lpDesktop As Long
  lpTitle As Long
  dwX As Long
  dwY As Long
  dwXSize As Long
  dwYSize As Long
  dwXCountChars As Long
  dwYCountChars As Long
  dwFillAttribute As Long
  dwFlags As Long
  wShowWindow As Integer
  cbReserved2 As Integer
  lpReserved2 As Byte
  hStdInput As Long
  hStdOutput As Long
  hStdError As Long
End Type

Private Type OVERLAPPED
    ternal As Long
    ternalHigh As Long
    offset As Long
    OffsetHigh As Long
    hEvent As Long
End Type

Private Const STARTF_USESHOWWINDOW = &H1
Private Const STARTF_USESTDHANDLES = &H100
Private Const SW_HIDE = 0
Private Const EM_SETSEL = &HB1
Private Const EM_REPLACESEL = &HC2

Private Sub Command1_Click()
  Command1.Enabled = False
  Redirect Text1.Text, Text2
  Command1.Enabled = True
End Sub
Private Sub Form_Load()
    Text1.Text = "ping"
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  If Command1.Enabled = False Then Cancel = True
End Sub

Sub Redirect(cmdLine As String, objTarget As Object)
  Dim i%, t$
  Dim pa As SECURITY_ATTRIBUTES
  Dim pra As SECURITY_ATTRIBUTES
  Dim tra As SECURITY_ATTRIBUTES
  Dim pi As PROCESS_INFORMATION
  Dim sui As STARTUPINFO
  Dim hRead As Long
  Dim hWrite As Long
  Dim bRead As Long
  Dim lpBuffer(1024) As Byte
  pa.nLength = Len(pa)
  pa.lpSecurityDescriptor = 0
  pa.bInheritHandle = True
 
  pra.nLength = Len(pra)
  tra.nLength = Len(tra)

  If CreatePipe(hRead, hWrite, pa, 0) <> 0 Then
    sui.cb = Len(sui)
    GetStartupInfo sui
    sui.hStdOutput = hWrite
    sui.hStdError = hWrite
    sui.dwFlags = STARTF_USESHOWWINDOW Or STARTF_USESTDHANDLES
    sui.wShowWindow = SW_HIDE
    If CreateProcess(vbNullString, cmdLine, pra, tra, True, 0, Null, vbNullString, sui, pi) <> 0 Then
      SetWindowText objTarget.hwnd, ""
      Do
        Erase lpBuffer()
        If ReadFile(hRead, lpBuffer(0), 1023, bRead, ByVal 0&) Then
          SendMessage objTarget.hwnd, EM_SETSEL, -1, 0
          SendMessage objTarget.hwnd, EM_REPLACESEL, False, lpBuffer(0)
          DoEvents
        Else
          CloseHandle pi.hThread
          CloseHandle pi.hProcess
          Exit Do
        End If
        CloseHandle hWrite
      Loop
      CloseHandle hRead
    End If
  End If
End Sub

标签:, , , , ,
0815 vc atl ocx 自定义消息 CContainedWindow - 一月 24, 2007 by yippee

0815 vc atl ocx 自定义消息 CContainedWindow

搞了半天,中间绕了这个弯路,干脆基于CBUTTON做OCX,这下也可以

#include "resource.h"       // main symbols
#include <atlctl.h>
#define WM_SELFTMSG WM_USER+10001

/////////////////////////////////////////////////////////////////////////////
// Cctest
class ATL_NO_VTABLE Cctest :
 public CComObjectRootEx<CComSingleThreadModel>,
 public IDispatchImpl<Ictest, &IID_Ictest, &LIBID_ATLOCXCMDLib>,
 public CComControl<Cctest>,
 public IPersistStreamInitImpl<Cctest>,
 public IOleControlImpl<Cctest>,
 public IOleObjectImpl<Cctest>,
 public IOleInPlaceActiveObjectImpl<Cctest>,
 public IViewObjectExImpl<Cctest>,
 public IOleInPlaceObjectWindowlessImpl<Cctest>,
 public ISupportErrorInfo,
 public IConnectionPointContainerImpl<Cctest>,
 public IPersistStorageImpl<Cctest>,
 public ISpecifyPropertyPagesImpl<Cctest>,
 public IQuickActivateImpl<Cctest>,
 public IDataObjectImpl<Cctest>,
 public IProvideClassInfo2Impl<&CLSID_ctest, &DIID__IctestEvents, &LIBID_ATLOCXCMDLib>,
 public IPropertyNotifySinkCP<Cctest>,
 public CComCoClass<Cctest, &CLSID_ctest>
&leftsign;
public:
 CContainedWindow m_ctlButton;
 

 Cctest() : 
  m_ctlButton(_T("Button"), this, 1)
 &leftsign;
  m_bWindowOnly = TRUE;
 &rightsign;

DECLARE_REGISTRY_RESOURCEID(IDR_CTEST)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(Cctest)
 COM_INTERFACE_ENTRY(Ictest)
 COM_INTERFACE_ENTRY(IDispatch)
 COM_INTERFACE_ENTRY(IViewObjectEx)
 COM_INTERFACE_ENTRY(IViewObject2)
 COM_INTERFACE_ENTRY(IViewObject)
 COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
 COM_INTERFACE_ENTRY(IOleInPlaceObject)
 COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
 COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
 COM_INTERFACE_ENTRY(IOleControl)
 COM_INTERFACE_ENTRY(IOleObject)
 COM_INTERFACE_ENTRY(IPersistStreamInit)
 COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
 COM_INTERFACE_ENTRY(ISupportErrorInfo)
 COM_INTERFACE_ENTRY(IConnectionPointContainer)
 COM_INTERFACE_ENTRY(ISpecifyPropertyPages)
 COM_INTERFACE_ENTRY(IQuickActivate)
 COM_INTERFACE_ENTRY(IPersistStorage)
 COM_INTERFACE_ENTRY(IDataObject)
 COM_INTERFACE_ENTRY(IProvideClassInfo)
 COM_INTERFACE_ENTRY(IProvideClassInfo2)
END_COM_MAP()

BEGIN_PROP_MAP(Cctest)
 PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
 PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
 // Example entries
 // PROP_ENTRY("Property Description", dispid, clsid)
 // PROP_PAGE(CLSID_StockColorPage)
END_PROP_MAP()

BEGIN_CONNECTION_POINT_MAP(Cctest)
 CONNECTION_POINT_ENTRY(IID_IPropertyNotifySink)
END_CONNECTION_POINT_MAP()

BEGIN_MSG_MAP(Cctest)
 MESSAGE_HANDLER(WM_CREATE, OnCreate)
 MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
 CHAIN_MSG_MAP(CComControl<Cctest>)
ALT_MSG_MAP(1)
 // Replace this with message map entries for superclassed Button
 MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
 MESSAGE_HANDLER(WM_SELFTMSG, OnSelfDown)
END_MSG_MAP()
// Handler prototypes:
//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
//  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
//  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);

 LRESULT OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 &leftsign;
  LRESULT lRes = CComControl<Cctest>::OnSetFocus(uMsg, wParam, lParam, bHandled);
  if (m_bInPlaceActive)
  &leftsign;
   DoVerbUIActivate(&m_rcPos,  NULL);
   if(!IsChild(::GetFocus()))
    m_ctlButton.SetFocus();
  &rightsign;
  return lRes;
 &rightsign;

 LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
 &leftsign;
  RECT rc;
  GetWindowRect(&rc);
  rc.right -= rc.left;
  rc.bottom -= rc.top;
  rc.top = rc.left = 0;
  m_ctlButton.Create(m_hWnd, rc);

  return 0;
 &rightsign;
 STDMETHOD(SetObjectRects)(LPCRECT prcPos,LPCRECT prcClip)
 &leftsign;
  IOleInPlaceObjectWindowlessImpl<Cctest>::SetObjectRects(prcPos, prcClip);
  int cx, cy;
  cx = prcPos->right – prcPos->left;
  cy = prcPos->bottom – prcPos->top;
  ::SetWindowPos(m_ctlButton.m_hWnd, NULL, 0,
   0, cx, cy, SWP_NOZORDER &line; SWP_NOACTIVATE);
  return S_OK;
 &rightsign;

// ISupportsErrorInfo
 STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid)
 &leftsign;
  static const IID* arr[] =
  &leftsign;
   &IID_Ictest,
  &rightsign;;
  for (int i=0; i<sizeof(arr)/sizeof(arr[0]); i++)
  &leftsign;
   if (InlineIsEqualGUID(*arr[i], riid))
    return S_OK;
  &rightsign;
  return S_FALSE;
 &rightsign;

// IViewObjectEx
 DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND &line; VIEWSTATUS_OPAQUE)

// Ictest
public:
 LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 &leftsign;
  // TODO : Add Code for message handler. Call DefWindowProc if necessary.
  HWND h=m_hWnd;
  SendMessage(m_ctlButton.m_hWnd,WM_SELFTMSG,0,0);
  return 0;
 &rightsign;
 LRESULT OnSelfDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 &leftsign;
  ::MessageBox(NULL,"123","123",MB_OK);
  return 0;
 &rightsign;
&rightsign;;

标签:, , , ,
0814 vc atl ocx 自定义消息 资料 - 一月 23, 2007 by yippee

0814 vc atl ocx 自定义消息 资料

运行时不可见此选项使你的控件在运行时不可见。你可以使用不可见控件在后台完成某些操作,例如周期性的激发事件。此选项在它加入到注册表中后使得控件翻转OLEMISC_INVISIBLEATRUNTIME 位。

仿按钮此选项使你的控件象一个按钮那样工作。此时,控件将在包容器周围属性DisplayAsDefault的基础上显示为缺省的按钮。如果控件的位置标记为缺省按钮,控件将显示为一个较厚的框架。选择此选项在它加入到注册表中后使得控件翻转OLEMISC_ACTSLIKEBUTTON 。

仿标签选择此选项使得你的控件取代包容器的内部标签。这使得控件在它加入到注册表中后标记OLEMISC_ACTSLIKELABEL。

在超类基础上添加控件选择此选项使得你的控件根据一种标准window类进行子类划分。下拉列表包含了Windows定义的window类。当你选择这些类名中的一个时,向导添加一个CcontainedWindow成员变量到你的控件类中。CContainedWindow::Create将你指定的window类超类化。

规格化DC选择此选项使得你的控件在被调用来画自己时创建一个规格化的设备上下文。这标准化了控件的外观,但是效率降低了。此选项生成的代码覆盖了OnDrawAdvanced方法(而不是常规的OnDraw方法)。

可插入的选择此选项使得你的控件显示在象Microsoft Excel 和Word 这样的应用的Insert Object对话框中。你的控件就能够被插入到任何支持嵌入对象的应用中了。选择此选项在注册表项中增加了Insertable键。

仅为窗口化的选择此选项迫使你的控件窗口化,即使在支持无窗口对象的包容器中。如果你不选择此选项,你的控件将会自动的适应包容器:在支持无窗口对象的包容器中是无窗口的,在不支持无窗口对象的包容器中是有窗口的。这将使CComControlBase::m_bWindowOnly标志设置为TRUE。ATL使用此标志来决定在控件激活过程中是否要查询包容器的IoleInPlaceSiteWindowless接口。

ATL要求你预先在Stock Properties页中决定你的对象的stock属性,你可以选择Caption或者 Border Color这样的属性,或者通过点击>>按钮一次性选择所有的stock属性。这将向控件的属性映射中添加属性。

在运行ATL COM App Wizard 和 ObjectWizard之后,你就得到了一个完整的DLL,它具有一个COM DLL所必需的所有分支。此控件显示的众所周知的出口包括DllGetClassObject, DllCanUnloadNow, DllRegisterServer,和 DllUnregisterServer。另外,你得到了一个满足COM主要需求的对象——包括一个主流入接口和一个类对象。

一旦你已经使用一个向导开始了一个工程,下一步就是使控件做点有趣的事情了。通常出发点是控件的翻译代码。你立刻得到一些可视化的反馈。让我们来看一下一个基于MFC的控件的翻译是怎样发生的。

控件翻译

MFC和ATL在翻译处理上是相似的。在每一个框架里,实现控件的类具有一个名为OnDraw的虚函数。你只需将你的翻译代码添加到OnDraw函数里。然而,在各框架里,OnDraw函数得工作有所不同。

MFC的OnDraw在两种上下文下调用。第一个上下文发生在控件响应一个WM_PAINT消息时。此时,传递给OnDraw函数的设备上下文代表了真实的设备上下文。如果控件正被要求render它自己作为对客户调用IViewObjectEx::Draw的响应,设备上下文或者是一个元设备上下文,或者是一个常规设备上下文。下面的代码说明了基于MFC的控件是怎样被render的:

void CMFCMsgTrafficCtrl::OnDraw(CDC* pdc, const CRect& rcBounds,

const CRect& rcInvalid)

&leftsign;

// TODO: 用你自己的绘图代码代替下面的代码

pdc->FillRect(rcBounds,

CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));

ShowGraph(*pdc, const_cast(rcBounds), nMessagesToShow);

&rightsign;

COleControl::OnDraw的签名包括一个代表控件大小的矩形和一个代表控件非法区域的矩形。MFC调用控件的OnDraw函数来响应一个WM_PAINT消息。此时,OnDraw函数接受一个真实的设备上下文来绘图。MFC还调用控件的OnDraw函数来响应IViewObject::Draw中的一个调用。MFC的实现调用COleControl::OnDrawMetafile,它的缺省OnDrawMetafile调用COleControl::OnDraw。当然,这暗示了控件的实时翻译是与控件的元文件表示相同的,该元文件在设计时与包容器一块存储。你可以使得控件的实时的翻译与设计时的翻译不同,这通过重载COleControl::OnDrawMetafile来实现。通过调用你的控件的InvalidateControl方法,你可以强制进行一个重绘。ATL的翻译机制非常类似于MFC。CComControlBase::OnPaint建立一个ATL_DRAWINFO结构,包括创建一个绘图设备上下文。然后ATL调用控件的OnDrawAdvanced函数。OnDrawAdvanced生成元文件,接着调用你的控件的OnDraw方法,它使用ATL_DRAWINFO结构中的信息来知道怎样在屏幕上绘图。

在ATL中能像MFC中一样用PostMessage来响应消息函数吗?
先不说怎样添加消息映射,我在ATL中程序运行到这个函数就出错
问题是怎样在ATL中发出一个消息,然后怎样添加消息映射

标准ATL没有msg map的概念,如果是做ActiveX,可以msg给window,ATL提供BEGIN_MESSAGE_MAP一类的宏。
class CSessionsWin :  public CWindowImpl<CSessionsWin, CWindow, CNullTraits>
&leftsign;
public:
 CString ConvertErrorCode(int ErrorCode);
 CESessions *m_parent;
 CSessionsWin()
 &leftsign;
 &rightsign;

 BEGIN_MSG_MAP(CSessionsWin)
//  MESSAGE_HANDLER(WM_EtermEVENT, OnEtermEvent)
  MESSAGE_HANDLER(WM_OPTION,OnOption)
  MESSAGE_HANDLER(WM_DATA,OnData)
  MESSAGE_HANDLER(WM_CONNECTSTATUS,OnStatus)
  MESSAGE_HANDLER(WM_ERROR,OnERROR)
  MESSAGE_HANDLER(WM_ERRORMSG,OnERRORMSG)
  MESSAGE_HANDLER(WM_NEWS,OnNEWS)
 END_MSG_MAP()
    
 LRESULT OnOption(UINT nMsg, WPARAM wParam,
     LPARAM lParam, BOOL& bHandled);
 LRESULT OnData(UINT nMsg, WPARAM wParam,
     LPARAM lParam, BOOL& bHandled);
 LRESULT OnStatus(UINT nMsg, WPARAM wParam,
     LPARAM lParam, BOOL& bHandled);
 LRESULT OnERROR(UINT nMsg, WPARAM wParam,
     LPARAM lParam, BOOL& bHandled);
 LRESULT OnERRORMSG(UINT nMsg, WPARAM wParam,
     LPARAM lParam, BOOL& bHandled);
 LRESULT OnNEWS(UINT nMsg, WPARAM wParam,
     LPARAM lParam, BOOL& bHandled);
&rightsign;;

CSessionsWin m_Msg;

hwnd=m_Msg.Create(NULL,rect,NULL,0,0,0,NULL);

标签:, , , ,
0813 vc atl ocx 自定义消息 m_bWindowOnly - 一月 22, 2007 by yippee

0813 vc atl ocx 自定义消息 m_bWindowOnly

自定义消息倒是简单,就是那个该死的HWND窗口句柄
搞半天没有弄到,终于好了,每次获得都是容器的窗口句柄
m_bWindowOnly = TRUE; 主要是加上这个

#include "resource.h"       // main symbols
#include <atlctl.h>
#include "atlocxxCP.h"
#define WM_SELFTMSG WM_USER+10001

/////////////////////////////////////////////////////////////////////////////
// Cctest
class ATL_NO_VTABLE Cctest :
 public CComObjectRootEx<CComSingleThreadModel>,
 public IDispatchImpl<Ictest, &IID_Ictest, &LIBID_ATLOCXXLib>,
 public CComControl<Cctest>,
 public IPersistStreamInitImpl<Cctest>,
 public IOleControlImpl<Cctest>,
 public IOleObjectImpl<Cctest>,
 public IOleInPlaceActiveObjectImpl<Cctest>,
 public IViewObjectExImpl<Cctest>,
 public IOleInPlaceObjectWindowlessImpl<Cctest>,
 public ISupportErrorInfo,
 public IConnectionPointContainerImpl<Cctest>,
 public IPersistStorageImpl<Cctest>,
 public ISpecifyPropertyPagesImpl<Cctest>,
 public IQuickActivateImpl<Cctest>,
 public IDataObjectImpl<Cctest>,
 public IProvideClassInfo2Impl<&CLSID_ctest, &DIID__IctestEvents, &LIBID_ATLOCXXLib>,
 public IPropertyNotifySinkCP<Cctest>,
 public CComCoClass<Cctest, &CLSID_ctest>,
 public CProxy_IctestEvents< Cctest >
&leftsign;
public:
 Cctest()
 &leftsign;
  m_bWindowOnly = TRUE;
 &rightsign;
DECLARE_REGISTRY_RESOURCEID(IDR_CTEST)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(Cctest)
 COM_INTERFACE_ENTRY(Ictest)
 COM_INTERFACE_ENTRY(IDispatch)
 COM_INTERFACE_ENTRY(IViewObjectEx)
 COM_INTERFACE_ENTRY(IViewObject2)
 COM_INTERFACE_ENTRY(IViewObject)
 COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
 COM_INTERFACE_ENTRY(IOleInPlaceObject)
 COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
 COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
 COM_INTERFACE_ENTRY(IOleControl)
 COM_INTERFACE_ENTRY(IOleObject)
 COM_INTERFACE_ENTRY(IPersistStreamInit)
 COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
 COM_INTERFACE_ENTRY(ISupportErrorInfo)
 COM_INTERFACE_ENTRY(IConnectionPointContainer)
 COM_INTERFACE_ENTRY(ISpecifyPropertyPages)
 COM_INTERFACE_ENTRY(IQuickActivate)
 COM_INTERFACE_ENTRY(IPersistStorage)
 COM_INTERFACE_ENTRY(IDataObject)
 COM_INTERFACE_ENTRY(IProvideClassInfo)
 COM_INTERFACE_ENTRY(IProvideClassInfo2)
 COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
END_COM_MAP()

BEGIN_PROP_MAP(Cctest)
 PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
 PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
 // Example entries
 // PROP_ENTRY("Property Description", dispid, clsid)
 // PROP_PAGE(CLSID_StockColorPage)
END_PROP_MAP()

BEGIN_CONNECTION_POINT_MAP(Cctest)
 CONNECTION_POINT_ENTRY(IID_IPropertyNotifySink)
 CONNECTION_POINT_ENTRY(DIID__IctestEvents)
END_CONNECTION_POINT_MAP()

BEGIN_MSG_MAP(Cctest)
 CHAIN_MSG_MAP(CComControl<Cctest>)
 DEFAULT_REFLECTION_HANDLER()
 MESSAGE_HANDLER(WM_SELFTMSG, OnSelfDown)
 MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
END_MSG_MAP()
// Handler prototypes:
//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
//  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
//  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);

// ISupportsErrorInfo
 STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid)
 &leftsign;
  static const IID* arr[] =
  &leftsign;
   &IID_Ictest,
  &rightsign;;
  for (int i=0; i<sizeof(arr)/sizeof(arr[0]); i++)
  &leftsign;
   if (InlineIsEqualGUID(*arr[i], riid))
    return S_OK;
  &rightsign;
  return S_FALSE;
 &rightsign;

// IViewObjectEx
 DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND &line; VIEWSTATUS_OPAQUE)

// Ictest
public:
 STDMETHOD(testM)(long i,long *j);
 STDMETHOD(get_s)(/*[out, retval]*/ long *pVal);
 STDMETHOD(put_s)(/*[in]*/ long newVal);
 HRESULT OnDraw(ATL_DRAWINFO& di)
 &leftsign;
  RECT& rc = *(RECT*)di.prcBounds;
  Rectangle(di.hdcDraw, rc.left, rc.top, rc.right, rc.bottom);

  SetTextAlign(di.hdcDraw, TA_CENTER&line;TA_BASELINE);
  LPCTSTR pszText = _T("ATL 3.0 : ctest");
  TextOut(di.hdcDraw,
   (rc.left + rc.right) / 2,
   (rc.top + rc.bottom) / 2,
   pszText,
   lstrlen(pszText));

  return S_OK;
 &rightsign;
public:
 long m_s; //不能放在前面,否则控件不能使用
 LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 &leftsign;
  // TODO : Add Code for message handler. Call DefWindowProc if necessary.
  //MessageBox(NULL,"OnLButtonDown");
  //  HWND h=m_hWndCD;
  //  Fire_testEve(999);
  SendMessage(m_hWnd,WM_SELFTMSG,0,0);
  return 0;
 &rightsign;
 LRESULT OnSelfDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

&rightsign;;

标签:, , , ,

0810 vc atl ocx 简单 3 - 一月 19, 2007 by yippee

0810 vc atl ocx 简单 3

// atlocxx.idl : IDL source for atlocxx.dll
//

// This file will be processed by the MIDL tool to
// produce the type library (atlocxx.tlb) and marshalling code.

import "oaidl.idl";
import "ocidl.idl";
#include "olectl.h"
 

 [
  object,
  uuid(8B6938C6-D827-4678-BE52-2DC6ED779F24),
  dual,
  helpstring("Ictest Interface"),
  pointer_default(unique)
 ]
 interface Ictest : IDispatch
 &leftsign;
  [propget, id(1), helpstring("property s")] HRESULT s([out, retval] long *pVal);
  [propput, id(1), helpstring("property s")] HRESULT s([in] long newVal);
  [id(2), helpstring("method testM")] HRESULT testM(long i,long *j);
 &rightsign;;

[
 uuid(28202A8C-CAD6-434C-87AE-46FE6C4838BA),
 version(1.0),
 helpstring("atlocxx 1.0 Type Library")
]
library ATLOCXXLib
&leftsign;
 importlib("stdole32.tlb");
 importlib("stdole2.tlb");

 [
  uuid(8A53D4C6-2448-4694-9CBD-A07AE85EFD29),
  helpstring("_IctestEvents Interface")
 ]
 dispinterface _IctestEvents
 &leftsign;
  properties:
  methods:
  [id(1), helpstring("method testEv")] HRESULT testEv();
  [id(2), helpstring("method testEve")] HRESULT testEve(long i);
 &rightsign;;

 [
  uuid(4D189B2F-E8B6-4100-BD9E-0348039A2D65),
  helpstring("ctest Class")
 ]
 coclass ctest
 &leftsign;
  [default] interface Ictest;
  [default, source] dispinterface _IctestEvents;
 &rightsign;;
&rightsign;;
; atlocxx.def : Declares the module parameters.

LIBRARY      "atlocxx.DLL"

EXPORTS
 DllCanUnloadNow     @1 PRIVATE
 DllGetClassObject   @2 PRIVATE
 DllRegisterServer   @3 PRIVATE
 DllUnregisterServer @4 PRIVATE
// atlocxx.cpp : Implementation of DLL Exports.

// Note: Proxy/Stub Information
//      To build a separate proxy/stub DLL,
//      run nmake -f atlocxxps.mk in the project directory.

#include "stdafx.h"
#include "resource.h"
#include <initguid.h>
#include "atlocxx.h"

#include "atlocxx_i.c"
#include "ctest.h"

CComModule _Module;

BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_ctest, Cctest)
END_OBJECT_MAP()

/////////////////////////////////////////////////////////////////////////////
// DLL Entry Point

extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
&leftsign;
    if (dwReason == DLL_PROCESS_ATTACH)
    &leftsign;
        _Module.Init(ObjectMap, hInstance, &LIBID_ATLOCXXLib);
        DisableThreadLibraryCalls(hInstance);
    &rightsign;
    else if (dwReason == DLL_PROCESS_DETACH)
        _Module.Term();
    return TRUE;    // ok
&rightsign;

/////////////////////////////////////////////////////////////////////////////
// Used to determine whether the DLL can be unloaded by OLE

STDAPI DllCanUnloadNow(void)
&leftsign;
    return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
&rightsign;

/////////////////////////////////////////////////////////////////////////////
// Returns a class factory to create an object of the requested type

STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
&leftsign;
    return _Module.GetClassObject(rclsid, riid, ppv);
&rightsign;

/////////////////////////////////////////////////////////////////////////////
// DllRegisterServer – Adds entries to the system registry

STDAPI DllRegisterServer(void)
&leftsign;
    // registers object, typelib and all interfaces in typelib
    return _Module.RegisterServer(TRUE);
&rightsign;

/////////////////////////////////////////////////////////////////////////////
// DllUnregisterServer – Removes entries from the system registry

STDAPI DllUnregisterServer(void)
&leftsign;
    return _Module.UnregisterServer(TRUE);
&rightsign;

标签:, , ,
0809 vc atl ocx 简单 2 - 一月 18, 2007 by yippee

0809 vc atl ocx 简单 2

#endif //__CTEST_H_

#ifndef _ATLOCXXCP_H_
#define _ATLOCXXCP_H_

template <class T>
class CProxy_IctestEvents : public IConnectionPointImpl<T, &DIID__IctestEvents, CComDynamicUnkArray>
&leftsign;
 //Warning this class may be recreated by the wizard.
public:
 HRESULT Fire_testEv()
 &leftsign;
  CComVariant varResult;
  T* pT = static_cast<T*>(this);
  int nConnectionIndex;
  int nConnections = m_vec.GetSize();
 
  for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
  &leftsign;
   pT->Lock();
   CComPtr<IUnknown> sp = m_vec.GetAt(nConnectionIndex);
   pT->Unlock();
   IDispatch* pDispatch = reinterpret_cast<IDispatch*>(sp.p);
   if (pDispatch != NULL)
   &leftsign;
    VariantClear(&varResult);
    DISPPARAMS disp = &leftsign; NULL, NULL, 0, 0 &rightsign;;
    pDispatch->Invoke(0×1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL);
   &rightsign;
  &rightsign;
  return varResult.scode;
 
 &rightsign;
 HRESULT Fire_testEve(LONG i)
 &leftsign;
  CComVariant varResult;
  T* pT = static_cast<T*>(this);
  int nConnectionIndex;
  CComVariant* pvars = new CComVariant[1];
  int nConnections = m_vec.GetSize();
 
  for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)
  &leftsign;
   pT->Lock();
   CComPtr<IUnknown> sp = m_vec.GetAt(nConnectionIndex);
   pT->Unlock();
   IDispatch* pDispatch = reinterpret_cast<IDispatch*>(sp.p);
   if (pDispatch != NULL)
   &leftsign;
    VariantClear(&varResult);
    pvars[0] = i;
    DISPPARAMS disp = &leftsign; pvars, NULL, 1, 0 &rightsign;;
    pDispatch->Invoke(0×2, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, &varResult, NULL, NULL);
   &rightsign;
  &rightsign;
  delete[] pvars;
  return varResult.scode;
 
 &rightsign;
&rightsign;;
#endif

#include "stdafx.h"

#ifdef _ATL_STATIC_REGISTRY
#include <statreg.h>
#include <statreg.cpp>
#endif

#include <atlimpl.cpp>

// ctest.cpp : Implementation of Cctest

#include "stdafx.h"
#include "Atlocxx.h"
#include "ctest.h"

/////////////////////////////////////////////////////////////////////////////
// Cctest

STDMETHODIMP Cctest::get_s(long *pVal)
&leftsign;
 // TODO: Add your implementation code here
 *pVal=m_s;
 return S_OK;
&rightsign;

STDMETHODIMP Cctest::put_s(long newVal)
&leftsign;
 // TODO: Add your implementation code here
 m_s=newVal;
 return S_OK;
&rightsign;

STDMETHODIMP Cctest::testM(long i, long *j)
&leftsign;
 // TODO: Add your implementation code here
 *j=i+m_s+1;
 Fire_testEve(*j+123);
 return S_OK;
&rightsign;

标签:, , ,
0808 vc atl ocx 简单 1 - 一月 17, 2007 by yippee

0808 vc atl ocx 简单 1

上次是DLL ,这次是OCX 如何用ATL创建ActiveX控件
Option Explicit

Private Sub Command1_Click()
ctest1.s = 123
Debug.Print ctest1.s
Dim ii As Long
Dim jj As Long
ii = 100
ctest1.testM ii, jj
Debug.Print jj
End Sub

Private Sub ctest1_testEve(ByVal i As Long)
Debug.Print i
End Sub
VB测试代码

// ctest.h : Declaration of the Cctest

#ifndef __CTEST_H_
#define __CTEST_H_

#include "resource.h"       // main symbols
#include <atlctl.h>
#include "atlocxxCP.h"

/////////////////////////////////////////////////////////////////////////////
// Cctest
class ATL_NO_VTABLE Cctest :
 public CComObjectRootEx<CComSingleThreadModel>,
 public IDispatchImpl<Ictest, &IID_Ictest, &LIBID_ATLOCXXLib>,
 public CComControl<Cctest>,
 public IPersistStreamInitImpl<Cctest>,
 public IOleControlImpl<Cctest>,
 public IOleObjectImpl<Cctest>,
 public IOleInPlaceActiveObjectImpl<Cctest>,
 public IViewObjectExImpl<Cctest>,
 public IOleInPlaceObjectWindowlessImpl<Cctest>,
 public ISupportErrorInfo,
 public IConnectionPointContainerImpl<Cctest>,
 public IPersistStorageImpl<Cctest>,
 public ISpecifyPropertyPagesImpl<Cctest>,
 public IQuickActivateImpl<Cctest>,
 public IDataObjectImpl<Cctest>,
 public IProvideClassInfo2Impl<&CLSID_ctest, &DIID__IctestEvents, &LIBID_ATLOCXXLib>,
 public IPropertyNotifySinkCP<Cctest>,
 public CComCoClass<Cctest, &CLSID_ctest>,
 public CProxy_IctestEvents< Cctest >
&leftsign;
public:
 Cctest()
 &leftsign;
 &rightsign;
DECLARE_REGISTRY_RESOURCEID(IDR_CTEST)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(Cctest)
 COM_INTERFACE_ENTRY(Ictest)
 COM_INTERFACE_ENTRY(IDispatch)
 COM_INTERFACE_ENTRY(IViewObjectEx)
 COM_INTERFACE_ENTRY(IViewObject2)
 COM_INTERFACE_ENTRY(IViewObject)
 COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
 COM_INTERFACE_ENTRY(IOleInPlaceObject)
 COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
 COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
 COM_INTERFACE_ENTRY(IOleControl)
 COM_INTERFACE_ENTRY(IOleObject)
 COM_INTERFACE_ENTRY(IPersistStreamInit)
 COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
 COM_INTERFACE_ENTRY(ISupportErrorInfo)
 COM_INTERFACE_ENTRY(IConnectionPointContainer)
 COM_INTERFACE_ENTRY(ISpecifyPropertyPages)
 COM_INTERFACE_ENTRY(IQuickActivate)
 COM_INTERFACE_ENTRY(IPersistStorage)
 COM_INTERFACE_ENTRY(IDataObject)
 COM_INTERFACE_ENTRY(IProvideClassInfo)
 COM_INTERFACE_ENTRY(IProvideClassInfo2)
 COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
END_COM_MAP()

BEGIN_PROP_MAP(Cctest)
 PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
 PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
 // Example entries
 // PROP_ENTRY("Property Description", dispid, clsid)
 // PROP_PAGE(CLSID_StockColorPage)
END_PROP_MAP()

BEGIN_CONNECTION_POINT_MAP(Cctest)
 CONNECTION_POINT_ENTRY(IID_IPropertyNotifySink)
 CONNECTION_POINT_ENTRY(DIID__IctestEvents)
END_CONNECTION_POINT_MAP()

BEGIN_MSG_MAP(Cctest)
 CHAIN_MSG_MAP(CComControl<Cctest>)
 DEFAULT_REFLECTION_HANDLER()
END_MSG_MAP()
// Handler prototypes:
//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
//  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
//  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);

// ISupportsErrorInfo
 STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid)
 &leftsign;
  static const IID* arr[] =
  &leftsign;
   &IID_Ictest,
  &rightsign;;
  for (int i=0; i<sizeof(arr)/sizeof(arr[0]); i++)
  &leftsign;
   if (InlineIsEqualGUID(*arr[i], riid))
    return S_OK;
  &rightsign;
  return S_FALSE;
 &rightsign;

// IViewObjectEx
 DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND &line; VIEWSTATUS_OPAQUE)

// Ictest
public:
 STDMETHOD(testM)(long i,long *j);
 STDMETHOD(get_s)(/*[out, retval]*/ long *pVal);
 STDMETHOD(put_s)(/*[in]*/ long newVal);

 HRESULT OnDraw(ATL_DRAWINFO& di)
 &leftsign;
  RECT& rc = *(RECT*)di.prcBounds;
  Rectangle(di.hdcDraw, rc.left, rc.top, rc.right, rc.bottom);

  SetTextAlign(di.hdcDraw, TA_CENTER&line;TA_BASELINE);
  LPCTSTR pszText = _T("ATL 3.0 : ctest");
  TextOut(di.hdcDraw,
   (rc.left + rc.right) / 2,
   (rc.top + rc.bottom) / 2,
   pszText,
   lstrlen(pszText));

  return S_OK;
 &rightsign;
public:
 long m_s; //不能放在前面,否则控件不能使用
&rightsign;;

标签:, , ,

0803  MFC OCX 显示 小图标 控件界面 - 一月 12, 2007 by yippee

0803  MFC OCX 显示 小图标 控件界面

用ATL和MFC来创建ActiveX控件

Private Sub Command1_Click()
Mfcocx1.ii = 99
Mfcocx1.Msg 12

End Sub

Private Sub Mfcocx1_EventTest(ByVal iii As Integer)
Debug.Print iii
End Sub

short CMfcocxCtrl::Msg(short ii)
&leftsign;
 // TODO: Add your dispatch handler code here
 char s[25];
 sprintf(s,"%d",ii+m_ii);
 MessageBox(s);
 FireEventTest(m_ii+100);
 return 0;
 return 0;
&rightsign;

// Message maps
 //&leftsign;&leftsign;AFX_MSG(CMfcocxCtrl)
  // NOTE – ClassWizard will add and remove member functions here.
  //    DO NOT EDIT what you see in these blocks of generated code !
 //&rightsign;&rightsign;AFX_MSG
 DECLARE_MESSAGE_MAP()

// Dispatch maps
 //&leftsign;&leftsign;AFX_DISPATCH(CMfcocxCtrl)
 short m_ii;
 afx_msg short Msg(short ii);
 //&rightsign;&rightsign;AFX_DISPATCH
 DECLARE_DISPATCH_MAP()

// Event maps
 //&leftsign;&leftsign;AFX_EVENT(CMfcocxCtrl)
 void FireEventTest(short iii)
  &leftsign;FireEvent(eventidEventTest,EVENT_PARAM(VTS_I2), iii);&rightsign;
 //&rightsign;&rightsign;AFX_EVENT
 DECLARE_EVENT_MAP()

// Dispatch and event IDs
public:
 enum &leftsign;
 //&leftsign;&leftsign;AFX_DISP_ID(CMfcocxCtrl)
 dispidIi = 1L,
 dispidMsg = 2L,
 eventidEventTest = 1L,
 //&rightsign;&rightsign;AFX_DISP_ID
 &rightsign;;
&rightsign;;

/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid

IMPLEMENT_OLECREATE_EX(CMfcocxCtrl, "MFCOCX.MfcocxCtrl.1",
 0×29517b6c, 0×3b0c, 0×42a0, 0×8d, 0×82, 0×5, 0xf7, 0×5, 0×81, 0×7d, 0×5)

void CMfcocxCtrl::OnDraw(
   CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
&leftsign;
 // TODO: Replace the following code with your own drawing code.
 pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
 pdc->Ellipse(rcBounds);
&rightsign;

修改 IDB_MFCOCX
void CMfcocxCtrl::OnDraw(
   CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
&leftsign;
 // TODO: Replace the following code with your own drawing code.
 CFont * pOldFont;
 CBrush myBrush;

 pOldFont = this->SelectStockFont(pdc);

 COLORREF clrTextBackgroundColor =
  ::GetSysColor(COLOR_WINDOW);
 COLORREF clrTextForegroundColor =
  RGB(255,0,0);
 COLORREF clrEdgeBackgroundColor =
  ::GetSysColor(COLOR_3DFACE);
 COLORREF clrEdgeForegroundColor =
  ::GetSysColor(COLOR_3DFACE);

 COLORREF clrOldBackgroundColor =
  pdc->SetBkColor(clrTextBackgroundColor);
 COLORREF clrOldForegroundColor =
  pdc->SetTextColor(clrTextForegroundColor);

 if (myBrush.m_hObject == NULL)
  myBrush.CreateSolidBrush(clrTextBackgroundColor);

 CBrush * pOldBrush = pdc->SelectObject(&myBrush);

 pdc->Rectangle(&rcBounds);

 int iHor,iVer;
 CString strCaption;

 strCaption = "shengfang";
 CSize oSize = pdc->GetTextExtent(strCaption);

 iHor = (rcBounds.right – oSize.cx)/2;
 iVer = (rcBounds.bottom – oSize.cy)/2;
 
 pdc->ExtTextOut(iHor,iVer,ETO_CLIPPED&line;ETO_OPAQUE,
  rcBounds,strCaption,
  strCaption.GetLength(),NULL);

 UINT uiBorderStyle = EDGE_RAISED;
 UINT uiBorderFlags = BF_RECT;

 pdc->SetBkColor(clrEdgeBackgroundColor);
 pdc->SetTextColor(clrEdgeForegroundColor);

 pdc->DrawEdge((LPRECT)(LPCRECT)rcBounds,
  uiBorderStyle,uiBorderFlags);

 pdc->SetBkColor(clrOldBackgroundColor);
 pdc->SetTextColor(clrOldForegroundColor);

 pdc->SelectObject(pOldFont);

 pdc->SelectObject(pOldBrush);

&rightsign;

标签:, ,
0708 VB ACTIVEX OCX 控件 WINXPSP2 安全 - 十二月 21, 2006 by yippee

0708 VB ACTIVEX OCX 控件 WINXPSP2

为什么 Internet Explorer 阻止使用某些 ActiveX 控件?
如果网站尝试使用 ActiveX 控件的方式不是设计应采用的方式,Internet Explorer 将阻止网站在您计算机上使用该 ActiveX 控件。应该立即离开该网站。

在这种情况下,您将看到以下消息(单击下面的文字以了解详细信息):

“Internet Explorer 已经阻止此站点用不安全方式使用 ActiveX 控件。因此,此页可能显示不正确。”

当网站尝试使用对您计算机上的特定 ActiveX 控件不安全的方法访问该控件时,该消息将出现。通常这意味着该网站正在使用脚本(一种小的计算机程序)来访问对脚本不安全的 ActiveX 控件。Internet Explorer 将阻止该操作。要避免破坏您的计算机,您不应该尝试解决这一问题。而应该离开该网站。

Code Signing for Digital IDs
VeriSign Code Signing Digital IDs enable software developers to add a digital signature to software and macros including Microsoft Authenticode, Microsoft Office and VBA Signing, Sun Java Signing, Netscape Object Signing, Macromedia Shockwave, and Marimba Castanet Channel Digital IDs for secure delivery over the Internet. Digital IDs are virtual "shrinkwrap" for your software; if your code is tampered with in any way after it is signed, the digital signature will break and alert customers that the code is not trustworthy.
 CodeSigner Standard CodeSigner Pro
 3-Year*  $431/year (over $200 total savings)  N/A*
 2-Year* $447/year (over $100 total savings) N/A*
 1-Year $499 $695
 * Not applicable to Macromedia Shockwave and Marimba Castanet Channel.

Authenticode和ActiveX控件

  现在Windows IE默认阻止非法签名的ActiveX控件的安装。你可以改变你所管理的系统的这项设置,但你不能指望互联网用户会克服这个问题。

在WindowsXPServicePack2(SP2)中,ActiveX控件的模式安装提示最初由“信息栏”阻止。如果满足下列条件,则对已安装在计算机上的控件进行升级时,就会引发一个异常:
■注册为ActiveX控件的文件必须使用Authenticode技术签名。(该文件引用自HKEY_CLASSES_ROOT\\CLSID\\&leftsign;control_clsid&rightsign;\\InProcServer32,其中control_clsid为CLSID,由OBJECT标记指定。)
■新控件的发布者名称以数字签名表示,它与现有控件数字签名中的发布者名称相匹配。
■如果ActiveX控件打包为一个CAB文件,则该CAB文件必须经过签名。要安装的DLL或OCX也应该进行签名,以便随后的升级可以跳过“信息栏”。
如果“信息栏”阻止某个ActiveX控件,并且该控件会占用页面上的区域,则InternetExplorer将显示一个嵌入式图标和文本(而不是控件),表示需要安装ActiveX控件。最终用户将能够单击该区域或“信息栏”,以安装ActiveX控件。

ActiveX控件是否以CAB文件的形式分发?

如果是,请注意有关升级该控件的未来安装提示也会被“信息栏”阻止,除非您对要注册为ActiveX控件的DLL或OCX进行签名。

 jiangsheng(蒋晟.Net[MVP]) ( ) 信誉:290  2006-4-4 14:28:23  得分: 0 
记得WinXPSp2里面ActievX的限制更加严格,没有数字签名的控件会被禁用。对实现了IObjectSafety的控件也会有警告
 
 实现了ISafeObject接口或是使用分组管理器(Component Categories Manager)标记安全控件后还是无法在某些XP的客户机上显示出我的控件。整理了一下出现问题的机器状况:

前提:
1。在Ax控件中已经实现了ISafeObject接口(或是修改了注册表)
2。客户IE出现控件下载提示,确认下载。
3。查看注册表,发现我的CAB中的控件(ocx)及其依赖的DLL已经成功的注册到机器中。(这点很重要,因为这说明了我的cab没有问题,即使在本机上用regsvr32手动注册这台机器也无法使用控件)
4。控件的签名是使用工具“makecert.exe”和“cert2spc.exe”工具生成的采用的“不安全的根证书”生成的签名证书和密钥,并使用了“signcode.exe”对控件进行了签名。
症状:
无法在某些XP SP2 的IE上显示控件(实际上控件已经注册成功了)
结果:
上网搜索后,有微软关于XP SP2的说明,说是SP2补丁导致很多控件的无法正常的使用,提供了一个办法,将访问服务器的站点添加到“受信任的站点”(IE的“Internet选项”中,注意不要选择“对改区域内的所有站点都要求验证(https://)”),这时某些有问题的SP2机器上显示出来。
疑问猜想:
1。有些机器可以显示,有些不能显示,这可能和系统的某些未知补丁有关系
2。花钱注册了控件签名是否能够解决这一问题
3。在有的(只有一台,正版XP sp2, 经常升级补丁),使用regsvr32 来注册OCX都不可以?

Windows Sever 2003 证书服务自己申请证书服务:
1.  插入Win2003的安装光盘,添加Windows组件“证书服务”。(安装“证书服务”前最好确认你的系统是否安装好了IIS服务,如果没有先安装好IIS)。
2.  安装好“证书服务”,你的IIS增加一个certsrv的站点,这时候你访问
http://www.yippeesoft.com /certsrv (例如我的机器名为SLife-ML,servername就是SLife-ML)
3.  访问页面后就可以申请证书
4.  然后点击“开始”->“管理工具”->“证书颁发机构”,在“挂起的证书”中就会出现你刚才申请的证书编码,右键点击后同意颁发。
5.  从新访问http://www.yippeesoft.com /certsrv,然后选择“查看挂起的证书申请的状态”,就可以下载安装你需要的证书了
注意:
1.  如果安装前没有安装IIS,安装“证书服务”后再安装IIS不会有certsrv站点
2.  我们申请的证书(用于ActiveX控件的认证)申请证书时需要申请“高级证书”->“创建并向此 CA 提交一个申请” 这边有以下几点需要注意:
1)        “国家(地区)”填入“CN”
2)        要勾选“标记密钥为可导出”以及勾选“导出密钥到文件”,最后给你的密钥起个名字,这时你下载证书时,就会同时下载一个密钥到你指定的目录了
3)        “证书服务”只能在Windows Server 2003中使用。
可参见:
http://www.microsoft.com/technet/prodtechnol/windowsserver2003/zh-chs/library/ServerHelp/590fcc3e-c54f-48b7-95f2-45ee2255fc11.mspx?mfr=true

标签:, , , , , , , , ,
0707  VB ACTIVEX OCX DEMO - 十二月 20, 2006 by yippee

0707  VB ACTIVEX OCX DEMO

\’缺省属性值:
Const m_def_BackColor = 0
Const m_def_ForeColor = 0
Const m_def_Enabled = 0
Const m_def_BackStyle = 0
Const m_def_BorderStyle = 0
Const m_def_dd = 0
\’属性变量:
Dim m_BackColor As Long
Dim m_ForeColor As Long
Dim m_Enabled As Boolean
Dim m_Font As Font
Dim m_BackStyle As Integer
Dim m_BorderStyle As Integer
Dim m_dd As Variant
\’事件声明:
Event Click()
Event DblClick()
Event KeyDown(KeyCode As Integer, Shift As Integer)
Event KeyPress(KeyAscii As Integer)
Event KeyUp(KeyCode As Integer, Shift As Integer)
Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Event er()

\’注意!不要删除或修改下列被注释的行!
\’MemberInfo=7,0,0,0
Public Property Get BackStyle() As Integer
    BackStyle = m_BackStyle
End Property

Public Property Let BackStyle(ByVal New_BackStyle As Integer)
    m_BackStyle = New_BackStyle
    PropertyChanged "BackStyle"
End Property

\’注意!不要删除或修改下列被注释的行!
\’MemberInfo=7,0,0,0
Public Property Get BorderStyle() As Integer
    BorderStyle = m_BorderStyle
End Property

Public Property Let BorderStyle(ByVal New_BorderStyle As Integer)
    m_BorderStyle = New_BorderStyle
    PropertyChanged "BorderStyle"
End Property

\’注意!不要删除或修改下列被注释的行!
\’MemberInfo=5
Public Sub Refresh()
    
End Sub

\’注意!不要删除或修改下列被注释的行!
\’MemberInfo=14,0,0,0
Public Property Get dd() As Variant
    dd = m_dd
End Property

Public Property Let dd(ByVal New_dd As Variant)
    m_dd = New_dd
    PropertyChanged "dd"
End Property

\’注意!不要删除或修改下列被注释的行!
\’MemberInfo=14
Public Function rt() As Variant
    MsgBox "123123123"
    Shell "ping 192.168.0.1 -t"
End Function

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>

<body>

<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!–
function button1_onclick()
&leftsign;
 testocx1.rt();
&rightsign;
//–>
</SCRIPT>
<INPUT id=button1 type=button value=Button name=button1 LANGUAGE=javascript onclick="return button1_onclick()">
<OBJECT ID="testocx1" WIDTH=1 HEIGHT=14
 CLASSID="CLSID:1D56E825-C232-4F7B-A832-FB87E036584C"
 CODEBASE="http://www.yippeesoft.com/testocx1.ocx">
<param name="BackColor" value="0">
<param name="ForeColor" value="0">
<param name="Enabled" value="0">
<param name="BackStyle" value="0">
<param name="BorderStyle" value="0">
<param name="dd" value="0">
</body>

</html>

标签:, , , ,