Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

VBA EXCEL - OUVRIR WINDOWS EXPLORER ET DEFINIR TAILLE FENETRE

15 réponses
Avatar
29Eric29
Bonjour,

Je cherche à ouvrir 4 fenêtres "windows explorer" en imposant leur taille et position sur l'écran.

J'ai trouvé un code qui fonctionne parfaitement pour ouvrir "notepad.exe" (et positionner les fenêtres en définissant leur taille) et je cherche à l'adapter pour "explorer.exe".
https://www.experts-exchange.com/questions/28323487/MoveWindow-in-VBA-in-EXCEL.html


Je pensais que remplacer :
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
par :
np_retval = Shell("C:windowsexplorer.exe", vbNormalFocus)
suffirait....mais ça n'est pas si simple j'ai l'impression ?


Voici le code si quelqu'un avait une idée pour l'adapter à explorer.exe ?? :

Un grand merci d'avance...et bonne journée

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Option Explicit

Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long

Public Const GW_HWNDNEXT As Long = 2
Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwprocessid As Long) As Long

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Sub tile1()
Dim retval As Long, np_retval As Long

np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 0, 0, 950, 550, 1) ' Application.hwnd ' X Y largeur hauteur

np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 950, 0, 950, 550, 1) ' Application.hwnd ' X Y largeur hauteur

np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 950, 550, 950, 550, 1) ' Application.hwnd ' X Y largeur hauteur

np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 0, 550, 950, 550, 1) ' Application.hwnd ' X Y largeur hauteur

End Sub

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Function ProcIDFromWnd(ByVal hwnd As Long) As Long
Dim idProc As Long

' Get PID for this HWnd
GetWindowThreadProcessId hwnd, idProc
ProcIDFromWnd = idProc

End Function

Function GetWinHandle(hInstance As Long) As Long
Dim tempHwnd As Long

' Grab the first window handle that Windows finds:
tempHwnd = FindWindow(vbNullString, vbNullString)

' Loop until you find a match or there are no more window handles:
Do Until tempHwnd = 0
' Check if no parent for this window
If GetParent(tempHwnd) = 0 Then
' Check for PID match
If hInstance = ProcIDFromWnd(tempHwnd) Then
' Return found handle
GetWinHandle = tempHwnd
' Exit search loop
Exit Do
End If
End If

' Get the next window handle
tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT)
Loop
End Function
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

5 réponses

