Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / February 2004



Tip: Looking for answers? Try searching our database.

Finding form elements in another application with just a window handle

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Matt Atwood - 28 Feb 2004 23:46 GMT
I am trying to enumerate through the form elements of another
program's window with just a window handle.  Is this possible?

What I am ultimately trying to do is this:  I am writing an
application that needs to be able to respond to the changes in a label
on a form in another application with just the window handle.  Sounds
simple enough to do, but I am unable to determine if this is posible
and if so, how to do it.

Thanks in advance...

Matt
Joe - 29 Feb 2004 00:10 GMT
> I am trying to enumerate through the form elements of another
> program's window with just a window handle.  Is this possible?
[quoted text clipped - 4 lines]
> simple enough to do, but I am unable to determine if this is posible
> and if so, how to do it.

Some of VB's "controls" are implemented by VB itself and don't have
a handle visible to other running programs or even to Windows at all.

--
Joe Foster <mailto:jlfoster%40znet.com>  Sacrament R2-45 <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!
J French - 29 Feb 2004 07:11 GMT
>I am trying to enumerate through the form elements of another
>program's window with just a window handle.  Is this possible?
[quoted text clipped - 4 lines]
>simple enough to do, but I am unable to determine if this is posible
>and if so, how to do it.

Try examining the Form with this Snooper
- however as Joe pointed out, Labels (in VB) have no Window Handle

Option Explicit

' Add one Timer

Private Type POINTAPI
       X As Long
       Y As Long
End Type
Private Declare Function GetCursorPos _
       Lib "user32" _
       (lpPoint As POINTAPI) As Long

Private Declare Function WindowFromPoint _
       Lib "user32" _
       (ByVal xPoint As Long, _
        ByVal yPoint As Long) 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 SendMessage Lib "user32" Alias "SendMessageA"
( _
    ByVal hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    lParam As Any) As Long

Private Const WM_GETTEXT = &HD

Private Sub Form_Load()
   Timer1.Enabled = True
   Timer1.Interval = 500
End Sub

Private Function WindowInf() As String
   Dim Hnd As Long, Buff$, Q&
   Dim PT As POINTAPI

   GetCursorPos PT
   Hnd = WindowFromPoint(PT.X, PT.Y)
   
   WindowInf = Str$(Hnd)
   ' ---
   Buff$ = Space$(255)
   Q& = GetClassName(Hnd, Buff$, Len(Buff$))
   WindowInf = WindowInf + ":" + Left$(Buff$, Q)
   ' ---
   Q& = SendMessage(Hnd, WM_GETTEXT, Len(Buff$), ByVal Buff$)
   WindowInf = WindowInf + ":" + Left$(Buff$, Q)

End Function

Private Sub Timer1_Timer()
   Me.Caption = WindowInf
End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.