Hello
I'm trying to open 4 windows of "explorer.exe" (windows explorer) application and I would like to define their position and size.
I found some code which works perfectly with notepad !
I've tried to modify it ...to make it work with "explorer.exe"
I've replaced :
np_retval = Shell("C:\windows\notepad.exe", vbNormalFocus)
by :
np_retval = Shell("C:\windows\explorer.exe", vbNormalFocus)
But it's not as simple !! (I'm not an expert at all..sorry)
Here is the code for notepad.exe. If anyone can help me to adapt it for "explorer.exe" (for w7 & w10) ??
Thanks a lot !!!
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
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:\windows\notepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 0, 0, 950, 550, 1) ' Application.hwnd ' X Y largeur hauteur
np_retval = Shell("C:\windows\notepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 950, 0, 950, 550, 1) ' Application.hwnd ' X Y largeur hauteur
np_retval = Shell("C:\windows\notepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 950, 550, 950, 550, 1) ' Application.hwnd ' X Y largeur hauteur
np_retval = Shell("C:\windows\notepad.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
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
I'm trying to open 4 windows of "explorer.exe" (windows explorer) application and I would like to define their position and size.
I found some code which works perfectly with notepad !
I've tried to modify it ...to make it work with "explorer.exe"
I've replaced :
np_retval = Shell("C:\windows\notepad.exe", vbNormalFocus)
by :
np_retval = Shell("C:\windows\explorer.exe", vbNormalFocus)
But it's not as simple !! (I'm not an expert at all..sorry)
Here is the code for notepad.exe. If anyone can help me to adapt it for "explorer.exe" (for w7 & w10) ??
Thanks a lot !!!
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
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:\windows\notepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 0, 0, 950, 550, 1) ' Application.hwnd ' X Y largeur hauteur
np_retval = Shell("C:\windows\notepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 950, 0, 950, 550, 1) ' Application.hwnd ' X Y largeur hauteur
np_retval = Shell("C:\windows\notepad.exe", vbNormalFocus)
retval = MoveWindow(GetWinHandle(np_retval), 950, 550, 950, 550, 1) ' Application.hwnd ' X Y largeur hauteur
np_retval = Shell("C:\windows\notepad.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
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@