AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Explorer Windows Manipulations
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Sean



Joined: 12 Feb 2007
Posts: 1281

PostPosted: Mon Jul 02, 2007 6:27 am    Post subject: Explorer Windows Manipulations Reply with quote

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
View user's profile Send private message
ABCYourWay
Guest





PostPosted: Mon Jul 02, 2007 6:52 am    Post subject: Reply with quote

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

PostPosted: Mon Jul 02, 2007 9:46 am    Post subject: Reply with quote

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
View user's profile Send private message
Guest






PostPosted: Tue Jul 17, 2007 8:51 am    Post subject: Reply with quote

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






PostPosted: Tue Jul 17, 2007 9:12 am    Post subject: Reply with quote

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

PostPosted: Tue Jul 17, 2007 10:36 am    Post subject: Reply with quote

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
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Tue Jul 17, 2007 3:43 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Sean



Joined: 12 Feb 2007
Posts: 1281

PostPosted: Wed Jul 18, 2007 12:13 am    Post subject: Reply with quote

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. Wink
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
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1281

PostPosted: Wed Jul 18, 2007 9:41 am    Post subject: Reply with quote

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
View user's profile Send private message
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Wed Jul 18, 2007 3:22 pm    Post subject: Reply with quote

Sean wrote:
But, I'm not sure if you really want to see it. Wink
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! Very Happy
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
tfcahm



Joined: 20 May 2007
Posts: 48

PostPosted: Sun Jul 22, 2007 4:25 pm    Post subject: Reply with quote

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
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1281

PostPosted: Sun Jul 22, 2007 5:59 pm    Post subject: Reply with quote

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
View user's profile Send private message
tfcahm



Joined: 20 May 2007
Posts: 48

PostPosted: Sun Jul 22, 2007 7:47 pm    Post subject: Reply with quote

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
View user's profile Send private message
corrupt



Joined: 29 Dec 2004
Posts: 2391

PostPosted: Sun Jul 22, 2007 8:51 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Sean



Joined: 12 Feb 2007
Posts: 1281

PostPosted: Mon Jul 23, 2007 3:30 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group