Jump to content


Photo

Explorer Windows Manipulations


  • Please log in to reply
99 replies to this topic

#1 Sean

Sean
  • Members
  • 2462 posts

Posted 02 July 2007 - 05:27 AM

This script will navigate to a specified directory in one of already running explorer windows if exist, otherwise, then trigger new one and navigate in it.

REQUIRE that explorer.exe is running as a shell.

NEED COM Standard Library.

#f::MsgBox, % ShellFolder()
#m::ShellNavigate(A_MyDocuments, True)
#p::ShellNavigate(A_ProgramFiles)
#s::ShellNavigate(A_ScriptDir)
#w::ShellNavigate(A_WinDir)


ShellNavigate(sPath, bExplore=False, hWnd=0)
{
	COM_Init()
	psh  :=	COM_CreateObject("Shell.Application")
	If	hWnd||(hWnd:=WinExist("ahk_class CabinetWClass"))||(hWnd:=WinExist("ahk_class ExploreWClass"))
	{
		psw  :=	COM_Invoke(psh, "Windows")
		Loop, %	COM_Invoke(psw, "Count")
			If	COM_Invoke(pwb:=COM_Invoke(psw, "Item", A_Index-1), "hWnd") <> hWnd
				COM_Release(pwb)
			Else	Break
		COM_Invoke(pwb, "Navigate2", sPath)
		COM_Release(pwb)
		COM_Release(psw)
	}
	Else	COM_Invoke(psh, bExplore ? "Explore" : "Open", sPath)
	COM_Release(psh)
	COM_Term()
}

ShellFolder(hWnd=0)
{
	If	hWnd||(hWnd:=WinExist("ahk_class CabinetWClass"))||(hWnd:=WinExist("ahk_class ExploreWClass"))
	{
		COM_Init()
		psh  :=	COM_CreateObject("Shell.Application")
		psw  :=	COM_Invoke(psh, "Windows")
		Loop, %	COM_Invoke(psw, "Count")
			If	COM_Invoke(pwb:=COM_Invoke(psw, "Item", A_Index-1), "hWnd") <> hWnd
				COM_Release(pwb)
			Else	Break
		pfv  :=	COM_Invoke(pwb, "Document")
		sFolder	:= COM_Invoke(pfi:=COM_Invoke(psf:=COM_Invoke(pfv, "Folder"), "Self"), "Path"), COM_Release(psf), COM_Release(pfi), pfi:=0
		sFocus	:= COM_Invoke(pfi:=COM_Invoke(pfv, "FocusedItem"), "Name"), COM_Release(pfi), pfi:=0
		Loop, %	COM_Invoke(psi:=COM_Invoke(pfv, "SelectedItems"), "Count")
			sSelect	.= COM_Invoke(pfi:=COM_Invoke(psi, "Item", A_Index-1), "Name") . "`n", COM_Release(pfi), pfi:=0
		COM_Release(psi)
		COM_Release(pfv)
		COM_Release(pwb)
		COM_Release(psw)
		COM_Release(psh)
		COM_Term()
		Return	"Folder:`t" . sFolder . "`nFocus:`t" . sFocus . "`n<Selected Items>`n" . sSelect
	}
}


#2 ABCYourWay

ABCYourWay
  • Guests

Posted 02 July 2007 - 05:52 AM

To Sean

About running windows media Player, is it possible to GetCurrentPosition and SetCurrentPosition(miliseconds)?

I know there are some automation script for Wmplayer
but I think Get/Set Position methods are avaiable only via COM.

Thanks.

#3 Sean

Sean
  • Members
  • 2462 posts

Posted 02 July 2007 - 08:46 AM

About running windows media Player, is it possible to GetCurrentPosition and SetCurrentPosition(miliseconds)?

I've never tried to automate WMP as I seldom use it.
But, looks like it's possible. A test:
(You may have to copy CoHelper.ahk again for it to work properly.)

#Include IEControl.ahk

sUrl := "C:\WINDOWS\clock.avi" ; Replace it with your media file.

GoSub, GuiStart
Gui, +Resize +LastFound
Gui, Show, w800 h600 Center, WMP
hGui := WinExist()

pwmp := CreateObject("WMPlayer.OCX")
AtlAxAttachControl(pwmp, hGui)

Invoke(pwmp, "URL=", sUrl)
Invoke(pwmp, "Play")

Sleep, 1000
pmda := Invoke(pwmp, "CurrentMedia")
name := Invoke(pmda, "Name")
duration := Invoke(pmda, "durationString")

Sleep, 2000
pctl := Invoke(pwmp, "controls")
Position := Invoke(pctl, "currentPosition")
Invoke(pctl, "currentPosition=", Position+6)
Return

GuiStart:
CoInitialize()
AtlAxWinInit()
Return
GuiClose:
Gui, Destroy
Release(pctl)
Release(pmda)
Release(pwmp)
AtlAxWinTerm()
CoUninitialize()
ExitApp


#4 Guests

  • Guests

Posted 17 July 2007 - 07:51 AM

About running windows media Player, is it possible to GetCurrentPosition and SetCurrentPosition(miliseconds)?

I've never tried to automate WMP as I seldom use it.
But, looks like it's possible. A test:
(You may have to copy CoHelper.ahk again for it to work properly.)



How would you get a duration of the song though? I have a C# function but I'm having trouble converting it to AHK,. Could you please help?

public static void GetDuration()
{
WindowsMediaPlayer m = new WindowsMediaPlayer();
m.URL = @"my.wma";
m.controls.play();
System.Threading.Thread.Sleep(1000);//delay time
string name = m.currentMedia.name;
string duration = m.currentMedia.durationString;
Console.WriteLine("File Name: " + name);
Console.WriteLine("Duration: {0}", duration);
}

