事情是这样的:
  我要运行一个exe文件,运行起来后先获得进程ID然后用进程ID查找到窗口,然后把窗口隐藏掉。
现在问题时:
  如何获得进程ID
  如何根据进程ID查找窗口
    谢谢!

解决方案 »

  1.   

    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
      

  2.   

    Public Declare Function GetWindowThreadProcessId Lib "user32" Alias "GetWindowThreadProcessId" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
    这是根据进程句柄获得进程ID的函数
      

  3.   

    上面说得不够准确
    GetWindowThreadProcessId VB声明 
    Declare Function GetWindowThreadProcessId Lib "user32" Alias "GetWindowThreadProcessId" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
     
    说明 
    获取与指定窗口关联在一起的一个进程和线程标识符 
    返回值 
    Long,拥有窗口的线程的标识符 
    参数表 
    参数 类型及说明 
    lpdwProcessId Long,指定一个变量,用于装载拥有那个窗口的一个进程的标识符 
    hwnd Long,指定窗口句柄