OK. Je n'ai pas été très sympa hier. Sans doute de mauvais poil. Voila une solution.
Accroche toi, on y va.....
A copier en tête de procédure, au niveau des déclarations globales:
Private Declare Function SetWindowPos _
Lib "user32" (ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal X As Long, ByVal Y As Long, _
ByVal cx As Long, ByVal cy As Long, _
ByVal wFlags As Long) As Long
Private Declare Function OpenIcon Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function GetWindow Lib "user32" _
(ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" _
Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextA" (ByVal hwnd As Long, _
ByVal lpSting As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hwnd As Long, _
ByVal wIndx As Long) As Long
Const GW_HWNDFIRST = 0 ' Handle de la 1ere fenetre
Const GW_HWNDNEXT = 2 ' Handle de la prochaine fenetre
Const GWL_STYLE = (-16) ' Récupère le style de la fenetre
Const HWND_TOPMOST = -1 ' Force la fenetre au 1er plan.
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1
A copier dans la procédure qui doir ouvrir ta fenêtre:
Dim hwCurr As Long
Dim intLen As Long
Dim strTitle As String, Appli As String
hwCurr = GetWindow(Me.hwnd, GW_HWNDFIRST) ' On commence par la premiere fenetre
Do While hwCurr ' On boucle sur toutes les fenetres
If hwCurr <> Me.hwnd And TaskWindow(hwCurr) Then ' On ignore la fenetre du prog.
intLen = GetWindowTextLength(hwCurr) + 1 ' Longueur de la caption de fenetre
strTitle = Space$(intLen) ' Caption de fenetre
intLen = GetWindowText(hwCurr, strTitle, intLen)
If intLen > 0 Then ' Si la fenetre a une caption interessante..
If InStr(1, strTitle, "Excel", vbTextCompare) > 1 _ Then ' On regarde si c'est la bonne
OpenIcon (hwCurr) ' Miracle!!! la fenetre s'ouvre !!!
SetWindowPos hwCurr, HWND_TOPMOST, 0, 0, 0, 0, _ SWP_NOMOVE + SWP_NOSIZE
Exit Do ' Le boulot est fait. On sort.
End If
End If
End If
hwCurr = GetWindow(hwCurr, GW_HWNDNEXT) ' On passe à la suivante
Loop
Petite fonction à ajouter à la fin de ton code:
Function TaskWindow(hwCurr As Long) As Long
Dim lngStyle As Long
Dim IsTask As Long
' Voyons si la fenetre est une tache qui nous interesserait....
lngStyle = GetWindowLong(hwCurr, GWL_STYLE)
If (lngStyle And IsTask) = IsTask Then TaskWindow = True
End Function
Cet exemple fonctionne avec Excel réduit en icone. Pour l'adapter à ton cas, remplace la chaine "Excel" par une partie du titre de ton appli à ouvrir.
---------------
J'ai un message.."Cliquez OK pour continuer."...Qu'est ce que je fais ?