Страница: 1 |
|
Вопрос: Дайте модуль
|
Добавлено: 12.03.10 22:25
|
|
Автор вопроса: FixedMixed
|
...Если у кого Уже есть для студии 2005 на языке басик. Модуль который получает имена всех открытых окон. Ну незнаю я где ошибка. Примеры чужие не работают.
Ответить
|
Номер ответа: 1 Автор ответа: Artyom
Разработчик
Вопросов: 130 Ответов: 6602
|
Профиль | | #1
|
Добавлено: 13.03.10 02:20
|
Раз
- Imports System.Runtime.InteropServices
- Imports System.Text
- Imports System.Drawing
-
- Friend Module Win32API
- <DllImport("user32.dll", SetLastError:=True)> _
- Public Function EnumWindows(ByVal lpEnumFunc As EnumThreadWindowsCallback, ByVal lParam As Integer) As Boolean
- End Function
-
- <DllImport("user32.dll", SetLastError:=True)> _
- Public Function EnumDesktopWindows(ByVal hDesktop As IntPtr, ByVal lpfn As EnumThreadWindowsCallback, ByVal lParam As Integer) As Boolean
- End Function
-
- <DllImport("user32.dll", SetLastError:=True)> _
- Public Function EnumChildWindows(ByVal hWndParent As IntPtr, ByVal lpEnumFunc As EnumThreadWindowsCallback, ByVal lParam As Integer) As Boolean
- End Function
-
- Public Delegate Function EnumThreadWindowsCallback(ByVal hwnd As IntPtr, ByVal lParam As Integer) As Boolean
-
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
- Public Function GetWindowText(ByVal hwnd As IntPtr, ByVal lpString As StringBuilder, ByVal nMaxCount As Integer) As Integer
- End Function
-
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
- Public Function SetWindowText(ByVal hwnd As IntPtr, ByVal lpString As String) As Boolean
- End Function
-
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
- Public Function SetFocus(ByVal hwnd As IntPtr) As IntPtr
- End Function
-
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
- Public Function SetForegroundWindow(ByVal hwnd As IntPtr) As Integer
- End Function
-
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
- Public Function GetWindowTextLength(ByVal hwnd As IntPtr) As Integer
- End Function
-
- <DllImport("kernel32.dll", SetLastError:=True)> _
- Public Function TerminateProcess(ByVal hProcess As IntPtr, ByVal uExitCode As UInteger) As Boolean
- End Function
-
- <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
- Public Function GetClassName(ByVal hWnd As System.IntPtr, ByVal lpClassName As System.Text.StringBuilder, ByVal nMaxCount As Integer) As Integer
- End Function
-
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
- Public Function PostMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
- End Function
-
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto, entrypoint:="SendMessage")> _
- Public Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
- End Function
-
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto, entrypoint:="SendMessage")> _
- Public Function SendMessageAsInt32(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Int32
- End Function
-
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto, entrypoint:="SendMessage")> _
- Public Function SendMessageAsInt32(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As Integer, ByVal lParam As Integer) As Int32
- End Function
-
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto, entrypoint:="SendMessage")> _
- Public Function SendMessageAsInt32(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As Integer, ByVal lParam As StringBuilder) As Int32
- End Function
-
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto, entrypoint:="SendMessage")> _
- Public Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As Integer, ByVal lParam As String) As IntPtr
- End Function
-
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto, entrypoint:="SendMessage")> _
- Public Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As Integer, ByVal lParam As StringBuilder) As IntPtr
- End Function
-
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto, entrypoint:="SendMessage")> _
- Public Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As Integer, ByVal lParam As Integer) As IntPtr
- End Function
-
- <DllImport("user32.dll")> _
- Public Function AttachThreadInput(ByVal idAttach As IntPtr, ByVal idAttachTo As IntPtr, ByVal fAttach As Boolean) As Boolean
- End Function
-
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)> _
- Public Function GetWindowThreadProcessId(ByVal hwnd As IntPtr, ByRef lpdwProcessId As IntPtr) As IntPtr
- End Function
-
- <DllImport("kernel32.dll")> _
- Public Function GetCurrentThreadId() As IntPtr
- End Function
-
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
- Public Function ShowWindow(ByVal hwnd As IntPtr, ByVal nCmdShow As Int32) As Boolean
- End Function
-
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
- Public Function MapWindowPoints(ByVal hWndFrom As IntPtr, ByVal hWndTo As IntPtr, ByRef lpPoints As POINT, ByVal cPoints As UInt32) As Integer
- End Function
-
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
- Public Function MapWindowPoints(ByVal hWndFrom As IntPtr, ByVal hWndTo As IntPtr, ByRef lpPoints As RECT, ByVal cPoints As UInt32) As Integer
- End Function
-
- <DllImport("user32.dll", ExactSpelling:=True, CharSet:=CharSet.Auto)> _
- Public Function GetParent(ByVal hWnd As IntPtr) As IntPtr
- End Function
-
- <DllImport("user32.dll")> _
- Public Function GetWindowRect(ByVal hWnd As IntPtr, ByRef lpRect As RECT) As Boolean
- End Function
-
- <DllImport("user32.dll")> _
- Public Function mouse_event(ByVal dwFlags As Int32, ByVal dX As Int32, ByVal dY As Int32, ByVal cButtons As Int32, ByVal dwExtraInfo As Int32) As Boolean
- End Function
-
- <DllImport("user32.dll", SetLastError:=True)> _
- Public Function SetCursorPos(ByVal X As Integer, ByVal Y As Integer) As Boolean
- End Function
-
- <DllImport("user32.dll", SetLastError:=True)> _
- Public Function GetCursorPos(ByRef lpPoint As POINT) As Boolean
- End Function
-
- <DllImport("user32.dll", ExactSpelling:=True)> _
- Public Function GetAncestor(ByVal hwnd As IntPtr, ByVal gaFlags As Int32) As IntPtr
- End Function
-
- <DllImport("user32.dll")> _
- Public Function GetWindowPlacement(ByVal hWnd As IntPtr, ByRef lpwndpl As WINDOWPLACEMENT) As Boolean
- End Function
-
- <DllImport("user32.dll")> _
- Public Function GetAsyncKeyState(ByVal vKey As Int32) As Short
- End Function
-
- <DllImport("gdi32.dll")> _
- Public Function CreateRectRgnIndirect(ByRef lprc As RECT) As IntPtr
- End Function
-
- <DllImport("user32.dll")> _
- Public Function SetWindowRgn(ByVal hWnd As IntPtr, ByVal hRgn As IntPtr, ByVal bRedraw As Boolean) As Long
- End Function
-
- <DllImport("user32.dll", SetLastError:=True)> _
- Public Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As UInt32) As Boolean
- End Function
-
-
- End Module
Два
- Imports System.Runtime.InteropServices
- Imports System.Text
- Imports System.Drawing
-
- Friend Module Win32API_Constants
- Public Const BM_CLICK As UInteger = &HF5
- Public Const WM_COMMAND As UInteger = &H111
- Public Const WM_SETTEXT As UInteger = &HC
- Public Const WM_GETTEXT As UInteger = &HD
- Public Const WM_GETTEXTLENGTH As UInteger = &HE
- Public Const WM_LBUTTONDOWN As UInteger = &H201
- Public Const WM_LBUTTONUP As UInteger = &H202
- Public Const WM_CLOSE As UInteger = &H10
- Public Const WM_ACTIVATE As UInteger = &H6
-
- Public Const MK_LBUTTON As Integer = 1
-
- Public Const MOUSEEVENTF_MOVE As Int32 = &H1
- Public Const MOUSEEVENTF_LEFTDOWN As Int32 = &H2
- Public Const MOUSEEVENTF_LEFTUP As Int32 = &H4
- Public Const MOUSEEVENTF_RIGHTDOWN As Int32 = &H8
- Public Const MOUSEEVENTF_RIGHTUP As Int32 = &H10
- Public Const MOUSEEVENTF_MIDDLEDOWN As Int32 = &H20
- Public Const MOUSEEVENTF_MIDDLEUP As Int32 = &H40
- Public Const MOUSEEVENTF_ABSOLUTE As Int32 = &H8000
- Public Const MOUSEEVENTF_WHEEL As Int32 = &H800
-
- Public Const GA_PARENT As Int32 = 1
- Public Const GA_ROOT As Int32 = 2
- Public Const GA_ROOTOWNER As Int32 = 3
-
- Public Const WA_INACTIVE As Integer = 0
- Public Const WA_ACTIVE As Integer = 1
- Public Const WA_CLICKACTIVE As Integer = 2
-
- Public Const SW_HIDE As Integer = 0
- Public Const SW_SHOWNORMAL As Integer = 1
- Public Const SW_NORMAL As Integer = 1
- Public Const SW_SHOWMINIMIZED As Integer = 2
- Public Const SW_SHOWMAXIMIZED As Integer = 3
- Public Const SW_MAXIMIZE As Integer = 3
- Public Const SW_SHOWNOACTIVATE As Integer = 4
- Public Const SW_SHOW As Integer = 5
- Public Const SW_MINIMIZE As Integer = 6
- Public Const SW_SHOWMINNOACTIVE As Integer = 7
- Public Const SW_SHOWNA As Integer = 8
- Public Const SW_RESTORE As Integer = 9
- Public Const SW_SHOWDEFAULT As Integer = 10
- Public Const SW_FORCEMINIMIZE As Integer = 11
- Public Const SW_MAX As Integer = 11
-
- Public Const VK_LBUTTON As Integer = 1
- Public Const VK_RBUTTON As Integer = 2
- Public Const VK_MBUTTON As Integer = 4
-
- Public Const CB_GETCOUNT As Integer = &H146
- Public Const CB_GETLBTEXT As Integer = &H148
- Public Const CB_GETLBTEXTLEN As Integer = &H149
- Public Const CB_SETCURSEL As Integer = &H14E
- Public Const CB_GETCURSEL As Integer = &H147
-
- Public ReadOnly HWND_NOTOPMOST As IntPtr = New IntPtr(-2)
-
- Public Const SWP_NOSIZE As Integer = &H1
- Public Const SWP_SHOWWINDOW As Integer = &H40
- End Module
Три
- Imports System.Runtime.InteropServices
- Imports System.Text
- Imports System.Drawing
-
- Friend Module Win32API_Structures
- <StructLayout(LayoutKind.Sequential)> _
- Public Structure POINT
- Public X As Integer
- Public Y As Integer
-
- Public Sub New(ByVal x As Integer, ByVal y As Integer)
- Me.X = x
- Me.Y = y
- End Sub
- End Structure
-
- <StructLayout(LayoutKind.Sequential)> _
- Public Structure RECT
- Public Left As Integer
- Public Top As Integer
- Public Right As Integer
- Public Bottom As Integer
-
- Public Sub New(ByVal Rectangle As Rectangle)
- Me.New(Rectangle.Top, Rectangle.Left, Rectangle.Right, Rectangle.Bottom)
- End Sub
- Public Sub New(ByVal left As Integer, ByVal top As Integer, ByVal right As Integer, ByVal bottom As Integer)
- Me.Left = left
- Me.Top = top
- Me.Right = right
- Me.Bottom = bottom
- End Sub
- End Structure
-
- <StructLayout(LayoutKind.Sequential)> _
- Public Structure WINDOWPLACEMENT
- Public length As Integer
- Public flags As Integer
- Public showCmd As Integer
- Public minPosition As POINT
- Public maxPosition As POINT
- Public normalPosition As RECT
- End Structure
- End Module
Четыре
- Imports System.Runtime.InteropServices
-
-
- Public Class NativeMouse
- Public Enum MouseAction As Int32
- Move = &H1
- LeftDown = &H2
- LeftUp = &H4
- RightDown = &H8
- RightUp = &H10
- MiddleDown = &H20
- MiddleUp = &H40
- Wheel = &H800
- End Enum
-
- Public Shared Sub MakeAction(ByVal action As MouseAction, ByVal x As Integer, ByVal y As Integer)
- Win32API.mouse_event(action Or MOUSEEVENTF_ABSOLUTE, x, y, 0, 0)
- End Sub
-
- Public Shared Sub LeftClick(ByVal x As Integer, ByVal y As Integer)
- Dim OldPoint As POINT
- Win32API.GetCursorPos(OldPoint)
- Win32API.SetCursorPos(x, y)
- Win32API.mouse_event(MouseAction.LeftDown, 0, 0, 0, 0)
- Win32API.mouse_event(MouseAction.LeftUp, 0, 0, 0, 0)
- SetCursorPos(OldPoint.X, OldPoint.Y)
- End Sub
-
- Public Shared ReadOnly Property LeftButtonPressed() As Boolean
- Get
- Return Win32API.GetAsyncKeyState(VK_LBUTTON) <> 0
- End Get
- End Property
-
- Public Shared ReadOnly Property RightButtonPressed() As Boolean
- Get
- Return Win32API.GetAsyncKeyState(VK_RBUTTON) <> 0
- End Get
- End Property
-
- Public Shared ReadOnly Property MiddleButtonPressed() As Boolean
- Get
- Return Win32API.GetAsyncKeyState(VK_RBUTTON) <> 0
- End Get
- End Property
-
- Public Shared ReadOnly Property AnyButtonPressed() As Boolean
- Get
- Return LeftButtonPressed Or RightButtonPressed Or MiddleButtonPressed
- End Get
- End Property
-
-
- End Class
Пять
- Imports System.Text
-
- Friend Class NativeWindow
- Private _Handle As IntPtr
-
- Public Sub New(ByVal handle As IntPtr)
- _Handle = handle
- End Sub
-
- Public ReadOnly Property Handle() As IntPtr
- Get
- Return _Handle
- End Get
- End Property
-
- Public ReadOnly Property ProcessId() As Integer
- Get
- Dim Result As IntPtr
- Win32API.GetWindowThreadProcessId(Handle, Result)
- Return Result.ToInt32
- End Get
- End Property
-
- Public Property Text() As String
- Get
- Dim TextLength = Win32API.GetWindowTextLength(Handle)
- Dim SB As New StringBuilder("", TextLength + 1)
- Win32API.GetWindowText(Handle, SB, TextLength + 1)
- Return SB.ToString()
- End Get
- Set(ByVal value As String)
- Win32API.SetWindowText(Handle, value)
- End Set
- End Property
-
- Public Function GetAllChildWindows() As List(Of NativeWindow)
- Dim Enumerator As New WindowEnumerator()
- EnumChildWindows(Handle, AddressOf Enumerator.EnumThreadWindowsCallback, 0)
- Return Enumerator.List
- End Function
-
- Public Function GetChildWindows() As List(Of NativeWindow)
- Return (From w In GetAllChildWindows() _
- Where w.ParentWindowHandle = Handle) _
- .ToList
- End Function
-
- Public ReadOnly Property ClassName() As String
- Get
- Dim SB As New StringBuilder("", 255)
- Dim Length = Win32API.GetClassName(Handle, SB, 255)
- SB.Length = Length
- Return SB.ToString
- End Get
- End Property
-
- Public Sub SendClick()
- Win32API.SendMessage(Me.Handle, BM_CLICK, IntPtr.Zero, IntPtr.Zero)
-
-
- End Sub
-
- Public Sub SendClickAsync()
- Win32API.PostMessage(Me.Handle, BM_CLICK, IntPtr.Zero, IntPtr.Zero)
- End Sub
-
- Public Sub Show()
- Win32API.ShowWindow(Me.Handle, SW_SHOW)
- End Sub
-
- Public Sub Hide()
- Win32API.ShowWindow(Me.Handle, SW_HIDE)
- End Sub
-
- Public ReadOnly Property ParentWindowHandle() As IntPtr
- Get
- Return Win32API.GetParent(Handle)
- End Get
- End Property
-
- Public ReadOnly Property RootWindowHandle() As IntPtr
- Get
- Return Win32API.GetAncestor(Handle, GA_ROOT)
- End Get
- End Property
-
- Public Property ContentText() As String
- Get
- Dim Length As Integer = SendMessageAsInt32(Handle, WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero)
- Dim SB As New StringBuilder("", Length)
- SendMessage(Handle, WM_GETTEXT, Length + 1, SB)
- Return SB.ToString
- End Get
- Set(ByVal value As String)
- SendMessage(Handle, WM_SETTEXT, 0, value)
- End Set
- End Property
-
- Public Sub SetForeground()
- Win32API.ShowWindow(Handle, SW_SHOW)
- Win32API.ShowWindow(Handle, SW_SHOWNORMAL)
-
- Win32API.SetForegroundWindow(Handle)
- End Sub
-
- Public Sub SetFocus()
- Win32API.SetFocus(Handle)
- End Sub
-
- Public ReadOnly Property ThreadId() As IntPtr
- Get
- Dim ProccessID As IntPtr
- Return Win32API.GetWindowThreadProcessId(Handle, ProccessID)
- End Get
- End Property
-
- Public Sub Close()
- Win32API.SendMessage(Handle, WM_CLOSE, IntPtr.Zero, IntPtr.Zero)
- End Sub
-
- Public Function ClientToScreen(ByVal point As POINT) As POINT
- Dim Result As POINT = point
- Win32API.MapWindowPoints(Handle, IntPtr.Zero, Result, 1)
- Return Result
- End Function
-
- Public Function ScreenToClient(ByVal point As POINT) As POINT
- Dim Result As POINT = point
- Win32API.MapWindowPoints(IntPtr.Zero, Handle, Result, 1)
- Return Result
- End Function
-
- Public Function ScreenToClient(ByVal rect As RECT) As RECT
- Dim Result As RECT = rect
- Win32API.MapWindowPoints(IntPtr.Zero, Handle, Result, 2)
- Return Result
- End Function
-
- Public Function ClientToOtherClient(ByVal point As POINT, ByVal otherHandle As IntPtr) As POINT
- Dim Result As POINT = point
- Win32API.MapWindowPoints(Handle, otherHandle, Result, 1)
- Return Result
- End Function
-
- Public Function OtherClientToClient(ByVal point As POINT, ByVal otherHandle As IntPtr) As POINT
- Dim Result As POINT = point
- Win32API.MapWindowPoints(otherHandle, Handle, Result, 1)
- Return Result
- End Function
-
- Public ReadOnly Property ScreenRect() As RECT
- Get
- Dim Result As RECT
- Win32API.GetWindowRect(Handle, result)
- Return Result
- End Get
- End Property
-
- Public Sub EmulateClick()
- WaitFor(Function() Not NativeMouse.AnyButtonPressed)
- Dim RootWindow = New NativeWindow(Me.RootWindowHandle)
-
- Dim Res = SetWindowPos(RootWindow.Handle, HWND_NOTOPMOST, 100, 100, 0, 0, SWP_NOSIZE)
-
-
- Dim Rect = ScreenRect
-
-
-
-
-
-
-
-
-
-
-
-
- RootWindow.SetForeground()
- NativeMouse.LeftClick(Rect.Left + 5, Rect.Top + 5)
-
- End Sub
-
- Public Function GetComboItems() As List(Of String)
- Dim Result As New List(Of String)
- Dim ItemsCount = SendMessageAsInt32(Handle, CB_GETCOUNT, IntPtr.Zero, IntPtr.Zero)
- For i = 0 To ItemsCount - 1
- Dim Length = SendMessageAsInt32(Handle, CB_GETLBTEXTLEN, i, 0)
- Dim SB As New StringBuilder(Length)
- Dim Readed = SendMessageAsInt32(Handle, CB_GETLBTEXT, i, SB)
- Result.Add(SB.ToString)
- Next
- Return Result
- End Function
-
- Public Function GetComboSelectedIndex() As Integer
- Return SendMessageAsInt32(Handle, CB_GETCURSEL, 0, 0)
- End Function
-
- Public Sub SetComboSelectedIndex(ByVal index As Integer)
- SendMessage(Handle, CB_SETCURSEL, index, 0)
- End Sub
-
- Public Shared Function GetTopLevelWindows() As List(Of NativeWindow)
- Dim Enumerator As New WindowEnumerator()
- EnumWindows(AddressOf Enumerator.EnumThreadWindowsCallback, 0)
- Return Enumerator.List
- End Function
-
- Public Shared Function GetDesktopWindows() As List(Of NativeWindow)
- Dim Enumerator As New WindowEnumerator()
- EnumDesktopWindows(IntPtr.Zero, AddressOf Enumerator.EnumThreadWindowsCallback, 0)
- Return Enumerator.List
- End Function
-
-
- Private Class WindowEnumerator
- Private _List As New List(Of NativeWindow)
- Public Function EnumThreadWindowsCallback(ByVal hwnd As IntPtr, ByVal lParam As Integer) As Boolean
- _List.Add(New NativeWindow(hwnd))
- Return True
- End Function
-
- Public ReadOnly Property List() As List(Of NativeWindow)
- Get
- Return _List
- End Get
- End Property
- End Class
- End Class
Шесть
- For Each Window In NativeWindow.GetTopLevelWindows()
- Console.WriteLine(Window.Text)
- Next
Если есть желание, выбери только те что нужно
Ответить
|
Номер ответа: 8 Автор ответа: Artyom
Разработчик
Вопросов: 130 Ответов: 6602
|
Профиль | | #8
|
Добавлено: 14.03.10 01:15
|
Sharp пишет:
Вот она — компактность дотнета!
Столько кода потому что помимо перебора списка окон мне требовались и другие операции с объектами Windows.
Я думал это очень очевидно, но, видимо, нужно пояснить.
Первые 3 части - это декларации функций Win32API, констант и структур которые используются при вызове функций Win32API.
4 - управляемая обертка для выполнения некоторых операций с мышкой
5 - управляемая обертка для работы с окнами (как с объектами)
6 - код который, используя все вышеописанное, выполняет перебор окон.
FixedMixed пишет:
Артем. Ты наверное прочитал только название темы. Мне нужен не любой модуль.
Упс, извини. Ты попросил модуль перебора окон, а я непредусмотрительно дал тебе модуль математических рассчетов
FixedMixed пишет:
А, это все часть одного проекта. Понятно. Это мне не пригодится. У кого нить другого есть одним модулем? Чтобы поменьше мусора.
Если соберешь все это вместе, то получишь перебор окон (6-я часть как раз и выполняет его). Если ты думаешь что я буду лично для тебя удалять из кода ненужные только для перебора декларции и константы, ты ошибаешься. Тебе прийдется самому этим заняться.
Или, если уж на то пошло, потрудиться набрать в гугле EnumWindows и GetWindowText.
Ответить
|
Номер ответа: 11 Автор ответа: Artyom
Разработчик
Вопросов: 130 Ответов: 6602
|
Профиль | | #11
|
Добавлено: 14.03.10 23:35
|
- <DllImport("user32.dll", SetLastError:=True)> _
- Public Function EnumWindows(ByVal lpEnumFunc As EnumThreadWindowsCallback, ByVal lParam As Integer) As Boolean
- End Function
-
- Public Delegate Function EnumThreadWindowsCallback(ByVal hwnd As IntPtr, ByVal lParam As Integer) As Boolean
-
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
- Public Function GetWindowText(ByVal hwnd As IntPtr, ByVal lpString As System.Text.StringBuilder, ByVal nMaxCount As Integer) As Integer
- End Function
-
- <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
- Public Function GetWindowTextLength(ByVal hwnd As IntPtr) As Integer
- End Function
-
- Public Function EnumWindowsProc(ByVal hwnd As IntPtr, ByVal lParam As Integer) As Boolean
- Dim TextLength = GetWindowTextLength(hwnd)
- Dim SB As New System.Text.StringBuilder("", TextLength + 1)
- GetWindowText(hwnd, SB, TextLength + 1)
- Console.WriteLine(SB.ToString())
- Return True
- End Function
-
- Public Sub Main()
- EnumWindows(AddressOf EnumWindowsProc, 0)
- Console.ReadLine()
- End Sub
Ответить
|
Страница: 1 |
Поиск по форуму