RunProgram and Windows Explorer

Just starting out? Need help? Post your questions and find answers here.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

RunProgram and Windows Explorer

Post by davido »

Is there a way of using RunProgram to open some Explorer Windows and specifying their position and dimensions on the screen?
DE AA EB
User avatar
skywalk
Addict
Addict
Posts: 3994
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: RunProgram and Windows Explorer

Post by skywalk »

Here is what I use for 3 file explorers of different paths.

Code: Select all

; COMPILER OPTIONS:
;   [ ] Use Compiler:     PureBasic 5.70 LTS (Windows-x64)
;   [ ] Use Icon:         
;   [ ] Enable inline ASM syntax coloring
;   [ ] Create threadsafe executable
;   [ ] Enable OnError lines support
;   [x] Enable modern theme support (for Windows XP and above)
;   [ ] Request Administrator mode for Windows Vista and above
;   [ ] Request User mode for Windows Vista and above (no virtualization)
;   [x] Enable DPI aware executable (Windows)
;   Library Subsystem:    
;   Executable Format:    Windows  ;|Console|Shared DLL
;   CPU:                  All      ;|Dynamic|w/MMX|w/3DNOW|w/SSE|w/SSE2
;   Linker options file:  
;   File Format:          UTF-8
;   Version Info:         auto set fields --> %yy.%mm.%dd
; COMPILE/RUN:
;   [x] Create temporary executable in the source directory
; RESOURCES:
;   None
EnableExplicit
Define.i i, ri, hW, hW2, hW3, nDesktops
Define r.RECT
Define$ Dir1$, Dir2$, Dir3$
Dir1$ = "C:\dev"    ; Windows 10 messes with "C:\". Drop trailing "\" for window to be found.
Dir2$ = "C:\dev\Favorites"
Dir3$ = "C:\dev-try"
;RunProgram("Explorer.exe", "/n,/root," + Dir1$, #Empty$) ;FYI; Windows 10 forces new window when navigating folders.
;///////////////////////////////////////////////////////////////////////////////////////////
RunProgram("Explorer.exe", Dir1$, #Empty$)
Delay(30)
Repeat
  hW = FindWindow_(0, Dir1$)
Until hW
; l   t   r     b
; 55  0   964   1087
; 950 0   1927  1087
ri = MoveWindow_(hW,50,0,928,1050,1)
;///////////////////////////////////////////////////////////////////////////////////////////
RunProgram("Explorer.exe", Dir2$, #Empty$)
Delay(30)
Repeat
  hW2 = FindWindow_(0,Dir2$)
Until hW2
ri = GetWindowRect_(hW,r.RECT)
Delay(30)
ri = MoveWindow_(hW2,r\right+10,r\top,r\right-r\left+10,r\bottom-r\top, #SWP_SHOWWINDOW)
;///////////////////////////////////////////////////////////////////////////////////////////
nDesktops = ExamineDesktops() - 1
For i = 0 To nDesktops
  Dir1$ = DesktopName(i)
  If FindString(Dir1$, "1")
    nDesktops = i
    RunProgram("Explorer.exe", Dir3$, #Empty$)
    Delay(30)
    Repeat
      hW3 = FindWindow_(0,Dir3$)
    Until hW3
    Delay(30)
    ;BUG; DesktopWidth(), DesktopHeight() <> DPI values?
    ri = MoveWindow_(hW3, DesktopX(nDesktops)+DesktopWidth(nDesktops)/2-1080, DesktopY(nDesktops), 1080, 750, #SWP_SHOWWINDOW)
    ri = SetForegroundWindow_(hW)
    Break
  EndIf
Next i
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: RunProgram and Windows Explorer

Post by davido »

@skywalk,
Just tested your code. Works perfectly. :D
I could not have done this without your help.

Thank you very much, indeed.
DE AA EB
Post Reply