本节将创建并测试自己的activex exe程序。
示例中将使用这样一个组件,它是一个有效的文件探测器。大约每隔60秒检测指定文件的存在性。如何该文件存在,该组件激发一个事件来调用应用程序,如果不存在,则另作处理。
当然,如果将所有代码写到activex dll工程,则运行时程序代码将被挂起直到文件检测代码运行完毕为止。由于activex exe工程拥有自己的进程空间,代码运行时会自我协调、异步处理,从而不会使其他程序代码停顿。
下面就来创建:
新建一个"activex exe"工程;
工程名设为"file";
添加的类名为"filecheck";
下一步,我们需要构造一些用于每隔1分钟左右检测文件的代码。这里将在activex exe工程插入一个带有计时器的表单。但该表单不会被显示,因为我们只是使用上面的计时器控件每隔1分钟左右来检测文件,如果相应的文件被检测到,则激发一个事件。
选择"project"->"add form";
在表单form1中添加一个计时器;
在表单代码中添加下列变量的声明:
| public filename as string |
| public event filefound() |
| private sub timer1_timer() if dir(filename) <> "" then raiseevent filefound timer1.interval = 0 end if end sub |
| dim withevents objfilecheck as form1 |
| public filename as string |
| private sub timer1_timer() if dir(filename) <> "" then raiseevent filefound timer1.interval = 0 end if end sub |
| dim withevents objfilecheck as form1 |
| private sub class_initialize() set objfilecheck = new form1 end sub |
| public sub monitorfile(filename as string) objfilecheck.filename = filename objfilecheck.timer1.interval = 60000 end sub |
| public event filefound(filename as string) |
| private sub objfilecheck_filefound ( ) raiseevent filefound ( objfilecheck.filename) end sub |
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器