Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

COM Object Reference [AutoHotkey v1.1+]


  • Please log in to reply
233 replies to this topic
Learning one
  • Members
  • 1483 posts
  • Last active: Jan 02 2016 02:30 PM
  • Joined: 04 Apr 2009

i need your help to get selected items and their paths on desktop

F1::MsgBox % Explorer_GetSelection()	; example

Explorer_GetSelection(hwnd="") {
    WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
    WinGetClass class, ahk_id %hwnd%
    if (process = "explorer.exe")
        if (class ~= "Progman|WorkerW") {
            ControlGet, files, List, Selected Col1, SysListView321, ahk_class %class%
            Loop, Parse, files, `n, `r
                ToReturn .= A_Desktop "" A_LoopField "`n"
        } else if (class ~= "(Cabinet|Explore)WClass") {
            for window in ComObjCreate("Shell.Application").Windows
                if (window.hwnd==hwnd)
                    sel := window.Document.SelectedItems
            for item in sel
                ToReturn .= item.path "`n"
        }
    return Trim(ToReturn,"`n")
}


Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
jethrow,maul.esel
thanks for explaining vtable thing, guys!

Learning one
thanks, man!
this is exactly what i made to retrive selected items in explorer window, but the method for desktop (progman) items will not work properly in case user has enabled option "Hide extensions for known file types", because in this case files with same name can exist and gotten path will be invalid
Is there another way to get selections from desktop?
Btw, with your help, guys, i was able to finish code to the point where CreateViewObject method call required, but which interface's refiid should i use in this method?
DllCall("Shell32\SHGetDesktopFolder","Ptr*",pIShellFolder)
IShellView_refiid := GUID(IID_IShellView, "{000214E3-0000-0000-C000-000000000046}")

vt := NumGet(pIShellFolder + 0)
CreateViewObject := NumGet(vt + 8*A_PtrSize)
DllCall(CreateViewObject,"Ptr", pIShellFolder,"Ptr",0, "Ptr", IShellView_refiid, "Ptr*", pIShellView)

vt := NumGet(pIShellView + 0)
GetItemObject := NumGet(vt + 15*A_PtrSize)
DllCall(GetItemObject,"Ptr", pIShellView,"Uint",SVGIO_SELECTION := 1,"Uptr",[color=red]SomeInterface_refiid[/color],"Ptr*",[color=red]pSomeInterface[/color])
;which IID should i use in this method to get enumeration of selected items?

btw, here is another method to get IShellView pointer:
	;~ typedef struct {
  ;~ UINT               cbSize;			uint
  ;~ IShellFolder       *pshf;			ptr
  ;~ IShellView         *psvOuter;		ptr
  ;~ IShellFolderViewCB *psfvcb;		ptr
;~ } SFV_CREATE;	

VarSetCapacity(SFV_CREATE,4*A_PtrSize,0)
NumPut(4*A_PtrSize,SFV_CREATE,0,"Uint")
NumPut(pIShellFolder,SFV_CREATE,A_PtrSize,"Uptr")
DllCall("Shell32\SHCreateShellFolderView","Ptr",&SFV_CREATE,"Ptr*",pIShellView)


maul.esel
  • Members
  • 790 posts
  • Last active: Jan 05 2013 09:26 PM
  • Joined: 28 Feb 2011
Wanted to post you the link but I hadn't the time - thanks jethrow.

I do not KNOW the answer to your last question, but when searching google there seem to be a lot of people using IDataObject :)

In this thread, the author (of the 2nd post) points to IShellFolder::GetUIObjectOf(), and in the msdn article there's a list of interfaces supported by this function (including IDataObject).
Join the discussion on The future of AutoHotkey
Posted Image Visit me on github Posted Image
Win7 HP SP1 64bit | AHK_L U 64bit

Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
for some reason when i trying to use
vt := NumGet(pIShellView + 0)
GetItemObject := NumGet(vt + 15*A_PtrSize)
IDataObject_refiid := GUID(IID_IDataObject, "{0000010e-0000-0000-C000-000000000046}")
ret := DllCall(GetItemObject,"Ptr", pIShellView,"Uint",1,"Uptr",IDataObject_refiid,"Ptr*",pIDataObject)
it returns me "Unspecified error" (0x80004005)
and success if IDataObject_refiid = 0, seems he don't like this COM interface IID. I've tried few else with same result
any suggestions?

Deo
  • Members
  • 199 posts
  • Last active: Jan 31 2014 03:19 PM
  • Joined: 16 May 2010
