RE:Poner el Foco en un Proceso en Ejecución
Ya le encontré la vuelta, las instrucciones a usar son varias pero me funcionó lo siguiente:
APIS (En Módulo)
Public Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
Public Declare Function SetActiveWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Public Const GW_HWNDFIRST = 0&
Public Const GW_HWNDNEXT = 2&
Public Const GW_CHILD = 5&
CODIGO (En Formulario)
Private Function VentanasActivas() As String
' Devuelve en una Cadena los "Captions" de las Ventanas actuales y el Handle asociado
' Salida = CaptionVentana|Handle;CaptionVentana1|Handle1;CaptionVentana2|Handle2; ...
Dim lBuf As Long
Dim lHandle As Long
Dim lLenT As Long
Dim lRet As Long
Dim sTitulo As String
On Error GoTo VerError
VentanasActivas = ""
lHandle = GetForegroundWindow
Rem lHandle = GetWindow(hwnd, GW_HWNDFIRST)
lHandle = GetWindow(hwnd, GW_HWNDFIRST)
lHandle = GetForegroundWindow
' SetActiveWindow ((lHandle))
' lHandle = GetWindow(hwnd, 4)
' lHandle = GetWindow(lHandle, GW_HWNDFIRST)
Do While (lHandle <> 0)
If IsWindowVisible(lHandle) Then
lLenT = GetWindowTextLength(lHandle)
If (lLenT <> 0) Then
sTitulo = String$(lLenT, 0)
lRet = GetWindowText(lHandle, sTitulo, lLenT + 1)
VentanasActivas = (VentanasActivas & sTitulo & "|" & Trim(Str(lHandle)) & ";")
End If ' (lLenT > 0)
End If ' (IsWindowVisible(lHandle))
lHandle = GetWindow(lHandle, GW_HWNDNEXT)
Loop ' (lHandle <> 0)
Exit Function
VerError:
Beep
VentanasActivas = ""
Exit Function
End Function
Private Sub Modulo_Llamador()
Dim lPosInicio As Long
Dim lPosFin As Long
Dim lHandle As Long
Dim vVentanas As Variant
On Error GoTo VerError
vVentanas = VentanasActivas
lPosInicio = InStr(1, vVentanas, "NombreDeLaAplicacion", vbTextCompare)
If (Val(lPosInicio) > 0) Then
' CaptionVentana|Handle;
lPosInicio = InStr(lPosInicio + 4, vVentanas, "|", vbTextCompare)
lPosFin = InStr(lPosInicio + 1, vVentanas, ";", vbTextCompare)
lHandle = Val(Mid(vVentanas, lPosInicio + 1, lPosFin - lPosInicio - 1))
BringWindowToTop ((lHandle))
Else
opcTalleryRepuestos.Enabled = False
MsgBox "El Aplicativo seleccionado ya no está Activo.", vbInformation + vbOKOnly, "DCS - " & Me.Caption & " ..."
End If ' (Val(lPosInicio) > 0)
Exit Sub
VerError:
Beep
Exit Sub
End Sub