From: Dee Earley on
On 06/10/2009 05:31, xytsrm wrote:
> I have a form with three visable items: a textbox, a label, and a button.
> I'm simply trying to retrieve the handle of the textbox. I've used
> FindWindow to retrieve the handle of the form, and have been using
> FindWindowsEx to try and retrieve the handle of the Textbox. This works if
> the textbox is the only entity on the form, but fails when there are other
> items on the form. The only way I have been able to get FindWindowEx to
> return anything is with the following format:
>
> FindWindowEx (hndl, vbNullString, vbNullString).
>
> According to "Appleman" I should be able to enter the title of the item in
> the third parameter (eg. "myTextBox"), but that only returns 0, I've tried
> entering "TextBox" for the class in the second parameter, but again that
> returns 0.
>
> This seems like it should be easy BUT? Does anyone have any suggestions?

The text box contents are not the "caption" which si why FindWindow*
won't see it.
You need to enumerate them all (EnumWindows()) and check for one that
looks like the one you want, possibly extracting and checking the text
manually.

--
Dee Earley (dee.earley(a)icode.co.uk)
i-Catcher Development Team

iCode Systems
From: xytsrm on
Hi Dee Earley,

Actually the property in the textbox is not "caption", it's "name", but as
some have suggested the name is not exposed and needs to be enumerated, or
perhaps can be found through Winspector.

X.


"Dee Earley" wrote:

> On 06/10/2009 05:31, xytsrm wrote:
> > I have a form with three visable items: a textbox, a label, and a button.
> > I'm simply trying to retrieve the handle of the textbox. I've used
> > FindWindow to retrieve the handle of the form, and have been using
> > FindWindowsEx to try and retrieve the handle of the Textbox. This works if
> > the textbox is the only entity on the form, but fails when there are other
> > items on the form. The only way I have been able to get FindWindowEx to
> > return anything is with the following format:
> >
> > FindWindowEx (hndl, vbNullString, vbNullString).
> >
> > According to "Appleman" I should be able to enter the title of the item in
> > the third parameter (eg. "myTextBox"), but that only returns 0, I've tried
> > entering "TextBox" for the class in the second parameter, but again that
> > returns 0.
> >
> > This seems like it should be easy BUT? Does anyone have any suggestions?
>
> The text box contents are not the "caption" which si why FindWindow*
> won't see it.
> You need to enumerate them all (EnumWindows()) and check for one that
> looks like the one you want, possibly extracting and checking the text
> manually.
>
> --
> Dee Earley (dee.earley(a)icode.co.uk)
> i-Catcher Development Team
>
> iCode Systems
>
From: Eduardo on

> Sorry I guess I wasn't as clear as I could be; the "FindWindow" &
> "FindWindowEx" functions are being issued from another App.

