Skip to content

Commit

Permalink
stdWindow#ShellWindow
Browse files Browse the repository at this point in the history
Closes #22
  • Loading branch information
sancarn committed Jun 2, 2024
1 parent 2a94213 commit 0a344e2
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/stdWindow.cls
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,18 @@ Public Function CreateManyFromProcessId(ByVal processID As Long) As Collection
Set CreateManyFromProcessId = ret
End Function

'Create window objects for all shell windows
'@constructor
'@returns Collection<stdWindow> - Collection of shell windows
Public Function CreateManyFromShellWindows() as Collection
set CreateManyFromShellWindows = new Collection
Dim shell: set shell = CreateObject("Shell.Application")
Dim win as object
For each win in shell.windows
CreateManyFromShellWindows.add CreateFromHwnd(win.hwnd)
next
End Function

'Converts a stdWindow object to a stdAcc object
'@constructor
'@returns Object<stdAcc>|stdAcc - stdAcc object representing the window
Expand Down Expand Up @@ -1529,6 +1541,21 @@ Public Property Let Opacity(ByVal v As Byte)
Call SetLayeredWindowAttributes(This.Handle, This.LayeredWindowInfo.crKey, This.LayeredWindowInfo.bAlpha, newFlags)
End Property

'Gets the Shell Window COM object for this window if it exists
'@returns Object<Shell.IWebBrowser2|Nothing> - Shell Window COM object
'@example ```
' Dim location as string: location = stdWindow.CreateFromHwnd(hwnd).ShellWindow.LocationURL
'```
'@TODO: is there a better way?
Public Property Get ShellWindow() as Object
if Class = "CabinetWClass" then
With stdWindow.protGetShellWindowCache(This.Handle)
if .exists(CStr(This.Handle)) then
set ShellWindow = .item(CStr(This.Handle))
end if
end with
end if
End Property

'================================================================================================
'= PUBLIC INSTANCE METHODS
Expand Down Expand Up @@ -2098,7 +2125,31 @@ End Function
'= PROTECTED METHODS
'================================================================================================

'Obtain a shell window cache
'@protected
'@param hwnd - Handle of the window to test for in the cache. If this window is not in the cache, the cache will be updated.
'@returns - Shell window cache
#if VBA7 then
Friend Function protGetShellWindowCache(ByVal hwnd as LongPtr) as object
#else
Friend Function protGetShellWindowCache(ByVal hwnd as Long) as object
#end if
Static cache As Object: If cache Is Nothing Then Set cache = CreateObject("Scripting.Dictionary")
If Not cache.Exists(CStr(hwnd)) Then
Static shell As Object: If shell Is Nothing Then Set shell = CreateObject("Shell.Application")

Dim win
For Each win In shell.windows
If Not cache.Exists(CStr(win.hwnd)) Then
cache.Add CStr(win.hwnd), win
End If
Next
End If
Set protGetShellWindowCache = cache
End Function

'Obtain the next window given a stack
'@protected
'@param stack - Stack of windows
'@param DFS - Whether to use Depth First Search or not
'@param Prev - Previous window
Expand Down Expand Up @@ -2127,6 +2178,7 @@ Friend Function protGetNextDescendent(ByVal stack As collection, ByVal DFS As Bo
End Function

'Returns the lookups object
'@protected
'@returns Object<Dictionary<Dictionary<Dictionary<string|long>>>> - Lookups object
Friend Function protGetLookups() as Object
If This.Lookups Is Nothing Then
Expand Down

0 comments on commit 0a344e2

Please sign in to comment.