 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Sean
Joined: 12 Feb 2007 Posts: 1281
|
Posted: Mon Jul 02, 2007 6:27 am Post subject: Explorer Windows Manipulations |
|
|
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.
| Code: | #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
}
}
|
Last edited by Sean on Tue Feb 05, 2008 1:04 am; edited 9 times in total |
|
| Back to top |
|
 |
ABCYourWay Guest
|
Posted: Mon Jul 02, 2007 6:52 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1281
|
Posted: Mon Jul 02, 2007 9:46 am Post subject: |
|
|
| ABCYourWay wrote: | | 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.)
| Code: | #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
|
Last edited by Sean on Thu Jul 19, 2007 3:08 am; edited 2 times in total |
|
| Back to top |
|
 |
Guest
|
Posted: Tue Jul 17, 2007 8:51 am Post subject: |
|
|
| Sean wrote: | | ABCYourWay wrote: | | 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);
} |
|
| Back to top |
|
 |
Guest
|
Posted: Tue Jul 17, 2007 9:12 am Post subject: |
|
|
I was able to do it Like thi. Add this to your script:
| Code: |
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 |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1281
|
Posted: Tue Jul 17, 2007 10:36 am Post subject: |
|
|
I updated the script to accord with the recent changes in CoHelper.ahk.
And, I used the GUI, so you need IEControl.ahk too. |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Tue Jul 17, 2007 3:43 pm Post subject: |
|
|
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). _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1281
|
Posted: Wed Jul 18, 2007 12:13 am Post subject: |
|
|
| PhiLho wrote: | | 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:
http://blogs.msdn.com/oldnewthing/archive/2004/07/20/188696.aspx
| Quote: | | 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. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1281
|
Posted: Wed Jul 18, 2007 9:41 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Wed Jul 18, 2007 3:22 pm Post subject: |
|
|
| Sean wrote: | 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!  _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
tfcahm
Joined: 20 May 2007 Posts: 48
|
Posted: Sun Jul 22, 2007 4:25 pm Post subject: |
|
|
| Sean wrote: | 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. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1281
|
Posted: Sun Jul 22, 2007 5:59 pm Post subject: |
|
|
| tfcahm wrote: | | 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.
| Quote: | | 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. |
|
| Back to top |
|
 |
tfcahm
Joined: 20 May 2007 Posts: 48
|
Posted: Sun Jul 22, 2007 7:47 pm Post subject: |
|
|
Thanks Sean. The revised script works great.
| Sean wrote: | 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.
| Sean wrote: | | 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. |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2391
|
Posted: Sun Jul 22, 2007 8:51 pm Post subject: |
|
|
| tfcahm wrote: | | My version is 6.00.2900.3051. No need to troubleshoot it...just curious. | Same version here (XP Pro SP2). |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 1281
|
Posted: Mon Jul 23, 2007 3:30 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|