看了一个VB API的应用,原文中的程序是
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Sub Form_Load()
Dim hwnd As
Long' 储存 FindWindow 函数返回的句柄
hwnd = FindWindow(vbNullString, 计算器)' 取得进程标识符
If hwnd = 0 Then
Label1.Caption = "程序未运行"
Else
Label1.Caption = "程序已运行"
End If
End Sub
我把hwnd改成了a,但由于一时手误,if语句中的没改,如下
Private Sub Form_Load()
Dim a As Long
a = FindWindow(vbNullString, "计算器")
If hwnd = 0 Then
Label1.Caption = "程序未运行"
Else
Label1.Caption = "程序已运行"
End If
End Sub
结果不管计算器开没开,都是“程序已运行”,后来我又把if语句中的hwnd换成了b,结果老是“程序未运行”,与预期一样,为什么换成hwnd就会出错呢?是不是hwnd还有什么特殊意义?