1 2
Avatar
29eric29
Le vendredi 22 Juin 2018 à 10:33 par 29Eric29 :
Bonjour,
Je cherche à ouvrir 4 fenêtres "windows explorer" en
imposant leur taille et position sur l'écran.
J'ai trouvé un code qui fonctionne parfaitement pour ouvrir
"notepad.exe" (et positionner les fenêtres en
définissant leur taille) et je cherche à l'adapter pour
"explorer.exe".
https://www.experts-exchange.com/questions/28323487/MoveWindow-in-VBA-in-EXCEL.html
Je pensais que remplacer :
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
par :
np_retval = Shell("C:windowsexplorer.exe", vbNormalFocus)
suffirait....mais ça n'est pas si simple j'ai l'impression ?
Voici le code si quelqu'un avait une idée pour l'adapter à
explorer.exe ?? :
Un grand merci d'avance...et bonne journée
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Option Explicit
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long,
ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long,
ByVal bRepaint As Long) As Long
Public Const GW_HWNDNEXT As Long = 2
Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long)
As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long,
ByVal wCmd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias
"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As
String) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal
hwnd As Long, lpdwprocessid As Long) As Long
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Sub tile1()
Dim retval As Long, np_retval As Long
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 0, 0, 950, 550, 1) '
Application.hwnd ' X Y largeur hauteur
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 950, 0, 950, 550, 1) '
Application.hwnd ' X Y largeur hauteur
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 950, 550, 950, 550, 1) '
Application.hwnd ' X Y largeur hauteur
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 0, 550, 950, 550, 1) '
Application.hwnd ' X Y largeur hauteur
End Sub
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Function ProcIDFromWnd(ByVal hwnd As Long) As Long
Dim idProc As Long
' Get PID for this HWnd
GetWindowThreadProcessId hwnd, idProc
ProcIDFromWnd = idProc
End Function
Function GetWinHandle(hInstance As Long) As Long
Dim tempHwnd As Long
' Grab the first window handle that Windows finds:
tempHwnd = FindWindow(vbNullString, vbNullString)
' Loop until you find a match or there are no more window handles:
Do Until tempHwnd = 0
' Check if no parent for this window
If GetParent(tempHwnd) = 0 Then
' Check for PID match
If hInstance = ProcIDFromWnd(tempHwnd) Then
' Return found handle
GetWinHandle = tempHwnd
' Exit search loop
Exit Do
End If
End If
' Get the next window handle
tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT)
Loop
End Function
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Nom d'un petit bonhomme !!!!
Ça marche....Je n'y crois pas.... J'ai tellement galéré !
Je vais analyser et voir pour intégrer tout ça dans mon code...
Un grand grand merci !
Bonne journée à tous
Eric
Avatar
29eric29
Le vendredi 22 Juin 2018 à 10:33 par 29Eric29 :
Bonjour,
Je cherche à ouvrir 4 fenêtres "windows explorer" en
imposant leur taille et position sur l'écran.
J'ai trouvé un code qui fonctionne parfaitement pour ouvrir
"notepad.exe" (et positionner les fenêtres en
définissant leur taille) et je cherche à l'adapter pour
"explorer.exe".
https://www.experts-exchange.com/questions/28323487/MoveWindow-in-VBA-in-EXCEL.html
Je pensais que remplacer :
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
par :
np_retval = Shell("C:windowsexplorer.exe", vbNormalFocus)
suffirait....mais ça n'est pas si simple j'ai l'impression ?
Voici le code si quelqu'un avait une idée pour l'adapter à
explorer.exe ?? :
Un grand merci d'avance...et bonne journée
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Option Explicit
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long,
ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long,
ByVal bRepaint As Long) As Long
Public Const GW_HWNDNEXT As Long = 2
Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long)
As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long,
ByVal wCmd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias
"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As
String) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal
hwnd As Long, lpdwprocessid As Long) As Long
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Sub tile1()
Dim retval As Long, np_retval As Long
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 0, 0, 950, 550, 1) '
Application.hwnd ' X Y largeur hauteur
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 950, 0, 950, 550, 1) '
Application.hwnd ' X Y largeur hauteur
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 950, 550, 950, 550, 1) '
Application.hwnd ' X Y largeur hauteur
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 0, 550, 950, 550, 1) '
Application.hwnd ' X Y largeur hauteur
End Sub
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Function ProcIDFromWnd(ByVal hwnd As Long) As Long
Dim idProc As Long
' Get PID for this HWnd
GetWindowThreadProcessId hwnd, idProc
ProcIDFromWnd = idProc
End Function
Function GetWinHandle(hInstance As Long) As Long
Dim tempHwnd As Long
' Grab the first window handle that Windows finds:
tempHwnd = FindWindow(vbNullString, vbNullString)
' Loop until you find a match or there are no more window handles:
Do Until tempHwnd = 0
' Check if no parent for this window
If GetParent(tempHwnd) = 0 Then
' Check for PID match
If hInstance = ProcIDFromWnd(tempHwnd) Then
' Return found handle
GetWinHandle = tempHwnd
' Exit search loop
Exit Do
End If
End If
' Get the next window handle
tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT)
Loop
End Function
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Deux points à ajuster:
(1) Ne fonctionne pas si des fenêtres "explorer" sont déjà ouvertes. Il faut donc trouver un moyen de toutes les fermer avant ?
(2) Sur l'un de mes PC les 4 fenêtres s'ouvrent et sont mises à la bonne taille mais "restent derrière excel"...donc restent cachées...
Je poursuis mes recherches...mais si quelqu'un a des suggestions je suis preneur !
Merci d'avance
Avatar
29eric29
Le vendredi 22 Juin 2018 à 10:33 par 29Eric29 :
Bonjour,
Je cherche à ouvrir 4 fenêtres "windows explorer" en
imposant leur taille et position sur l'écran.
J'ai trouvé un code qui fonctionne parfaitement pour ouvrir
"notepad.exe" (et positionner les fenêtres en
définissant leur taille) et je cherche à l'adapter pour
"explorer.exe".
https://www.experts-exchange.com/questions/28323487/MoveWindow-in-VBA-in-EXCEL.html
Je pensais que remplacer :
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
par :
np_retval = Shell("C:windowsexplorer.exe", vbNormalFocus)
suffirait....mais ça n'est pas si simple j'ai l'impression ?
Voici le code si quelqu'un avait une idée pour l'adapter à
explorer.exe ?? :
Un grand merci d'avance...et bonne journée
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Option Explicit
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long,
ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long,
ByVal bRepaint As Long) As Long
Public Const GW_HWNDNEXT As Long = 2
Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long)
As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long,
ByVal wCmd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias
"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As
String) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal
hwnd As Long, lpdwprocessid As Long) As Long
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Sub tile1()
Dim retval As Long, np_retval As Long
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 0, 0, 950, 550, 1) '
Application.hwnd ' X Y largeur hauteur
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 950, 0, 950, 550, 1) '
Application.hwnd ' X Y largeur hauteur
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 950, 550, 950, 550, 1) '
Application.hwnd ' X Y largeur hauteur
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 0, 550, 950, 550, 1) '
Application.hwnd ' X Y largeur hauteur
End Sub
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Function ProcIDFromWnd(ByVal hwnd As Long) As Long
Dim idProc As Long
' Get PID for this HWnd
GetWindowThreadProcessId hwnd, idProc
ProcIDFromWnd = idProc
End Function
Function GetWinHandle(hInstance As Long) As Long
Dim tempHwnd As Long
' Grab the first window handle that Windows finds:
tempHwnd = FindWindow(vbNullString, vbNullString)
' Loop until you find a match or there are no more window handles:
Do Until tempHwnd = 0
' Check if no parent for this window
If GetParent(tempHwnd) = 0 Then
' Check for PID match
If hInstance = ProcIDFromWnd(tempHwnd) Then
' Return found handle
GetWinHandle = tempHwnd
' Exit search loop
Exit Do
End If
End If
' Get the next window handle
tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT)
Loop
End Function
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
La première partie de mon problème est réglé. J'ai trouvé ce code (je ferme ainsi toutes les autres fenêtres "explorer.exe" :
Dim aProcess, theProcesses
Set theProcesses = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!." _
& "rootcimv2").ExecQuery _
("Select * from Win32_Process Where Name = 'explorer.exe'")
If theProcesses.Count > 0 Then
For Each aProcess In theProcesses
aProcess.Terminate
Next
End If
Il me reste à trouver comment éviter que les fenêtres restent "derrière" !
Courage...
Avatar
Michd
Bonjour,
Adapte la procédure de Michel_D comme ceci. Attention, certaines lignes peuvent être coupées par le
service de messagerie.
'Déclaration des API
Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, ByVal x As Long, _
ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
'---------------------------------------------------------
Sub Depart()
Dim oSHA As Object, oWnd As Object
Dim iK As Long, ndT As Double
' ouverture des 4 fenêtres de l'explorateur windows
For iK = 1 To 4
Shell "C:windowsSystem32explorer.exe", vbNormalFocus
Next
ndT = Timer + 1
Do While ndT >= Timer
DoEvents
Loop
iK = 0
asV = Split("0,0,950,550,950,0,950,550,950,550,950,550,0,550,950,550", ",")
Set oSHA = CreateObject("Shell.Application")
For Each oWnd In oSHA.Windows
If Left(TypeName(oWnd.Document), 12) = "IShellFolder" Then
MoveWindow oWnd.hWnd, CLng(asV(iK)), CLng(asV(iK + 1)), CLng(asV(iK + 2)), CLng(asV(iK + 3)),
1
SetForegroundWindow oWnd.hWnd
iK = iK + 4
End If
If iK > 15 Then Exit For ' 4 Fenêtres
Next
Set oWnd = Nothing
Set oSHA = Nothing
End Sub
'---------------------------------------------------------
MichD
"29eric29" a écrit dans le message de groupe de discussion :
Le vendredi 22 Juin 2018 à 10:33 par 29Eric29 :
Bonjour,
Je cherche à ouvrir 4 fenêtres "windows explorer" en
imposant leur taille et position sur l'écran.
J'ai trouvé un code qui fonctionne parfaitement pour ouvrir
"notepad.exe" (et positionner les fenêtres en
définissant leur taille) et je cherche à l'adapter pour
"explorer.exe".

