OVH Cloud OVH Cloud

FindWindow et VB6

3 réponses
Avatar
News
Salut à tous
Je teste la présence d'une application en lancant un FINDWINDOW("appli",
argument)
Si elle existe ensuite, je voudrais la passer en premier plan, car elle est
dans la barre des tâches !
comment faire s'il vous plait ? Je pensais que GetWindowActive irait , mais
non !!!! :-(

Merci bcp
L.

3 réponses

Avatar
Jacques93
Bonjour News,
News a écrit :
Salut à tous
Je teste la présence d'une application en lancant un FINDWINDOW("appli",
argument)
Si elle existe ensuite, je voudrais la passer en premier plan, car elle est
dans la barre des tâches !
comment faire s'il vous plait ? Je pensais que GetWindowActive irait , mais
non !!!! :-(




Tu peux essayer ceci :

Après avoir récupéré la handle de la fenêtre, tu appelles :

MyHwnd = FindWindow ....
ForceForeWindow MyHwnd, True

'-------------------------------------------------------------
Option Explicit

Private Const SW_SHOW = 5
Private Const SW_RESTORE = 9

Private Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function AttachThreadInput Lib "user32" _
(ByVal idAttach As Long, ByVal idAttachTo As Long, _
ByVal fAttach As Long) As Long
Private Declare Function IsIconic Lib "user32" _
(ByVal hWnd As Long) As Long
Private Declare Function GetForegroundWindow Lib "user32" _
() As Long
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


Private Sub ForceForeGroundWindow(ByVal newHwnd As Long, _
Optional bRestoreIconic As Boolean = False)
Dim ThreadID1 As Long, ThreadID2 As Long
Dim X As Long

' Nouveau comportement de SetForeGroundWindow
' La fenêtre à activer doit appartenir au Thread appelant
If newHwnd = GetForegroundWindow() Then
Exit Sub
Else
ThreadID1 = GetWindowThreadProcessId(GetForegroundWindow(), 0)
ThreadID2 = GetWindowThreadProcessId(newHwnd, 0)
If ThreadID1 <> ThreadID2 Then
X = AttachThreadInput(ThreadID1, ThreadID2, True)
X = SetForegroundWindow(newHwnd)
X = AttachThreadInput(ThreadID1, ThreadID2, True)
Else
X = SetForegroundWindow(newHwnd)
End If
If IsIconic(newHwnd) And bRestoreIconic = True Then
X = ShowWindow(newHwnd, SW_RESTORE)
Else
X = ShowWindow(newHwnd, SW_SHOW)
End If
End If
End Sub
'-------------------------------------------------------------

--
Cordialement,

Jacques.
Avatar
News
MERCI BEAUCOUP
Ca fonctionne très bien !

:-)


"Jacques93" a écrit dans le message de news:

Bonjour News,
News a écrit :
Salut à tous
Je teste la présence d'une application en lancant un FINDWINDOW("appli",
argument)
Si elle existe ensuite, je voudrais la passer en premier plan, car elle
est dans la barre des tâches !
comment faire s'il vous plait ? Je pensais que GetWindowActive irait ,
mais non !!!! :-(




Tu peux essayer ceci :

Après avoir récupéré la handle de la fenêtre, tu appelles :

MyHwnd = FindWindow ....
ForceForeWindow MyHwnd, True

'-------------------------------------------------------------
Option Explicit

Private Const SW_SHOW = 5
Private Const SW_RESTORE = 9

Private Declare Function GetWindowThreadProcessId Lib "user32" _
(ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function AttachThreadInput Lib "user32" _
(ByVal idAttach As Long, ByVal idAttachTo As Long, _
ByVal fAttach As Long) As Long
Private Declare Function IsIconic Lib "user32" _
(ByVal hWnd As Long) As Long
Private Declare Function GetForegroundWindow Lib "user32" _
() As Long
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


Private Sub ForceForeGroundWindow(ByVal newHwnd As Long, _
Optional bRestoreIconic As Boolean = False)
Dim ThreadID1 As Long, ThreadID2 As Long
Dim X As Long

' Nouveau comportement de SetForeGroundWindow
' La fenêtre à activer doit appartenir au Thread appelant
If newHwnd = GetForegroundWindow() Then
Exit Sub
Else
ThreadID1 = GetWindowThreadProcessId(GetForegroundWindow(), 0)
ThreadID2 = GetWindowThreadProcessId(newHwnd, 0)
If ThreadID1 <> ThreadID2 Then
X = AttachThreadInput(ThreadID1, ThreadID2, True)
X = SetForegroundWindow(newHwnd)
X = AttachThreadInput(ThreadID1, ThreadID2, True)
Else
X = SetForegroundWindow(newHwnd)
End If
If IsIconic(newHwnd) And bRestoreIconic = True Then
X = ShowWindow(newHwnd, SW_RESTORE)
Else
X = ShowWindow(newHwnd, SW_SHOW)
End If
End If
End Sub
'-------------------------------------------------------------

--
Cordialement,

Jacques.


Avatar
Jacques93
Bonjour News,
News a écrit :
MERCI BEAUCOUP
Ca fonctionne très bien !

:-)




Merci du retour :-)

--
Cordialement,

Jacques.