WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: bobj on March 25, 2014, 12:51:22 PM

Title: Opening folders with RunShell
Post by: bobj on March 25, 2014, 12:51:22 PM
I have developed a program which displays a list of directory names and gives the user the option of double-clicking the display line to open a given folder. I've been using RunShell to start a copy of explorer.exe and provide the full path for the directory to be opened. That works fine, but I'd like to avoid opening multiple copies of explorer.exe, and I'd also prefer that any new folder selected would open in the original explorer window that was open. Any ideas on how to accomplish that?
Title: Re: Opening folders with RunShell
Post by: Deana on March 25, 2014, 01:33:46 PM
IntControl 31 can be used to return a tab-delimited list of Window ID's for all open Windows Explorer windows. Here is my undebugged attempt:

Code (winbatch) Select
directory = 'C:\temp' ; or ShortcutDir("personal")
if WinVersion(5) >= "2-6-0"
   winclass = "CabinetWClass"
   classcode = 1
else
   winclass = "ExploreWClass"
   classcode = 0
endif
a = IntControl( 31, classcode, 0, 0, 0 )  ;return list of ids of explorer windows
c = ItemCount( a, @TAB )
If c == 0
ShellExecute( 'explorer.exe',  '/separate,/e,':directory,  directory, @Normal ,   '' )
while FindWindow( winclass ) == ""    ;wait for it to come up
   TimeDelay( 0.1 )
endwhile
Else ;c >= 1
   d = 1
   while c < 1 && d < 500
      TimeDelay( 0.1 )
      a = IntControl( 31, classcode, 0, 0, 0 )
      c = ItemCount( a, @TAB )
      d = d + 1
   endwhile
   id1 = ItemExtract( 1, a, @TAB)
   WinActivate( id1 )   
   SendKeysTo( id1, "!d" )
   SendKeysTo( id1, directory )
   SendKeysTo( id1, "{enter}" )
Endif


Title: Re: Opening folders with RunShell
Post by: bobj on March 25, 2014, 01:59:00 PM
Thank you! I see what you're trying to do and I should be able to integrate that into the rest of my app. I'll give it a shot and see how it looks.