📄 form1.frm
字号:
VERSION 5.00
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "网络域名"
ClientHeight = 1950
ClientLeft = 45
ClientTop = 330
ClientWidth = 3180
Icon = "Form1.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 1950
ScaleWidth = 3180
StartUpPosition = 1 '所有者中心
Begin VB.CommandButton CmdGetDomainName
Caption = "运行(&R)"
Default = -1 'True
Height = 495
Left = 960
TabIndex = 2
Top = 1200
Width = 1215
End
Begin VB.TextBox TxtDomainName
Height = 375
Left = 720
TabIndex = 1
Text = "TxtDomainName"
Top = 600
Width = 1935
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "网络域名:"
Height = 180
Left = 480
TabIndex = 0
Top = 240
Width = 900
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub CmdGetDomainName_Click()
TxtDomainName = GetDomainName()
End Sub
Private Function GetDomainName() As String
Dim buff() As Byte
Dim cbRequired As Long
Dim nStructSize As Long
Dim Info As FIXED_INFO
'以空pFixedInfo参数调用api函数
'这样该API函数会返回存放数据所需的缓存大小,
'该值被保存在参数cbRequired中
Call GetNetworkParams(ByVal 0&, cbRequired)
If cbRequired > 0 Then
'创建所需大小的缓存
ReDim buff(0 To cbRequired - 1) As Byte
'再一次调用API函数
If GetNetworkParams(buff(0), cbRequired) = ERROR_SUCCESS Then
'拷贝该缓存中的数据为FIXED_INFO类型
CopyMemory Info, ByVal VarPtr(buff(0)), LenB(Info)
'返回主机名称
GetDomainName = TrimNull(StrConv(Info.DomainName, vbUnicode))
End If
End If
End Function
Private Function TrimNull(item As String)
Dim pos As Integer
'检查字符串中是否有chr$(0)字符)(即空字符)
pos = InStr(item, Chr$(0))
If pos Then
TrimNull = Left$(item, pos - 1)
Else: TrimNull = item
End If
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -