一、添加控件并修改属性
首先打开VB,建立一个EXE文件,在该窗体上放置控件如下:三个Label控件,标题分别为"当前时间"、"欢迎你使用网络设置"和"使你能够轻松控制上网"。三个Button控件,标题分别为"确定"、"取消"和"立即登陆"。三个Text控件,两个Check控件,标题分别为"上网时间"和"下网时间",Value的值都为1,就是被选中状态,最后是两个Timer控件,Timer1的Enabled值为True,Timer2的为False,两个的Interval值都为1。调整好后如图所示。
二、编写代码
为实现网络的连接和断开需要在程序开头声明以下函数:
Const INTERNET_DIALSTATE_DISCONNECTED = 1 Const INTERNET_AUTODIAL_FORCE_ONLINE = 1 Const INTERNET_AUTODIAL_FORCE_UNATTENDED = 2 Const INTERNET_DIAL_UNATTENDED = &H8000 Dim iHandle As Long Private Declare Function Inte.netDial Lib "wininet.dll" ( _ByVal hwndParent As Long, _ByVal lpszConnectoid As String, _ByVal dwFlags As Long, _lpdwConnection As Long, _ByVal dwReserved As Long) As Long |
参数dwConnection指定拨号连接句柄
Private Declare Function InternetHangUp Lib "wininet.dll" _ (ByVal dwConnection As Long, _ ByVal dwReserved As Long) As Long Private Declare Function InternetAutodial Lib "wininet.dll" _ (ByVal dwFlags As Long, ByVal dwReserved As Long) As Long Private Declare Function InternetAutodialHangup Lib "wininet.dll" _ (ByVal dwReserved As Long) As Long Private Sub Check1_Click() Private Sub Check2_Click() Private Sub Command1_Click() Private Sub Command2_Click() Private Sub Command3_Click() Private Sub Form_Load() Private Sub Timer1_Timer() Private Sub Timer2_Timer() |
以上就是程序的全部源代码,编译后就是一个简单控制上网的小软件,操作简单,非常实用,以上程序在Windows98+VB6.0中调试通过。其实通过这个小程序可以看出,很多的实用小软件都源于我们日常生活中的一些小问题,只要你善于发现和思考,相信你也一样能够做到。
文章来源于领测软件测试网 https://www.ltesting.net/
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073