Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long Private Const SW_HIDE = 0 Private Const SW_SHOW = 5Dim l As LongPrivate Sub Command1_Click() l = FindWindow(vbNullString, "计算器") ShowWindow l, SW_SHOW End SubPrivate Sub Command2_Click() l = FindWindow(vbNullString, "计算器") ShowWindow l, SW_HIDE End SubPrivate Sub Form_Load() Shell "calc.exe" End Sub
Public Declare Function GetWindowThreadProcessId Lib "user32" Alias "GetWindowThreadProcessId" (ByVal hwnd As Long, lpdwProcessId As Long) As Long 这是根据进程句柄获得进程ID的函数
上面说得不够准确 GetWindowThreadProcessId VB声明 Declare Function GetWindowThreadProcessId Lib "user32" Alias "GetWindowThreadProcessId" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_HIDE = 0
Private Const SW_SHOW = 5Dim l As LongPrivate Sub Command1_Click()
l = FindWindow(vbNullString, "计算器")
ShowWindow l, SW_SHOW
End SubPrivate Sub Command2_Click()
l = FindWindow(vbNullString, "计算器")
ShowWindow l, SW_HIDE
End SubPrivate Sub Form_Load()
Shell "calc.exe"
End Sub
这是根据进程句柄获得进程ID的函数
GetWindowThreadProcessId VB声明
Declare Function GetWindowThreadProcessId Lib "user32" Alias "GetWindowThreadProcessId" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
说明
获取与指定窗口关联在一起的一个进程和线程标识符
返回值
Long,拥有窗口的线程的标识符
参数表
参数 类型及说明
lpdwProcessId Long,指定一个变量,用于装载拥有那个窗口的一个进程的标识符
hwnd Long,指定窗口句柄