我用Shell App.Path & "\test.exe" 运行起来一个别人的拿C写的程序。但是他不是焦点,我想让在shell 以后的1秒钟后获得焦点,如何做到?
Timer1.Interval = 1000Private Sub Timer1_Timer()
'这里面怎么写?????
End Sub
别说Shell App.Path & "\test.exe", vbNormalFocus 啊!这样这个 test.exe 运行后直接就能获得焦点!我要他在运行后1秒钟获得焦点~ 如何做到??

解决方案 »

  1.   


     试试:AppActivate "计算器"
      

  2.   

    试试:SetFocusAPIPrivate Declare Function SetFocusAPI Lib "user32" Alias "SetFocus" (ByVal hWnd As Long) As Long
      

  3.   

    通用声明里面:Private Declare Function SetForegroundWindow Lib "User32" (ByVal hWnd As Long) As Long
    Private Declare Function ShowWindow Lib "User32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
    Const SW_RESTORE = 9
    Const SW_SHOWNORMAL = 1
    Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const WM_SYSCOMMAND = &H112
    Private Const SC_RESTORE = &HF120&
    Private Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Sub Timer1_Timer()
    hWindow = FindWindow(vbNullString, "这里写下你的程序的标题")
        If hWindow <> 0 Then
            SendMessage hWindow, WM_SYSCOMMAND, SC_RESTORE, 0&
            ShowWindow hWindow, SW_SHOWNORMAL
            SetForegroundWindow hWindow
            Else
            MsgBox "No Found Window"
        End If
    Timer1.Enabled = False
    End Sub