https://www.experts-exchange.com/questions/28323487/MoveWindow-in-VBA-in-EXCEL.html
Je pensais que remplacer :
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
par :
np_retval = Shell("C:windowsexplorer.exe", vbNormalFocus)
suffirait....mais ça n'est pas si simple j'ai l'impression ?
Voici le code si quelqu'un avait une idée pour l'adapter à
explorer.exe ?? :
Un grand merci d'avance...et bonne journée
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Option Explicit
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long,
ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As

Long,
ByVal bRepaint As Long) As Long
Public Const GW_HWNDNEXT As Long = 2
Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long)
As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long,
ByVal wCmd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias
"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As
String) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal
hwnd As Long, lpdwprocessid As Long) As Long
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Sub tile1()
Dim retval As Long, np_retval As Long
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 0, 0, 950, 550, 1) '
Application.hwnd ' X Y largeur hauteur
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 950, 0, 950, 550, 1) '
Application.hwnd ' X Y largeur hauteur
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 950, 550, 950, 550, 1) '
Application.hwnd ' X Y largeur hauteur
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 0, 550, 950, 550, 1) '
Application.hwnd ' X Y largeur hauteur
End Sub
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Function ProcIDFromWnd(ByVal hwnd As Long) As Long
Dim idProc As Long
' Get PID for this HWnd
GetWindowThreadProcessId hwnd, idProc
ProcIDFromWnd = idProc
End Function
Function GetWinHandle(hInstance As Long) As Long
Dim tempHwnd As Long
' Grab the first window handle that Windows finds:
tempHwnd = FindWindow(vbNullString, vbNullString)
' Loop until you find a match or there are no more window handles:
Do Until tempHwnd = 0
' Check if no parent for this window
If GetParent(tempHwnd) = 0 Then
' Check for PID match
If hInstance = ProcIDFromWnd(tempHwnd) Then
' Return found handle
GetWinHandle = tempHwnd
' Exit search loop
Exit Do
End If
End If
' Get the next window handle
tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT)
Loop
End Function
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

