'Option Explicit
'patricktoulon
'déclaration VBA7 en 32/64 bits
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As LongPtr, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare PtrSafe Function GetWindow Lib "user32" (ByVal hwnd As LongPtr, ByVal wCmd As Long) As Long
Declare PtrSafe Function ShowWindow Lib "user32" (ByVal hwnd As LongPtr, ByVal nCmdShow As Long) As Long
Sub Maximizemafenetretaratata()
Dim hwnd As Long
hwnd = FindWindoWByPartTitle("taratata", "Bloc-notes") ' chaine , nom de l'app qui l'execute (les 2 optionnels)
If hwnd <> 0 Then
ShowWindow hwnd, 3 ' 3 correspond à SW_MAXIMIZE
Else
MsgBox "Aucune fenetre contenant ""taratata"" n'est ouverte affichée ou reduites!"
End If
End Sub
Function FindWindoWByPartTitle(Optional partTittle As String = "", Optional PartApp As String = "")
Dim sStr As String, hwnd As LongPtr
sStr = Space$(150)
hwnd = FindWindow(vbNullString, vbNullString)
Do While hwnd <> 0
GetWindowText hwnd, sStr, 300
If sStr Like "*" & partTittle & "*" & PartApp & "*" Then
FindWindoWByPartTitle = hwnd
Exit Do
End If
hwnd = GetWindow(hwnd, 2)
Loop
End Function