473,320 Members | 1,825 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

EnumPropsEx API in VB.NEt

Has anyone got working code using the EnumPropsEx API call in VB.NET. I have
several other API calls working to get info from other application windows,
but I can't seem to get this one working. Any help would be appreciated.
Here is the code I'm using currently (that doesn't work) I think I copied it
all in here correctly, but if I've missed something please let me know.

Thanks;
Shepard

Public Const GWL_EXSTYLE As Integer = (-20)
Public Const GW_OWNER As Integer = 4
Public Const SW_RESTORE As Integer = 9
Public Const SW_SHOW As Integer = 5
Public Const WS_EX_TOOLWINDOW As Integer = &H80
Public Const WS_EX_APPWINDOW As Integer = &H40000
' Declaration Section
Declare Function GetProp Lib "user32.dll" Alias "GetPropA" (ByVal hwnd
As Int32, ByVal lpString As String) As Int32
Declare Function SetProp Lib "user32.dll" Alias "SetPropA" ( _
ByVal hwnd As Int32, _
ByVal lpString As String, _
ByVal hData As Int32) As Int32
Private Declare Function RemoveProp Lib "user32.dll" Alias "RemovePropA"
(ByVal hwnd As Int32, ByVal lpString As String) As Int32
Private Declare Function EnumProps Lib "user32" Alias "EnumPropsA"
(ByVal hwnd As Integer, ByVal lpEnumFunc As Integer) As Long
Private Declare Function EnumPropsEx Lib "user32.dll" Alias
"EnumPropsExA" (ByVal hWnd As Int32, ByVal EnumPropCallback As
EnumPropCallback, ByVal lParam As Int32) As Int32
Private Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA"
(ByVal lpString As String) As Int32
Private Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyA"
(ByVal lpString1 As String, ByVal lpString2 As String) As Int32
Delegate Function EnumPropCallback(ByVal hWnd As Integer, _
ByVal lpszString As Integer, _
ByVal hData As Integer, _
ByVal dwData As Integer) As
Int32

Public Declare Function EnumWindows Lib "user32.dll" _
Alias "EnumWindows" (ByVal callback As EnumWindowsCallback, _
ByVal lParam As Integer) As Integer

Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent _
As Integer, ByVal lpEnumFunc As EnumChildCallback, ByVal lParam As
Integer) As Integer

Public Delegate Function EnumChildCallback(ByVal hWnd As Integer, _
ByVal lParam As Integer) As
Boolean
Public Declare Function GetWindow Lib "user32.dll" _
Alias "GetWindow" (ByVal hwnd As Integer, _
ByVal wCmd As Integer) As Integer

Public Declare Function GetWindowLong Lib "user32.dll" _
Alias "GetWindowLongA" (ByVal hwnd As Integer, _
ByVal nIndex As Integer) As Integer

' Call back Function
Function PropEnumProc(ByVal hwnd As Integer, _
ByVal lpszString As Integer, ByVal hData As Integer, _
ByVal dwData As Integer) As
Int32
Dim Buffer As String
'create ab buffer
Buffer = Space(lstrlen(lpszString) + 1)
'copy the string to the buffer
lstrcpy(Buffer, lpszString)
'show the buffer
TextBox1.Text = Buffer
'continue enumeration
PropEnumProc = True
End Function

Function FillActiveWindowsList(ByVal hWnd As Integer, ByVal lParam As
Integer) As Boolean
Dim windowText As New StringBuilder(STRING_BUFFER_LENGTH)

' Get the Window Caption.
GetWindowText(hWnd, windowText, STRING_BUFFER_LENGTH)

' Only add valid windows to the active windows listbox.
If ProcessIsActiveWindow(hWnd) Then
lstClassNames.Items.Add(windowText)
lstHandles.Items.Add(hWnd)
End If

Return True
End Function
Function ProcessIsActiveWindow(ByVal hWnd As Integer) As Boolean
Dim windowText As New StringBuilder(STRING_BUFFER_LENGTH)
Dim windowStyle As Integer

' Get the windows caption, owner information, and window style.
GetWindowText(hWnd, windowText, STRING_BUFFER_LENGTH)
Dim windowIsOwned As Boolean
windowIsOwned = GetWindow(hWnd, GW_OWNER) <> 0
windowStyle = GetWindowLong(hWnd,GWL_EXSTYLE)

' Do not allow invisible processes.
If Not IsWindowVisible(hWnd) Then
Return False
End If

' Window must have a caption
If windowText.ToString.Equals("") Then
Return False
End If

' Should not have a parent
If GetParent(hWnd) <> 0 Then
Return False
End If

' Don't allow unowned tool tips
If (windowStyle And WS_EX_TOOLWINDOW) <> 0 And Not windowIsOwned Then
Return False
End If

' Don't allow applications with owners
If (windowStyle And WS_EX_APPWINDOW) = 0 And windowIsOwned Then
Return False
End If

' All criteria were met, window is a valid active window.
Return True
End Function

Private Sub lstClassNames_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles lstClassNames.DoubleClick
Dim hWnd As Integer
hWnd = lstHandles.Items(lstClassNames.SelectedIndex)
EnumPropsEx(hWnd, New EnumPropCallback(AddressOf _
PropEnumProc), 0)
Debug.Write("Error: " & Err.LastDllError())
End Sub

Private Sub Form_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
lstClassNames.Items.Clear()
lstClassNames.Enabled = True
EnumWindows(New EnumWindowsCallback(AddressOf _
FillActiveWindowsList), 0)
End Sub

Jul 21 '05 #1
2 3243
but I can't seem to get this one working.


In what way is it failing?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #2
I'm receiving the following dll error

Error number 126: The specified module could not be found.

As far as I can tell, I'm declaring it correctly and using it properly, but
I continue to get this error.

Thanks
Shepard

"Mattias Sjögren" wrote:
but I can't seem to get this one working.


In what way is it failing?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: ShepardBerry | last post by:
Has anyone got working code using the EnumPropsEx API call in VB.NET. I have several other API calls working to get info from other application windows, but I can't seem to get this one working. ...
22
by: SQACSharp | last post by:
I'm trying to get the control name of an editbox in another window. The following code set the value "MyPassword" in the password EditBox but it fail to return the control name of the EditBox. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.