以下是引用zhoujibin1在2006-7-23 16:40:20的发言:四、示例 (1)弹出一个对话框,提示计算机的名称,并且扬声器喇叭会鸣叫。 Private Declare Function Beep Lib "kernel32" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long Private Const MAX_COMPUTERNAME_LENGTH As Long = 31 Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long Sub ComputerName() Dim dwLen As Long Dim strString As String '创建缓冲区32位 dwLen = MAX_COMPUTERNAME_LENGTH + 1 strString = String(dwLen, "X") '获得计算机名称 GetComputerName strString, dwLen '获得实际名称字串 strString = Left(strString, dwLen) '播放频率为4500赫兹的扬声器声音,持续100微秒 For I = 0 To 5 Beep 4500, 100 DoEvents Next '显示计算机名称 MsgBox "电脑名称是 " & strString & ", 我搞对了吗?" End Sub 不错,找寻已久。谢谢分享。 |