I need to open a file explorer window at a given folder. Currently I do this by using
Code: Select all
RunProgram("file://c:\git\")
Any idea how to position the opened file explorer window?
Kukulkan
Code: Select all
RunProgram("file://c:\git\")
Code: Select all
EnableExplicit
Define.MODULEENTRY32 Entry
Define.i handle, res, PID, hWnd
Define *Buffer
Define rect.RECT
Define.i w, h
*Buffer = AllocateMemory(256)
Entry\dwSize = SizeOf(MODULEENTRY32)
RunProgram("file://c:\windows\")
Repeat
hWnd = GetForegroundWindow_()
If hWnd
GetWindowThreadProcessId_(hWnd, @PID)
GetWindowText_(hWnd, *Buffer, 255)
handle = CreateToolhelp32Snapshot_(#TH32CS_SNAPMODULE, PID)
If handle
res = Module32First_(handle, Entry)
If res
EndIf
CloseHandle_(handle)
EndIf
EndIf
Until LCase(PeekS(@Entry\szModule,-1)) = "explorer.exe"
If GetWindowRect_(hWnd, @rect)
w = rect\right - rect\left
h = rect\bottom - rect\top
EndIf
SetWindowPos_(hWnd, #Null, 0, 0, w, h, #Null)
End
Code: Select all
RunProgram("file://c:\windows\")
Repeat
If OSVersion() > #PB_OS_Windows_Server_2003
hwnd = FindWindow_(0,"c:\windows")
Else
hwnd = FindWindow_(0,"WINDOWS")
EndIf
Until hWnd
GetWindowRect_(hWnd,r.RECT)
MoveWindow_(hWnd,50,50,r\right-r\left,r\bottom-r\top,1)
Well, you can change it to whatever you wish, in addition of having window title which can make a bit more sure you choose the right window...Danilo wrote:RASHAD's code works also with Directory Opus for me (Win8.1).
The code by bbanelli loops here without time-out because it opens an Opus window and waits for "explorer.exe".
Code: Select all
RunProgram("file://c:\windows\")
Repeat
If OSVersion() > #PB_OS_Windows_Server_2003
hwnd = FindWindow_(0,"WINDOWS")
Else
hwnd = FindWindow_(0,"c:\windows")
EndIf
Until hWnd
GetWindowRect_(hWnd,r.RECT)
MoveWindow_(hWnd,550,50,r\right-r\left,r\bottom-r\top,1)
Try thisKukulkan wrote:Hello,
I agree with Danilo that both codes are not complete. It works somehow, but users customization may break it. Adding some timeout is not a big deal, but in such case the goal is not reached
Are there any other ideas for a working way? For example, I'm ok if the Windows file explorer opens up even if some other product is installed (eg Directory Opus etc). Can I invoke a file explorer window by using some Windows API? And would this give me full control (eg returning the window handle)?
Kukulkan
Code: Select all
RunProgram("explorer.exe", "/n,/root,c:\windows", "")
Code: Select all
; Folder to open explorer in
; does not work with drive only (like "c:" or "f:")
Folder.s = "c:\windows"
FolderName.s = ""
c.s = ""
x.i = Len(Folder.s)
Repeat
c.s = Mid(Folder.s, x.i, 1)
If c.s <> "/" And c.s <> "\"
FolderName.s = c.s + FolderName.s
Else
Break
EndIf
x.i = x.i - 1
Until x.i < 1
StartTime = ElapsedMilliseconds()
RunProgram("explorer.exe", "/n,/root,"+Folder.s, "")
Repeat
hwnd = FindWindow_(0, Folder.s)
If hwnd = 0
; try FolderName if Windows explorer does not show full path in header
hwnd = FindWindow_(0, FolderName.s)
EndIf
Until hWnd <> 0 Or ElapsedMilliseconds() > (StartTime.i + 5000)
GetWindowRect_(hWnd,r.RECT)
MoveWindow_(hWnd,550,50,r\right-r\left,r\bottom-r\top,1)
End
Code: Select all
RunProgram("file://c:\windows\")
hwnd = FindWindow_(0,"c:\windows")
If Not hWnd
hwnd = FindWindow_(0,"WINDOWS")
EndIf
GetWindowRect_(hWnd,r.RECT)
MoveWindow_(hWnd,550,50,r\right-r\left,r\bottom-r\top,1)
This does not work because of 2 reasons:That's the way that it is impossible?
Code: Select all
RunProgram("file://c:\windows\")
hwnd = FindWindowEx_(0,0,0,0)
While text$ <> "Windows" Or text$ <> "C:\Windows"
text$ = Space(512)
GetWindowText_(hwnd,@text$,512)
If text$ = "Windows" Or text$ = "C:\Windows"
Debug text$
GetWindowRect_(hWnd,r.RECT)
MoveWindow_(hWnd,550,50,r\right-r\left,r\bottom-r\top,1)
Break
EndIf
hwnd = FindWindowEx_(0,hwnd,0,0)
Wend