MyTetra Share
Делитесь знаниями!
Получение списка открытых окон
Время создания: 10.02.2021 20:25
Текстовые метки: VBA, окна, Window
Раздел: !Закладки - VBA
Запись: xintrea/mytetra_db_adgaver_new/master/base/1612977946y84zwkw68g/text.html на raw.githubusercontent.com

Option Explicit

 

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal _

                        lpClassName As String, ByVal lpWindowName As String) As Long

Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long

Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long

 

Public Const GW_HWNDFIRST = 0

Public Const GW_HWNDNEXT = 2

 

Sub GetTaskList()

    Dim lw As Long, s As String, CurrWnd As Long

    CurrWnd = GetWindow(Application.hwnd, GW_HWNDFIRST)

    Do While CurrWnd <> 0

        lw = GetWindowTextLength(CurrWnd)

        s = Space(lw + 1)

        lw = GetWindowText(CurrWnd, s, lw + 1)

        If lw > 0 Then

            Debug.Print Trim(s)

        End If

        CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)

        DoEvents

    Loop

End Sub






Sub PerebratIE()

Dim IE As SHDocVw.InternetExplorer, URL$

URL$ = "*.ru*" '

Set IE = GetRunningIE(URL$)

If IE Is Nothing Then

MsgBox "Вкладка не найдена"

Else

MsgBox IE.Document.DocumentElement.outerHTML, vbInformation, "Исходный код страницы"

End If

End Sub


Function GetRunningIE(ByVal URL$, Optional ActivateWindow As Boolean = True) As SHDocVw.InternetExplorer

' подключается к браузеру IE, в котором открыта вкладка со страницей URL$

On Error Resume Next

Dim w As WebBrowser, oShellWind As New ShellWindows

' MsgBox URL$

For Each w In oShellWind

ПослСтр = Cells(Rows.Count, 1).End(xlUp).Row

Cells(ПослСтр + 1, 1) = w.LocationURL

If w.LocationURL Like URL$ Then

MsgBox w.LocationURL

'If ActivateWindow Then

' ShowWindow w.Hwnd, 5

' SetForegroundWindow w.Hwnd

'End If

Set GetRunningIE = w

MsgBox "Подключение выполнено к IE со ссылкой", w.LocationURL

' Exit For

End If

Next

Set oShellWind = Nothing

End Function


'Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal _

' lpClassName As String, ByVal lpWindowName As String) As Long

'Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long

'Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

'Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long

'

'Public Const GW_HWNDFIRST = 0

'Public Const GW_HWNDNEXT = 2

'

'

'Sub GetTaskList()

''Перебирает все открытое, при нормальной работе было открыто 241 окно

' Dim lw As Long, s As String, CurrWnd As Long

' CurrWnd = GetWindow(Application.hwnd, GW_HWNDFIRST)

' СчетчикОткрытыхОкон = 0

' Do While CurrWnd <> 0

' lw = GetWindowTextLength(CurrWnd)

' s = Space(lw + 1)

' lw = GetWindowText(CurrWnd, s, lw + 1)

' If lw > 0 Then

' If Trim(s) Like "*Windows Internet Explorer*" Then

' СчетчикОткрытыхОкон = СчетчикОткрытыхОкон + 1

' ПослСтр = Cells(Rows.Count, 1).End(xlUp).Row

' Cells(ПослСтр + 1, 1) = Trim(s)

' MsgBox Trim(s) 'Открытые окна

' End If

' End If

' CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)

' DoEvents

' Loop

' MsgBox СчетчикОткрытыхОкон

'End Sub


'Sub hgjg()

'Application.DisplayAlerts = False

'ф = "https://docs.google.com/spreadsheets/d/1thxKiDJ3Mmv1y-8XzX3YFSX_ZldYOjWWb1Gg0IasnGU/export"

'Hyperlinks(ф).Follow

'MsgBox "Открылось"

'End Sub

'Sub ОткрываемЧерезХромСсылку()

'aaaa = "https://docs.google.com/spreadsheets/d/1thxKiDJ3Mmv1y-8XzX3YFSX_ZldYOjWWb1Gg0IasnGU/export"

'Shell ("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" & " " & aaaa)

'

'End Sub


Так же в этом разделе:
 
MyTetra Share v.0.59
Яндекс индекс цитирования