i was able retrive IDataObject using this method
DllCall("shell32\SHParseDisplayName", "str",A_Desktop, "Ptr", 0, "Ptr*", pidl, "Uint", 0, "Uint*", 0)
DllCall("shell32\SHBindToParent", "Ptr", pidl, "Ptr", GUID(IID_IShellFolder,"{000214E6-0000-0000-C000-000000000046}"), "Ptr*", pIShellFolder, "Ptr*", pidlChild)
   ;IShellFolder->GetUIObjectOf
DllCall(VTable(pIShellFolder, 10), "Ptr", pIShellFolder, "Ptr", 0, "Uint", 1, "Ptr*", pidlChild, "Ptr", GUID(IID_IDataObject,"{0000010e-0000-0000-C000-000000000046}"), "Ptr", 0, "Ptr*", pIDataObject)
though it seems like this Object gets all items, not selected only, and i can't understand what to do next with this interface, lol...

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009

COM Object: Outlook.Application

Purpose: Personal Information Manager

System Requirements: MS Outlook (MS Office)

Documentation Link: Application Object[*:2cl6on5s]

Other Links: Session Property, Folders Collection, MAPIFolder Object, MailItem Object

Basic Code Example: This example will access the Outlook Folders, and then each item in the Drafts Folder, assuming Outlook is already open.

; Access the Session NameSpace
Session := ComObjActive("Outlook.Application").Session

; Access the Folders Collection
Folders := Session.Folders("Outlook Data File").Folders

; Loop through the MAPIFolders
Loop, % Folders.Count
   t .= Folders.item(A_Index).Name "`n"
MsgBox, %t%

; Loop through all the MailItems in the Drafts Folder
DraftItems := Folders.item("Drafts").Items
Loop, % DraftItems.Count {
   Item := DraftItems.item(A_Index)
   MsgBox, % "To:`t" Item.To
           . "`nSubject:`t" Item.Subject
           . "`nBody:`t" Item.Body
}


aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
I hope I am in the right place :) someone suggested I try my question here.

I've got a question which seems to involve javascript... I'd like to be able to detect when a YouTube video
is finished playing, so the channel changer can change to the next video.

I'm on AHK_L and the original question and info is HERE.

The YouTube player sends "0" when the video is done playing.... and all I can find out there for interacting with that is this javascript:
function onytplayerStateChange(newState)
I'm really hoping someone can shed some light on how this can be applied to AHK. I can see it in my head (sort of) with the information I've found:
function onytplayerStateChange(newState) {
if(newState == 0) {
*change the channel up to the next video*
}

Which leads me to dream up noob stuff like:
something call onStateChange(newState)
SomeVar := onStateChange(newState)
If SomeVar = (0 for video ended) ; if video has ended
{
   msgbox, video ended, this msgbox means detection was successful.
   GoSub, ChangeToAnotherChannelAndPlayAnotherVideo ; title = what it does lol
}
Thank you very much for any info you guys have on this...

JDK
  • Members
  • 8 posts
  • Last active: Oct 12 2011 08:15 AM
  • Joined: 07 Aug 2011
as title

aaronbewza
  • Members
  • 466 posts
  • Last active: Feb 05 2013 08:40 AM
  • Joined: 20 Feb 2011
Thank you, I've got someone who can understand what is required :) That's exciting for sure, it looks like it can all be done. I'm really impressed at the intelligence level of some of the people I've met at this forum. Why aren't you all rich??? :)

hughman
  • Members
  • 192 posts
  • Last active: Feb 14 2016 06:59 AM
  • Joined: 11 Feb 2007

xml.selectSingleNode


Why is getElementsByTagName not a valid method?
error: unknown name.
It can be applied in Javascript.

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
Of what Com Object/Interface?

rani
  • Members
  • 217 posts
  • Last active: Jul 21 2016 12:53 PM
  • Joined: 18 Mar 2008
I have a .dll SDK COM object , that with C# or VB it worked ok
in VB project I make instance as :

Public tTxtO As TxtSDKLib.TxtSDK
...

Set tTxtO = New TxtSDKLib.TxtSDK

and evrything work ok, I also see also the refrences of the .dll

in AHK_L I made :

tTxtO := ComObjCreate("TxtDKLib.TxtSDK")

and got AHK error :
Error ...1F3 Invalid class string

any idea how to make Object Instance with AHK_L ?

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
Have you tried:
tTxtO := ComObjCreate("Txt[color=red]S[/color]DKLib.TxtSDK")


rani
  • Members
  • 217 posts
  • Last active: Jul 21 2016 12:53 PM
  • Joined: 18 Mar 2008

Have you tried:

tTxtO := ComObjCreate("Txt[color=red]S[/color]DKLib.TxtSDK")

it's just semantic error in the post,

but ofcourse the class spelling is correct.

el

jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009
Can you get it to work in VBScript?