Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
||
ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
[18.224.32.86] |
|
Сообщ.
#1
,
|
|
|
Доброго времени суток! Допустим, у меня открыто сразу 3 папки. Каким образом я могу узнать пути, которые в них открыты, чтобы потом их открыть заново. Задача такая, запомнить все открытые директории, а после перезагрузки компьютера восстановить их. Помогите, пожалуйста, как это можно осуществить!
|
Сообщ.
#3
,
|
|
|
DIS, спасибо конечно, но мне нужно это программно на vb6 осуществить
|
Сообщ.
#4
,
|
|
|
Какие API-функции нужно использовать?
|
Сообщ.
#5
,
|
|
|
EnumWindows/GetWindowText/ShellExecute, видимо
|
Сообщ.
#6
,
|
|
|
B.V., спасибо, попробую
|
Сообщ.
#7
,
|
|
|
Подскажите, пожалуйста, в чём ошибка? В переменной hndExpl - нуль. Установен Windows7
'Функция для поиска окна первого уровня Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long 'Функция для поиска дочернего окна (коим являются такие контролы: Edit, Button и т.д.) Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long Private Const WM_GETTEXTLENGTH = &HE Private Const WM_GETTEXT = &HD Sub МакросПроба() Dim hndExpl As Long, hndComb As Long, hndComb2 As Long, hndComb3 As Long, hndComb4 As Long, hndComb5 As Long Dim s As String, iTxtLen As Long, a As Long 'Ищем hWnd Проводника по его классу hndExpl = FindWindow("ExploreWClass", vbNullString) 'Ищем hWnd ComboBox, который содержит адрес, продираясь через его родителей hndComb = FindWindowEx(hndExpl, 0, "WorkerA", vbNullString) hndComb2 = FindWindowEx(hndComb, 0, "ReBarWindow32", vbNullString) hndComb3 = FindWindowEx(hndComb2, 0, "ComboBoxEx32", vbNullString) ' получаем длину текста iTxtLen = SendMessage(hndComb3, WM_GETTEXTLENGTH, 0, 0) ' добавляем 1 для нулевого символа iTxtLen = iTxtLen + 1 s = Space$(iTxtLen) ' получаем текст в переменной s iTxtLen = SendMessage(hndComb3, WM_GETTEXT, iTxtLen, ByVal s) MsgBox s End Sub |
Сообщ.
#8
,
|
|
|
Вместе с Explore ищи CabinetWClass
|
Сообщ.
#9
,
|
|
|
B.V., не понял, как именно?
hndExpl = FindWindow("ExploreCabinetWClass", vbNullString) Добавлено так не работает |
Сообщ.
#10
,
|
|
|
hndExpl = FindWindow("CabinetWClass", vbNullString) |
Сообщ.
#11
,
|
|
|
Filka, написал, теперь hndComb равно нулю! Каков принцип, вообще?
Dim hndExpl As Long, hndComb As Long, hndComb2 As Long, hndComb3 As Long, hndComb4 As Long, hndComb5 As Long Dim s As String, iTxtLen As Long, a As Long 'Ищем hWnd Проводника по его классу hndExpl = FindWindow("CabinetWClass", vbNullString) 'Ищем hWnd ComboBox, который содержит адрес, продираясь через его родителей hndComb = FindWindowEx(hndExpl, 0, "WorkerA", vbNullString) hndComb2 = FindWindowEx(hndComb, 0, "ReBarWindow32", vbNullString) hndComb3 = FindWindowEx(hndComb2, 0, "ComboBoxEx32", vbNullString) ' получаем длину текста iTxtLen = SendMessage(hndComb3, WM_GETTEXTLENGTH, 0, 0) ' добавляем 1 для нулевого символа iTxtLen = iTxtLen + 1 s = Space$(iTxtLen) ' получаем текст в переменной s iTxtLen = SendMessage(hndComb3, WM_GETTEXT, iTxtLen, ByVal s) MsgBox s |
Сообщ.
#12
,
|
|
|
hndExpl = FindWindow("CabinetWClass", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "WorkerW", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "ReBarWindow32", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "ComboBoxEx32", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "ComboBox", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "Edit", vbNullString) Прикреплённая картинка
|
Сообщ.
#13
,
|
|
|
Filka, данная строка не выполняется
hndExpl = FindWindowEx(hndExpl, 0, "ComboBoxEx32", vbNullString) Добавлено hndExpl равно нулю |
Сообщ.
#14
,
|
|
|
salieri, а оконным шпионом посмотреть имена классов?
|
Сообщ.
#15
,
|
|
|
Цитата Filka @ а где его скачать? оконным шпионом |
Сообщ.
#16
,
|
|
|
Сообщ.
#17
,
|
|
|
Filka, спасибо огромное, буду смотреть
|
Сообщ.
#18
,
|
|
|
Пожалуйста.
|
Сообщ.
#19
,
|
|
|
Сообщ.
#20
,
|
|
|
Надо не сразу ToolBarWindow32 писать, а спускаться по иерархии окон, т.е. от родительского CabinetWClass, потом WorkerW, потом ReBarWindow32 и т.д.
|
Сообщ.
#21
,
|
|
|
Filka, да, именно так:
hndExpl = FindWindow("CabinetWClass", vbNullString) hndExpl1 = FindWindowEx(hndExpl, 0, "WorkerW", vbNullString) hndExpl2 = FindWindowEx(hndExpl1, 0, "ReBarWindow32 (Toolbar)", vbNullString) в итоге: hndExpl2 =0 |
Сообщ.
#22
,
|
|
|
hndExpl = FindWindow("CabinetWClass", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "WorkerW", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "ReBarWindow32", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "Address Band Root", vbNullString) '... и т.д. hndExpl = FindWindowEx(hndExpl, 0, "ToolBarWindow32", vbNullString) |
Сообщ.
#23
,
|
|
|
Filka, получилось, но не могу теперь текст вывести:
Sub findhead() Dim hndExpl As Long Dim s As String, iTxtLen As Long hndExpl = FindWindow("CabinetWClass", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "WorkerW", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "ReBarWindow32", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "Address Band Root", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "msctls_progress32", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "Breadcrumb Parent", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "ToolBarWindow32", vbNullString) iTxtLen = SendMessage(hndExpl, WM_GETTEXTLENGTH, 0, 0) iTxtLen = iTxtLen + 1 s = Space$(iTxtLen) iTxtLen = SendMessage(hndExpl, WM_GETTEXT, iTxtLen, ByVal s) MsgBox s End Sub Добавлено всё, разобрался Ret = GetWindowTextLength(hndExpl) sSave = Space(Ret) GetWindowText hndExpl, sSave, Ret + 1 Me.Caption = sSave Добавлено Ещё один момент, если у меня открыто 5 проводников, то как мне их заголовки все вывести последовательно? |
Сообщ.
#24
,
|
|
|
EnumWindows
|
Сообщ.
#25
,
|
|
|
Filka, написал, как-то опять не так выводит. Повторяет одну и ту же директорию n-ое число раз, при том, что открыто 2 директории. В чём опять ошибка?
' Модуль Option Explicit Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean Dim sSave As String Dim Ret As Long Dim hndExpl As Long Dim iTxtLen As Long hndExpl = FindWindow("CabinetWClass", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "WorkerW", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "ReBarWindow32", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "Address Band Root", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "msctls_progress32", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "Breadcrumb Parent", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "ToolBarWindow32", vbNullString) Ret = GetWindowTextLength(hndExpl) sSave = Space(Ret) GetWindowText hndExpl, sSave, Ret + 1 Form1.Text1.Text = Form1.Text1.Text + sSave + vbCrLf EnumWindowsProc = True End Function ' Форма Option Explicit Private Sub Form_Load() Text1.Text = vbNullString EnumWindows AddressOf EnumWindowsProc, ByVal 0& End Sub |
Сообщ.
#26
,
|
|
|
А так?
Option Explicit Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean Dim sSave As String Dim Ret As Long Dim hndExpl As Long Dim ClassName As String ClassName = Space(255) Ret = GetClassName(hwnd, ClassName, 255) ClassName = Left(ClassName, Ret) If ClassName = "CabinetWClass" Then hndExpl = FindWindowEx(hwnd, 0, "WorkerW", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "ReBarWindow32", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "Address Band Root", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "msctls_progress32", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "Breadcrumb Parent", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "ToolBarWindow32", vbNullString) Ret = GetWindowTextLength(hndExpl) sSave = Space(Ret) GetWindowText hndExpl, sSave, Ret + 1 Form1.Text1.Text = Form1.Text1.Text + sSave + vbCrLf End If EnumWindowsProc = True End Function |
Сообщ.
#27
,
|
|
|
Filka, спасибо огромное, всё получилось!
|
Сообщ.
#28
,
|
|
|
Пожалуйста
|
Сообщ.
#29
,
|
|
|
На Windows 7 всё заработало. Стал для Windows XP писать, и ничего не выходит. Подскажите, пожалуйста, в чём ошибка? Скриншот прилагаю.
'модуль Option Explicit Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean Dim sSave As String Dim Ret As Long Dim hndExpl As Long Dim iTxtLen As Long hndExpl = FindWindow("CabinetWClass", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "WorkerW", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "ReBarWindow32", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "ComboBoxEx32", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "ComboBox", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "Edit", vbNullString) Ret = GetWindowTextLength(hndExpl) sSave = Space(Ret) GetWindowText hndExpl, sSave, Ret + 1 Form1.Text1.Text = Form1.Text1.Text + sSave + vbCrLf EnumWindowsProc = True End Function 'форма Option Explicit Private Sub Form_Load() Text1.Text = vbNullString EnumWindows AddressOf EnumWindowsProc, ByVal 0& End Sub Прикреплённая картинка
Добавлено Проблема с этой строкой: Ret = GetWindowTextLength(hndExpl) |
Сообщ.
#30
,
|
|
|
Option Explicit Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean 'Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long 'Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long 'Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long Const WM_GETTEXTLENGTH As Long = &HE Const WM_GETTEXT As Long = &HD Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean Dim sSave As String Dim Ret As Long Dim hndExpl As Long Dim ClassName As String ClassName = Space(255) Ret = GetClassName(hwnd, ClassName, 255) ClassName = Left(ClassName, Ret) If ClassName = "CabinetWClass" Then hndExpl = FindWindowEx(hwnd, 0, "WorkerW", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "ReBarWindow32", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "ComboBoxEx32", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "ComboBox", vbNullString) hndExpl = FindWindowEx(hndExpl, 0, "Edit", vbNullString) Ret = SendMessage(hndExpl, WM_GETTEXTLENGTH, 0, 0) sSave = Space(Ret + 1) SendMessage hndExpl, WM_GETTEXT, Ret + 1, ByVal sSave sSave = Left(sSave, Ret) + vbCrLf Form1.Text1.Text = Form1.Text1.Text + sSave End If EnumWindowsProc = True End Function salieri, подошло? |
Сообщ.
#31
,
|
|
|
Filka, попробую, скажу, просто под рукой WinXP сейчас нет.
|
Сообщ.
#32
,
|
|
|
Filka, всё, спасибо, подошло! Спасибо огромное
|
Сообщ.
#33
,
|
|
|
Пожалуйста
|