|
-
Mar 5th, 2005, 07:01 PM
#1
Thread Starter
Lively Member
Find all buttons or statics of a parten hWnd
I am trying to get the caption of a class called static off of another app. There is more than one of static type class on the parent. Is there some way I can cycle through each "static" and get the caption from it? Or maybe is there someway that I can specify a partial caption and class "static" and then just get a single match? Thanks!
-
Mar 5th, 2005, 07:14 PM
#2
-
Mar 5th, 2005, 07:21 PM
#3
Re: Find all buttons or statics of a parten hWnd
OK, something along these lines? I tested it with a form and 3 textboxes and it worked :
VB Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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 GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Sub Command1_Click()
Dim h As Long
Dim hChild As Long
Dim sChildText As String
h = FindWindow(vbNullString, "Form1")
Do
hChild = FindWindowEx(h, hChild, "ThunderTextBox", vbNullString)
If hChild <> 0 Then
sChildText = String(GetWindowTextLength(hChild) + 1, Chr$(0))
GetWindowText hChild, sChildText, Len(sChildText)
Debug.Print sChildText
End If
Loop While hChild <> 0
End Sub
Has someone helped you? Then you can Rate their helpful post. 
-
Mar 5th, 2005, 08:16 PM
#4
Re: Find all buttons or statics of a parten hWnd
If you know the control id (you can find it using MS Spy++) you can use this API to get the
handle of it directly (and thus the caption) instead of looping.
VB Code:
Private Declare Function GetDlgCtrlID Lib "user32.dll" (ByVal hwnd As Long) As Long
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 5th, 2005, 08:27 PM
#5
-
Mar 5th, 2005, 09:29 PM
#6
Re: Find all buttons or statics of a parten hWnd
My code ex is at work But I think I made a mistake (I can admit it ). The API works reverse
of how I described it (I think I have a bit of Dyslexia). You would need to enumerate through
the static windows checking if the id matches. This API is mostly used for when the caption
is a nullstring and you have several nullstring captions of the same window class.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 6th, 2005, 03:22 PM
#7
-
Apr 12th, 2005, 05:37 PM
#8
Hyperactive Member
Re: Find all buttons or statics of a parten hWnd
manavo11, I tried your code to list captions of all buttons on a msgbox from another app - worked PERFECTLY - thanks!
I was able to automatically click the "OK" button. But now what if I need to see the caption/text of the msgbox first, can that be done?
I tried playing with your line of code:
VB Code:
hChild = FindWindowEx(h, hChild, "Button", vbNullString)
...by replacing "Button" with "Label", "Caption", or whatever... none returned me the value of the msgbox caption.
Any idea?
-
Apr 13th, 2005, 04:02 PM
#9
Re: Find all buttons or statics of a parten hWnd
 Originally Posted by Krass
manavo11, I tried your code to list captions of all buttons on a msgbox from another app - worked PERFECTLY - thanks!
I was able to automatically click the "OK" button. But now what if I need to see the caption/text of the msgbox first, can that be done?
I tried playing with your line of code:
VB Code:
hChild = FindWindowEx(h, hChild, "Button", vbNullString)
...by replacing "Button" with "Label", "Caption", or whatever... none returned me the value of the msgbox caption.
Any idea?
I'm glad you found it useful Now for your specific problem, you need to search for "Static", not label or anything like that :
VB Code:
hChild = FindWindowEx(h, hChild, "Static", vbNullString)
Has someone helped you? Then you can Rate their helpful post. 
-
Apr 19th, 2005, 11:51 PM
#10
Hyperactive Member
Re: Find all buttons or statics of a parten hWnd
This code works good:
VB Code:
hChild = FindWindowEx(h, hChild, "Button", vbNullString)
But how come it traps buttons ONLY from an IE msgbox? ("Proceed with entry submission, OK/CANCEL")... I want to use this method on one my own Vb application, which contains textboxes and buttons... But it doesn't seem to see any of them...
Any idea?
(my form has a button called "Command1")
Thanks
-
Apr 20th, 2005, 03:59 PM
#11
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|