16,553
社区成员
发帖
与我相关
我的任务
分享
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As UInteger
Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As UInteger, ByRef lpdwProcessId As UInteger) As UInteger
Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess As UInteger, _
ByVal bInheritHandle As UInteger, ByVal dwProcessId As UInteger) As UInteger
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer
'Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Boolean
Public Const SW_HIDE = 0
Public Const SW_NORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_SHOWNOACTIVATE = 4
Public Const SW_SHOW = 5
Public Const SW_MINIMIZE = 6
Public Const SW_SHOWMINNOACTIVE = 7
Public Const SW_SHOWNA = 8
Public Const SW_RESTORE = 9
Public Const SW_SHOWDEFAULT = 10
Const PROCESS_ALL_ACCESS = &H1F0FFF
Public Hwd As UInteger
Public pid As UInteger
Public hProcess As UInteger
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Hwd = FindWindow((vbNullString), "1.txt - 记事本")
Label1.Text = Hwd
If Hwd = 0 Then
Label2.Text = "程序未运行"
Else
Label2.Text = "程序已运行"
GetWindowThreadProcessId(Hwd, pid)
hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, pid)
If hProcess = 0 Then
'MsgBox("不能读取进程", , "提示")
Else
'MsgBox("OK", , "提示!")
'隐藏窗体
'================================================
ShowWindow(Hwd, 0) '隐藏
'===============================================
End If
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Hwd = FindWindow((vbNullString), "1.txt - 记事本")
ShowWindow(Hwd, SW_SHOW) '显示
End Sub