手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网络编程>Asp.Net编程>列表

API函数在VB开发中的应用

来源:互联网 作者:西部数码 时间:2008-04-09
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!
  VB作为快速开发Windows下的编程工具,已经为越来越多的开发者采用。但如果要开发出专业的Windows软件,还需采用大量的API函数,以下结合笔者开发管理软件的经验谈几点体会。

  1.程序中判定Windows的版本

  众所周知,Windows3.x各版本或多或少会有些差别,为了使开发程序避免出现莫名其妙的错误,最好在程序运行前自动判定Windows的版本。采用API提供的函数getversion很容易实现这一点。函数声明如下:

Declare Function GetVersion Lib"Kernel"() As Integer
  此函数没有参数,返回值为Windows的版本号,其中版本号的低位字节为Windows的主版本号,版本号的高位字节返回Windows的次版本号。判别过程如下:

Private Sub Form_Load ()
Dim ver As Integer
Dim major As Integer
Dim minor As Integer
Ver = GetVersion ()
major = ver And &HFF
minor = (ver And &HFF00) \ 256
If major <> 3 And minor <> 10 Then
MsgBox "版本不正确!"
Exit Sub
End If
End Sub

  2.程序中判断Windows的安装目录

  一般VB开发出来的程序包含vbrun300.dll等辅助文件和.vbx文件,它们均需安装到Windows目录(c:\windows)或Windows的系统目录(c:\windows\system)下,但因为用户安装Windows时可能会改变Windows的目录名(如c:\windows),使用安装软件后,不能正确运行.API中提供的GetwinDowsdirectory或GetSystemDirectory较好地解决了这个问题。函数声明如下:
 
Declare Function GetSystemDirectory Lib "Kernel"(ByVal lpBuffer As
String,ByVal nSize As Integer) As Integer
 
  其中参数lpbuffer为字串变量,将返回实际Windows目录或Windows的系统目录,nsize为lpbuffer的字串变量的大小,函数返回值均为实际目录的长度。检查函数如下:
 
Function checkdir() As Boolean
 Dim windir As String * 200
 Dim winsys As String * 200
 Dim winl As Integer
 Dim wins As Integer
 Dim s1 As String
 Dim s2 As String
 winl = GetWindowsDirectory(windir,200)
 winl = GetSystemDirectory(winsys,200)
 s1 = Mid $(windir,1,winl)
 s2 = Mid $(winsys,1,wins)
 If Wins = 0 Or wins = 0 Then
  checkdir = False
  Exit Function
 End If
 If s1 <> "C:\WINDOWS" Or s2 <> "C:\WINDOWS\SYSTEM" Then
  checkdir = False
  Exit Function
 End If
 checkdir = True
End Function

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!