Private Declare Function GetWindow Lib "USER32" (ByVal hwnd _
As Long, ByVal wFlag 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 Declare Function FindWindow Lib "USER32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName 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 Const GW_HWNDNEXT = 2&
Private Const GW_CHILD = 5&


Private Function GetFirstTextBoxHandle(nFormCaption As String, _
Optional nTextboxText As String) As Long

Dim iHwnd As Long
Dim iSize As Long
Dim iClass As String
Dim iText As String

iHwnd = FindWindow(vbNullString, nFormCaption)
If iHwnd Then
iHwnd = GetWindow(iHwnd, GW_CHILD)
Do While iHwnd
iClass = Space(64)
iSize = GetClassName(iHwnd, iClass, Len(iClass))
If iSize > 0 Then
iClass = Left(iClass, iSize)
If iClass = "ThunderTextBox" Then
If nTextboxText <> "" Then
iText = Space(100)
GetWindowText iHwnd, iText, 100&
iText = Left(iText, InStr(iText, _
Chr(0)) - 1)
If iText = nTextboxText Then
GetFirstTextBoxHandle = iHwnd
Exit Function
End If
Else
GetFirstTextBoxHandle = iHwnd
Exit Function
End If
End If
End If
iHwnd = GetWindow(iHwnd, GW_HWNDNEXT)
Loop
End If
End Function

Private Sub Command1_Click()
MsgBox GetFirstTextBoxHandle("OtherForm1", "Text1")
End Sub
From: Desi on
Assuming both apps in the system are yours why not simply have your app
publish it's own window handles for easy access by another app? Personally I
create a "named" file mapping using the CreateFileMapping and MapViewOfFile
APIs and use CopyMemory to read and write a UDT of numerous window handles.
Dan Appleman covers the subject of shared memory well also. If you don't
wish to tangle with the APIs you could easily write the hadles in question
to a text file.

Desi


"xytsrm" <xytsrm(a)discussions.microsoft.com> wrote in message
news:5B61CEBD-DEE4-446B-9127-EFCFE0CD6C0F(a)microsoft.com...
>I have a form with three visable items: a textbox, a label, and a button.
> I'm simply trying to retrieve the handle of the textbox. I've used
> FindWindow to retrieve the handle of the form, and have been using
> FindWindowsEx to try and retrieve the handle of the Textbox. This works
> if
> the textbox is the only entity on the form, but fails when there are other
> items on the form. The only way I have been able to get FindWindowEx to
> return anything is with the following format:
>
> FindWindowEx (hndl, vbNullString, vbNullString).
>
> According to "Appleman" I should be able to enter the title of the item in
> the third parameter (eg. "myTextBox"), but that only returns 0, I've tried
> entering "TextBox" for the class in the second parameter, but again that
> returns 0.
>
> This seems like it should be easy BUT? Does anyone have any suggestions?
>
> X.
>


From: Norm Cook on
If iClass = "ThunderTextBox" Then

Shouldn't it be "ThunderRT6TextBox" ?

"Eduardo" <mm(a)mm.com> wrote in message news:hago63$mka$1(a)aioe.org...
>
>> Sorry I guess I wasn't as clear as I could be; the "FindWindow" &
>> "FindWindowEx" functions are being issued from another App.
>
> Private Declare Function GetWindow Lib "USER32" (ByVal hwnd _
> As Long, ByVal wFlag 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 Declare Function FindWindow Lib "USER32" Alias _
> "FindWindowA" (ByVal lpClassName As String, ByVal _
> lpWindowName 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 Const GW_HWNDNEXT = 2&
> Private Const GW_CHILD = 5&
>
>
> Private Function GetFirstTextBoxHandle(nFormCaption As String, _
> Optional nTextboxText As String) As Long
>
> Dim iHwnd As Long
> Dim iSize As Long
> Dim iClass As String
> Dim iText As String
>
> iHwnd = FindWindow(vbNullString, nFormCaption)
> If iHwnd Then
> iHwnd = GetWindow(iHwnd, GW_CHILD)
> Do While iHwnd
> iClass = Space(64)
> iSize = GetClassName(iHwnd, iClass, Len(iClass))
> If iSize > 0 Then
> iClass = Left(iClass, iSize)
> If iClass = "ThunderTextBox" Then
> If nTextboxText <> "" Then
> iText = Space(100)
> GetWindowText iHwnd, iText, 100&
> iText = Left(iText, InStr(iText, _
> Chr(0)) - 1)
> If iText = nTextboxText Then
> GetFirstTextBoxHandle = iHwnd
> Exit Function
> End If
> Else
> GetFirstTextBoxHandle = iHwnd
> Exit Function
> End If
> End If
> End If
> iHwnd = GetWindow(iHwnd, GW_HWNDNEXT)
> Loop
> End If
> End Function
>
> Private Sub Command1_Click()
> MsgBox GetFirstTextBoxHandle("OtherForm1", "Text1")
> End Sub


First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7
Prev: Centralised MsgBox
Next: Updating the VB EXE