La première partie de mon problème est réglé. J'ai trouvé ce code (je ferme
ainsi toutes les autres fenêtres "explorer.exe" :
Dim aProcess, theProcesses
Set theProcesses = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!." _
& "rootcimv2").ExecQuery _
("Select * from Win32_Process Where Name = 'explorer.exe'")
If theProcesses.Count > 0 Then
For Each aProcess In theProcesses
aProcess.Terminate
Next
End If
Il me reste à trouver comment éviter que les fenêtres restent "derrière" !
Courage...
Avatar
patricktoulon
Le vendredi 22 Juin 2018 à 10:33 par 29Eric29 :
Bonjour,
Je cherche à ouvrir 4 fenêtres "windows explorer" en
imposant leur taille et position sur l'écran.
J'ai trouvé un code qui fonctionne parfaitement pour ouvrir
"notepad.exe" (et positionner les fenêtres en
définissant leur taille) et je cherche à l'adapter pour
"explorer.exe".
https://www.experts-exchange.com/questions/28323487/MoveWindow-in-VBA-in-EXCEL.html
Je pensais que remplacer :
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
par :
np_retval = Shell("C:windowsexplorer.exe", vbNormalFocus)
suffirait....mais ça n'est pas si simple j'ai l'impression ?
Voici le code si quelqu'un avait une idée pour l'adapter à
explorer.exe ?? :
Un grand merci d'avance...et bonne journée
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Option Explicit
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long,
ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long,
ByVal bRepaint As Long) As Long
Public Const GW_HWNDNEXT As Long = 2
Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long)
As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long,
ByVal wCmd As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias
"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As
String) As Long
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal
hwnd As Long, lpdwprocessid As Long) As Long
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Sub tile1()
Dim retval As Long, np_retval As Long
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 0, 0, 950, 550, 1) '
Application.hwnd ' X Y largeur hauteur
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 950, 0, 950, 550, 1) '
Application.hwnd ' X Y largeur hauteur
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 950, 550, 950, 550, 1) '
Application.hwnd ' X Y largeur hauteur
np_retval = Shell("C:windowsnotepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 0, 550, 950, 550, 1) '
Application.hwnd ' X Y largeur hauteur
End Sub
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Function ProcIDFromWnd(ByVal hwnd As Long) As Long
Dim idProc As Long
' Get PID for this HWnd
GetWindowThreadProcessId hwnd, idProc
ProcIDFromWnd = idProc
End Function
Function GetWinHandle(hInstance As Long) As Long
Dim tempHwnd As Long
' Grab the first window handle that Windows finds:
tempHwnd = FindWindow(vbNullString, vbNullString)
' Loop until you find a match or there are no more window handles:
Do Until tempHwnd = 0
' Check if no parent for this window
If GetParent(tempHwnd) = 0 Then
' Check for PID match
If hInstance = ProcIDFromWnd(tempHwnd) Then
' Return found handle
GetWinHandle = tempHwnd
' Exit search loop
Exit Do
End If
End If
' Get the next window handle
tempHwnd = GetWindow(tempHwnd, GW_HWNDNEXT)
Loop
End Function
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
bonsoir
tout les chemins menent a rome le mien aussi
#If VBA7 Then
Declare Function ptrsafe MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Declare Function ptrsafe FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
#Else
Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
#End If
'0, 0, 950, 550, 1
'950, 0, 950, 550, 1
'950, 550, 950, 550, 1
' 0, 550, 950, 550, 1
Sub test2()
mesdossiers = Array("C:UserspoluxDesktopimageBouton", "C:UserspoluxDesktoplien streaming", "C:UserspoluxDesktopcature d'ecran api vba", "C:UserspoluxDesktopwisiwig fonctionnels")
mespositions = Array("0, 0, 950, 550, 1", "950, 0, 950, 550, 1", "950, 550, 950, 550, 1", "0, 550, 950, 550, 1")
Set objShell = CreateObject("shell.application")
For x = 0 To UBound(mesdossiers)
nbfenetre = CLng(objShell.Windows.Count)
retval = Shell("C:windowsSystem32explorer.exe " & Chr(32) & mesdossiers(x) & Chr(32), vbNormalFocus)
Do: DoEvents: Loop While objShell.Windows.Count = nbfenetre: pos = Split(mespositions(x), ",")
MoveWindow FindWindow(vbNullString, objShell.Windows(nbfenetre - 1).locationname), pos(0), pos(1), pos(2), pos(3), pos(4)
Next
End Sub
1 2