#5 Guests

  • Guests

Posted 17 July 2007 - 08:12 AM

I was able to do it Like thi. Add this to your script:


pmda := Invoke(pwmp, "currentMedia")

GetCurrentDuration(pmda)
{
   DllCall("RtlMoveMemory", "doubleP", rDuration, "int64P", Invoke(pmda, "duration"), "Uint", 8)
   Return   rDuration
}


I still get Exception Processing Message 0x0000007b parameters 0x760E023C 0x760E023C 0x760E023C 0x760E023C when I do

Invoke(pwmp, "URL=", sUrl)

and Using your OpenURL doesn't work at all

#6 Sean

Sean
  • Members
  • 2462 posts

Posted 17 July 2007 - 09:36 AM

I updated the script to accord with the recent changes in CoHelper.ahk.
And, I used the GUI, so you need IEControl.ahk too.

#7 PhiLho

PhiLho
  • Fellows
  • 6850 posts

Posted 17 July 2007 - 02:43 PM

Sean, can this, or something else, can be used to get in a simple and reliable way the current directory of an Explorer window?
Currently I get the path from the address bar, which might not work in some configurations, and won't work in the Open/Save dialogs (which are Explorer based, I think).

#8 Sean

Sean
  • Members
  • 2462 posts

Posted 17 July 2007 - 11:13 PM

Sean, can this, or something else, can be used to get in a simple and reliable way the current directory of an Explorer window?

Yes, it's possible, even to get the focused/selected item(s).
But, I'm not sure if you really want to see it. ;)
Here is how it would look like:
<!-- m -->http://blogs.msdn.co... ... 88696.aspx<!-- m -->

won't work in the Open/Save dialogs (which are Explorer based, I think).

I already discussed about it once with majkinetor through PM a while ago.
To make it short, AFAIK, there is no known COM method similar to Explorer windows cases unless they are AHK's own ones.
However, there is another way to get it, but can't be used with AHK currently.

#9 Sean

Sean
  • Members
  • 2462 posts

Posted 18 July 2007 - 08:41 AM

I updated the script to include ShellFolder() function, which shows the folder path, the focused item name, and the full paths of the selected items in alphabetical order.
Be sure to have the latest CoHelper.ahk.

#10 PhiLho

PhiLho
  • Fellows
  • 6850 posts

Posted 18 July 2007 - 02:22 PM

But, I'm not sure if you really want to see it. ;)

Hum, you are right, it might be on the reliable side (more than using some undocumented API as I did once) but certainly not on the simple side! :D

#11 tfcahm

tfcahm
  • Members
  • 48 posts

Posted 22 July 2007 - 03:25 PM

I updated the script to include ShellFolder() function, which shows the folder path, the focused item name, and the full paths of the selected items in alphabetical order.
Be sure to have the latest CoHelper.ahk.

Something is not quite right with the ShellFolder() function. I think the CreateObject call is a typo and should be ActiveXObject instead. With that changed, sSelect returns the proper results, but sFolder, and sFocus both return blank, apparently because ppf and psf respectively are returned as zero. I tried a few things, but my knowledge in this area is too weak so your help is needed. Thanks.

#12 Sean

Sean
  • Members
  • 2462 posts

Posted 22 July 2007 - 04:59 PM

Something is not quite right with the ShellFolder() function. I think the CreateObject call is a typo and should be ActiveXObject instead.

Another discrepancy between the new and old CoHelper.ahk. But, I thought I changed CreateObject to ActiveXObject when posted...
Anyway, it's really becoming annoying for me to post my relatively recent COM scripts which have been based on the new CoHelper.ahk.

With that changed, sSelect returns the proper results, but sFolder, and sFocus both return blank, apparently because ppf and psf respectively are returned as zero.

What OS are you using? I used the latest available interfaces on my XPSP2 with all the latest hotfixes are applied. But, those interfaces may not available in earlier Windows versions. I downgraded those to the least required ones, so, please try again.

#13 tfcahm

tfcahm
  • Members
  • 48 posts

Posted 22 July 2007 - 06:47 PM

Thanks Sean. The revised script works great.

Another discrepancy between the new and old CoHelper.ahk. But, I thought I changed CreateObject to ActiveXObject when posted...
Anyway, it's really becoming annoying for me to post my relatively recent COM scripts which have been based on the new CoHelper.ahk.

Hey, these are great scripts. Didn't mean to be an annoyance. No problem with doing the rework here on the older ones to match with the new CoHelper. It's quite instructive.

What OS are you using? I used the latest available interfaces on my XPSP2 with all the latest hotfixes are applied. But, those interfaces may not available in earlier Windows versions. I downgraded those to the least required ones, so, please try again.

I'm using XPSP2 and thought I was pretty current with the latest updates. Obviously something is not there. Is the difference in Shell32.dll? My version is 6.00.2900.3051. No need to troubleshoot it...just curious.

#14 corrupt

corrupt
  • Members
  • 2558 posts

Posted 22 July 2007 - 07:51 PM

My version is 6.00.2900.3051. No need to troubleshoot it...just curious.

Same version here (XP Pro SP2).

#15 Sean

Sean
  • Members
  • 2462 posts

Posted 23 July 2007 - 02:30 AM

Mine is the same too.
As a matter of fact, those latest interfaces should be supported for XP too, even for W2K with some SP installed.
One thing which might affect is: what version of IE installed?
IE7 is installed on my machine.