PDA

View Full Version : Capture window help



pototoj
03-01-2013, 05:20 AM
Hi I am new to this forum and hope some can give me some help. I am ok to VBA macros but not a expert so please consider this.
I was reading this thread and found it very interesting.
Its a code from mark007, and because i am new here i cant post the link.
But the title is Capture Window Handles, Class Names and Titles
So please see if you can find it and compare it. Its a great code.

It capture all what it can find if i have understand it correct.And i think it seems to work really excellent.
What i have searched and googled for long time is quite similar.
I would like to have first a code similar to marks, but a code who only go for a certain window defined. So i example enter the caption of this window from the titlebar, in a inputbox. And when it find it it, it capture all also children.

I would like this to happen in excel like marks. So i get the result in a excel sheet.
What i really need after, is a way to see what is the different text fields, input boxes and scrolldown buttons.
So i can in excel can identify the different fields and when i know and identify the fields(textfields i guess)
I can put my input in the excel sheet and use another code to transfer this to this certain found windows form.
So its like having a kind of form filler. Where i can read the from, then put in my input and paste this input into the windows form.
And then i can save the excel and use this next time, i have the same form with same info to fill in.
I have to say this is not a webform, so i cant use example roboform.
I think all this is possible and i have read alot about it, but so far, not found anything or maybe not understand what to do with it.
So if some of the experts here would help with this, it would really be great.
And please consider i can make macroes but i am not an expert.

Hope some can help.

Ps. Use excel 2003 and also visual 2008

Thanks in advance
Pototoj

pototoj
03-01-2013, 09:32 AM
Hi To Help a little i will post mar007 code. And this is the one i would like to have changed, so it only capture the info from certain window difined by the titlebar, and would be nice with a inputbox for that. But the question is if this can help with the other i want to archieve.
But please have a look thanks


Option Explicit

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 GetClassName Lib "user32" Alias "GetClassNameA" _
(ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Private x As Integer

Private Type winEnum
winHandle As Integer
winClass As Integer
winTitle As Integer
winHandleClass As Integer
winHandleTitle As Integer
winHandleClassTitle As Integer
End Type
Dim winOutputType As winEnum

Public Sub GetWindows()
x = 0
winOutputType.winHandle = 0
winOutputType.winClass = 1
winOutputType.winTitle = 2
winOutputType.winHandleClass = 3
winOutputType.winHandleTitle = 4
winOutputType.winHandleClassTitle = 5

GetWinInfo 0&, 0, winOutputType.winHandleClassTitle
End Sub


Private Sub GetWinInfo(hParent As Long, intOffset As Integer, OutputType As Integer)

Dim hwnd As Long, lngRet As Long, y As Integer
Dim strText As String
hwnd = FindWindowEx(hParent, 0&, vbNullString, vbNullString)
While hwnd <> 0
Select Case OutputType
Case winOutputType.winClass
strText = String$(100, Chr$(0))
lngRet = GetClassName(hwnd, strText, 100)
Range("a1").Offset(x, intOffset) = Left$(strText, lngRet)
Case winOutputType.winHandle
Range("a1").Offset(x, intOffset) = hwnd
Case winOutputType.winTitle
strText = String$(100, Chr$(0))
lngRet = GetWindowText(hwnd, strText, 100)
If lngRet > 0 Then
Range("a1").Offset(x, intOffset) = Left$(strText, lngRet)
Else
Range("a1").Offset(x, intOffset) = "N/A"
End If
Case winOutputType.winHandleClass
Range("a1").Offset(x, intOffset) = hwnd
strText = String$(100, Chr$(0))
lngRet = GetClassName(hwnd, strText, 100)
Range("a1").Offset(x, intOffset + 1) = Left$(strText, lngRet)
Case winOutputType.winHandleTitle
Range("a1").Offset(x, intOffset) = hwnd
strText = String$(100, Chr$(0))
lngRet = GetWindowText(hwnd, strText, 100)
If lngRet > 0 Then
Range("a1").Offset(x, intOffset + 1) = Left$(strText, lngRet)
Else
Range("a1").Offset(x, intOffset + 1) = "N/A"
End If
Case winOutputType.winHandleClassTitle
Range("a1").Offset(x, intOffset) = hwnd
strText = String$(100, Chr$(0))
lngRet = GetClassName(hwnd, strText, 100)
Range("a1").Offset(x, intOffset + 1) = Left$(strText, lngRet)
strText = String$(100, Chr$(0))
lngRet = GetWindowText(hwnd, strText, 100)
If lngRet > 0 Then
Range("a1").Offset(x, intOffset + 2) = Left$(strText, lngRet)
Else
Range("a1").Offset(x, intOffset + 2) = "N/A"
End If
End Select
'check for children
y = x
Select Case OutputType
Case Is > 4
GetWinInfo hwnd, intOffset + 3, OutputType
Case Is > 2
GetWinInfo hwnd, intOffset + 2, OutputType
Case Else
GetWinInfo hwnd, intOffset + 1, OutputType
End Select
'increment by 1 row if no children found
If y = x Then
x = x + 1
End If
'now get next window
hwnd = FindWindowEx(hParent, hwnd, vbNullString, vbNullString)
Wend

End Sub